Skip to content

Instantly share code, notes, and snippets.

@itsjavi
Created May 26, 2020 14:51
Show Gist options
  • Save itsjavi/c3965cb1e955f2a464a017f886c48084 to your computer and use it in GitHub Desktop.
Save itsjavi/c3965cb1e955f2a464a017f886c48084 to your computer and use it in GitHub Desktop.
detect changed lines (additions + deletions) in git
#!/usr/bin/env bash
changed_lines_threshold=4
changed_lines=$(git diff --numstat --pretty="%H" HEAD^ HEAD | awk 'NF==3 {numlines+=$1+$2} END {printf("%d", numlines)}')
if [[ $changed_lines -gt $changed_lines_threshold ]]]; then
echo "ERROR: Source code changes detected after last command (${changed_lines} lines). Aborting.";
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment