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.
This commit is contained in:
Hayden Roche 2020-11-13 13:38:58 -06:00
parent d4e1340027
commit cd61fbd0fe

View File

@ -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"