Skip to content

Commit 06a3780

Browse files
authored
Merge pull request #263 from sysprog21/drop-diffstat
Remove dependency on external tool for summary
2 parents 2078cee + b186cd4 commit 06a3780

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/pre-commit.hook

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,20 @@ for FILE in $C_FILES; do
207207
fi
208208
done
209209

210+
# Show insertion and deletion counts.
210211
if [ "${#FILES[@]}" -gt 0 ]; then
211212
echo "Following files were changed:"
212213
for file in "${FILES[@]}"; do
213-
if command -v diffstat >/dev/null 2>&1; then
214-
summary=$(git diff --cached "$file" | diffstat -s | sed -E 's/^[[:space:]]*[0-9]+ files? changed,?[[:space:]]*//')
215-
echo " - $file | $summary"
214+
summary=$(git diff --cached --numstat "$file" | awk '{
215+
if ($1 != "0" && $2 != "0")
216+
printf "%s insertions(+), %s deletions(-)", $1, $2;
217+
else if ($1 != "0")
218+
printf "%s insertions(+)", $1;
219+
else if ($2 != "0")
220+
printf "%s deletions(-)", $2;
221+
}')
222+
if [ -n "$summary" ]; then
223+
echo " - $file : $summary"
216224
else
217225
echo " - $file"
218226
fi

0 commit comments

Comments
 (0)