From 135a4619bc5ff8a463cb9b531aeec8f74df12205 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 8 Feb 2023 23:31:06 +0100 Subject: [PATCH] Fix pre commit hook --- hooks/pre-commit.hook | 8 ++++++++ 1 file changed, 8 insertions(+) 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