summaryrefslogtreecommitdiff
path: root/git-legacy-stash.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-10-30 10:49:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-11-02 06:22:45 (GMT)
commit4a58c3d7f7a83ebcd4ede635871cab7be24f7f3f (patch)
tree127863a57bb8f9c640db43557850e6589d6b711c /git-legacy-stash.sh
parent8dfb04ae964868dda758997e5e7da29edff6164b (diff)
downloadgit-4a58c3d7f7a83ebcd4ede635871cab7be24f7f3f.zip
git-4a58c3d7f7a83ebcd4ede635871cab7be24f7f3f.tar.gz
git-4a58c3d7f7a83ebcd4ede635871cab7be24f7f3f.tar.bz2
stash: handle staged changes in skip-worktree files correctly
When calling `git stash` while changes were staged for files that are marked with the `skip-worktree` bit (e.g. files that are excluded in a sparse checkout), the files are recorded as _deleted_ instead. The reason is that `git stash` tries to construct the tree reflecting the worktree essentially by copying the index to a temporary one and then updating the files from the worktree. Crucially, it calls `git diff-index` to update also those files that are in the HEAD but have been unstaged in the index. However, when the temporary index is updated via `git update-index --add --remove`, skip-worktree entries mark the files as deleted by mistake. Let's use the newly-introduced `--ignore-skip-worktree-entries` option of `git update-index` to prevent exactly this from happening. Note that the regression test case deliberately avoids replicating the scenario described above and instead tries to recreate just the symptom. Reported by Dan Thompson. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-legacy-stash.sh')
-rwxr-xr-xgit-legacy-stash.sh3
1 files changed, 2 insertions, 1 deletions
diff --git a/git-legacy-stash.sh b/git-legacy-stash.sh
index f60e9b3..5398a51 100755
--- a/git-legacy-stash.sh
+++ b/git-legacy-stash.sh
@@ -193,7 +193,8 @@ create_stash () {
GIT_INDEX_FILE="$TMPindex" &&
export GIT_INDEX_FILE &&
git diff-index --name-only -z HEAD -- "$@" >"$TMP-stagenames" &&
- git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
+ git update-index --ignore-skip-worktree-entries \
+ -z --add --remove --stdin <"$TMP-stagenames" &&
git write-tree &&
rm -f "$TMPindex"
) ) ||