From cd61fbd0feaf329f24f2de8052beb851d83d0f28 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Fri, 13 Nov 2020 13:38:58 -0600 Subject: [PATCH] Modify pre-commit.sh to only stash and stash pop if there are modified files not added to the index. Before this change, if there was nothing to stash, the last thing you stashed would get popped at the end of the script. --- pre-commit.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index 17e312899..9c76f4b30 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -8,9 +8,15 @@ echo "\n\nSaving current config\n\n" cp config.status tmp.status cp wolfssl/options.h tmp.options.h -# stash modified files not part of this commit, don't test them -echo "\n\nStashing any modified files not part of commit\n\n" -git stash -q --keep-index +# stash modified files, if any, that are not part of this commit, don't test +# them +STASHED=0 +if ! git diff --quiet +then + STASHED=1 + echo "\n\nStashing modified files not part of commit\n\n" + git stash -q --keep-index +fi # do the commit tests echo "\n\nRunning commit tests...\n\n" @@ -18,8 +24,11 @@ echo "\n\nRunning commit tests...\n\n" RESULT=$? # restore modified files not part of this commit -echo "\n\nPopping any stashed modified files not part of commit\n" -git stash pop -q +if test $STASHED -eq 1 +then + echo "\n\nPopping stashed modified files not part of commit\n" + git stash pop -q +fi # restore current config echo "\nRestoring current config\n"