From e26af156c6cb2a8d7c3289494953fc580f5e989a Mon Sep 17 00:00:00 2001 From: teutat3s Date: Tue, 4 Jul 2023 01:34:01 +0200 Subject: [PATCH] devshell: stash only unstaged changes in pre-commit hook --- shell/hooks/pre-commit.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shell/hooks/pre-commit.sh b/shell/hooks/pre-commit.sh index 19c5384e..558167eb 100755 --- a/shell/hooks/pre-commit.sh +++ b/shell/hooks/pre-commit.sh @@ -14,8 +14,12 @@ fi # https://overflow.hostux.net/questions/7650797/how-to-stash-only-unstaged-changes-in-git#60875082 old_stash=$(git rev-parse --quiet --verify refs/stash) git stash push --quiet --staged --message "Staged changes before pre-commit hook" -git stash push --quiet --keep-index --message "Unstaged changes before pre-commit hook" -git stash pop --quiet --index "stash@{1}" +git stash push --quiet --message "Unstaged changes before pre-commit hook" +if git stash show "stash@{1}" 2>/dev/null; then + git stash pop --quiet --index "stash@{1}" +else + git stash pop --quiet --index "stash@{0}" +fi new_stash=$(git rev-parse --quiet --verify refs/stash) diff="git diff-index --name-only --cached $against --diff-filter d"