Re: [PATCH v2 4/4] builtin/stash: merge index in-core
Junio C Hamano <gitster@pobox.com> writes:
> The new test in the attached patch will fail with this step but if
> we revert the changes to builtin/stash.c in this step, it passes.
Oh, and with the change to the code, it passes again.
diff --git i/builtin/stash.c w/builtin/stash.c
index 219ca457be..44d962cc5d 100644
--- i/builtin/stash.c
+++ w/builtin/stash.c
@@ -639,7 +639,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
merge = lookup_tree(o.repo, &info->i_tree);
merge_base = lookup_tree(o.repo, &info->b_tree);
- merge_incore_nonrecursive(&o, head, merge, merge_base,
+ merge_incore_nonrecursive(&o, merge_base, merge, head,
&result);
if (!result.clean)
diff --git i/t/t3903-stash.sh w/t/t3903-stash.sh
index 3958ab3c8d..0a87e62b11 100755
--- i/t/t3903-stash.sh
+++ w/t/t3903-stash.sh
@@ -374,6 +374,38 @@ test_expect_success 'stash apply -q --index refreshes the index' '
test_cmp expect actual
'
+
+test_expect_success 'stash apply --index does not revert unrelated upstream index changes' '
+ test_when_finished "rm -fr playpen" &&
+ mkdir playpen &&
+ (
+ cd playpen &&
+ git init &&
+ echo "base1" >file1 &&
+ echo "base2" >file2 &&
+ git add file1 file2 &&
+ git commit -m "initial base" &&
+
+ # Make a staged change to file1 and stash it
+ echo "staged1" >file1 &&
+ git add file1 &&
+ git stash &&
+
+ # Upstream advances by modifying unrelated file2
+ echo "upstream2" >file2 &&
+ git add file2 &&
+ git commit -m "upstream change to file2" &&
+
+ # Apply the stash with --index
+ git stash apply --index &&
+
+ # Verify working tree and index state
+ test "$(git show :file1)" = "staged1" &&
+ test "$(git show :file2)" = "upstream2" &&
+ test "$(git show HEAD:file2)" = "upstream2"
+ )
+'
+
test_expect_success 'stash apply --index leaves everything untouched on failure' '
git reset --hard &&
echo test >other-file &&