diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook index 4e8e0cb..7660cca 100755 --- a/hooks/pre-commit.hook +++ b/hooks/pre-commit.hook @@ -24,6 +24,8 @@ do git show ":$file" > "$tmpfile" # Format it "$formatter" --no-backup -c AfRApay.MateCard/.uncrustify.cfg "$tmpfile" + # Format the non-tmp file too, to prevent loops + "$formatter" --no-backup -c AfRApay.MateCard/.uncrustify.cfg "$file" # Create a blob object from the formatted file hash=`git hash-object -w "$tmpfile"` # Add it back to index @@ -32,6 +34,12 @@ do rm "$tmpfile" done +# If amend - force succeed +IS_AMEND=$(ps -ocommand= -p $PPID | grep -e '--amend'); +if [ -n "$IS_AMEND" ]; then + exit 0 +fi + # If no files left in index after formatting - fail ret=0 if [ ! "`git diff --cached --name-only`" ]; then