diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook index 20de83f..ca516ef 100755 --- a/hooks/pre-commit.hook +++ b/hooks/pre-commit.hook @@ -17,16 +17,19 @@ fi for file in `git diff --cached --name-only --diff-filter=ACMR | grep $exts` do echo "Formatting $file" + # get tmpfile + tmpfile="${file//.cpp/.tmp.cpp}" + tmpfile="${file//.h/.tmp.h}" # Get the file from index - git show ":$file" > "$file.tmp" + git show ":$file" > "$tmpfile" # Format it - "$formatter" --no-backup -c AfRApay.MateCard/.uncrustify.cfg "$file.tmp" + "$formatter" --no-backup -c AfRApay.MateCard/.uncrustify.cfg "$tmpfile" # Create a blob object from the formatted file - hash=`git hash-object -w "$file.tmp"` + hash=`git hash-object -w "$tmpfile"` # Add it back to index git update-index --add --cacheinfo 100644 "$hash" "$file" # Remove the tmp file - rm "$file.tmp" + rm "$tmpfile" done # If no files left in index after formatting - fail