devshell: stash only unstaged changes in pre-commit hook

This commit is contained in:
teutat3s 2023-07-02 14:49:47 +02:00
parent ea69c1d12c
commit 319a96f5ff
Signed by: teutat3s
GPG key ID: 4FA1D3FA524F22C1

View file

@ -8,8 +8,14 @@ else
fi fi
# Stash only unstaged changes, keeping staged changes # Stash only unstaged changes, keeping staged changes
# We have to stash two times, because:
# --keep-index also stashes the staged changes.
# The staged changes end up in both the stage AND the stash.
# https://overflow.hostux.net/questions/7650797/how-to-stash-only-unstaged-changes-in-git#60875082
old_stash=$(git rev-parse --quiet --verify refs/stash) old_stash=$(git rev-parse --quiet --verify refs/stash)
git stash push --quiet --keep-index -m 'Unstaged changes before pre-commit hook' 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}"
new_stash=$(git rev-parse --quiet --verify refs/stash) new_stash=$(git rev-parse --quiet --verify refs/stash)
diff="git diff-index --name-only --cached $against --diff-filter d" diff="git diff-index --name-only --cached $against --diff-filter d"