Skip to content

Commit 9d4e28e

Browse files
peffgitster
authored andcommitted
stash: prefer plumbing over git-diff
When creating a stash, we need to look at the diff between the working tree and HEAD, and do so using the git-diff porcelain. Because git-diff enables porcelain config like renames by default, this causes at least one problem. The --name-only format will not mention the source side of a rename, meaning we will fail to stash a deletion that is part of a rename. We could fix that case by passing --no-renames, but this is a symptom of a larger problem. We should be using the diff-index plumbing here, which does not have renames enabled by default, and also does not respect any potentially confusing config options. Reported-by: Matthew Patey <matthew.patey2167@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 05219a1 commit 9d4e28e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

git-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ create_stash () {
116116
git read-tree --index-output="$TMPindex" -m $i_tree &&
117117
GIT_INDEX_FILE="$TMPindex" &&
118118
export GIT_INDEX_FILE &&
119-
git diff --name-only -z HEAD -- >"$TMP-stagenames" &&
119+
git diff-index --name-only -z HEAD -- >"$TMP-stagenames" &&
120120
git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
121121
git write-tree &&
122122
rm -f "$TMPindex"

t/t3903-stash.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,13 @@ test_expect_success 'stash list --cc shows combined diff' '
731731
test_cmp expect actual
732732
'
733733

734+
test_expect_success 'stash is not confused by partial renames' '
735+
mv file renamed &&
736+
git add renamed &&
737+
git stash &&
738+
git stash apply &&
739+
test_path_is_file renamed &&
740+
test_path_is_missing file
741+
'
742+
734743
test_done

0 commit comments

Comments
 (0)