Skip to content

Commit 1937610

Browse files
peffgitster
authored andcommitted
Revert "stash: require a clean index to apply"
This reverts commit ed178ef. That commit was an attempt to improve the safety of applying a stash, because the application process may create conflicted index entries, after which it is hard to restore the original index state. Unfortunately, this hurts some common workflows around "git stash -k", like: git add -p ;# (1) stage set of proposed changes git stash -k ;# (2) get rid of everything else make test ;# (3) make sure proposal is reasonable git stash apply ;# (4) restore original working tree If you "git commit" between steps (3) and (4), then this just works. However, if these steps are part of a pre-commit hook, you don't have that opportunity (you have to restore the original state regardless of whether the tests passed or failed). It's possible that we could provide better tools for this sort of workflow. In particular, even before ed178ef, it could fail with a conflict if there were conflicting hunks in the working tree and index (since the "stash -k" puts the index version into the working tree, and we then attempt to apply the differences between HEAD and the old working tree on top of that). But the fact remains that people have been using it happily for a while, and the safety provided by ed178ef is simply not that great. Let's revert it for now. In the long run, people can work on improving stash for this sort of workflow, but the safety tradeoff is not worth it in the meantime. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed178ef commit 1937610

File tree

2 files changed

+0
-9
lines changed

2 files changed

+0
-9
lines changed

git-stash.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ apply_stash () {
442442
assert_stash_like "$@"
443443

444444
git update-index -q --refresh || die "$(gettext "unable to refresh index")"
445-
git diff-index --cached --quiet --ignore-submodules HEAD -- ||
446-
die "$(gettext "Cannot apply stash: Your index contains uncommitted changes.")"
447445

448446
# current index state
449447
c_tree=$(git write-tree) ||

t/t3903-stash.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ test_expect_success 'applying bogus stash does nothing' '
4545
test_cmp expect file
4646
'
4747

48-
test_expect_success 'apply requires a clean index' '
49-
test_when_finished "git reset --hard" &&
50-
echo changed >other-file &&
51-
git add other-file &&
52-
test_must_fail git stash apply
53-
'
54-
5548
test_expect_success 'apply does not need clean working directory' '
5649
echo 4 >other-file &&
5750
git stash apply &&

0 commit comments

Comments
 (0)