From ac34813571d7962c001142febbc48982338db975 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 8 Feb 2023 16:49:47 +0100 Subject: [PATCH] Update pre-commit hook --- hooks/pre-commit.hook | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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