@matheusbsbs / matheus-bagliano / commits / e0e2a9cbfa
Fork 0

stash: drop dirty worktree check on apply

Before we apply a stash, we make sure there are no changes in the worktree that are not in the index. This check dates back to the original git-stash.sh, and is presumably intended to prevent changes in the working tree from being accidentally lost during the merge. However, this check has two problems: 1. It is overly restrictive. If my stash changes only file "foo", but "bar" is dirty in the working tree, it will prevent us from applying the stash. 2. It is redundant. We don't touch the working tree at all until we actually call merge-recursive. But it has its own (much more accurate) checks to avoid losing working tree data, and will abort the merge with a nicer message telling us which paths were problems. So we can simply drop the check entirely. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 5, 2011 at 17:23 UTC e0e2a9cbfa938d0f1e9857d5ca5b196360663440
2 files changed +17 -7
git-stash.sh
+1 -3
@@ -344,9 +344,7 @@ apply_stash () {
344
345 assert_stash_like "$@"
346
347 - git update-index -q --refresh &&
348 - git diff-files --quiet --ignore-submodules ||
349 - die 'Cannot apply to a dirty working tree, please stage your changes'
347 + git update-index -q --refresh || die 'unable to refresh index'
348
349 # current index state
350 c_tree=$(git write-tree) ||
t/t3903-stash.sh
+16 -4
@@ -37,14 +37,26 @@ test_expect_success 'parents of stash' '
37 test_cmp output expect
38 '
39
40 -test_expect_success 'apply needs clean working directory' '
41 - echo 4 > other-file &&
40 +test_expect_success 'apply does not need clean working directory' '
41 + echo 4 >other-file &&
42 git add other-file &&
43 - echo 5 > other-file &&
44 - test_must_fail git stash apply
43 + echo 5 >other-file &&
44 + git stash apply &&
45 + echo 3 >expect &&
46 + test_cmp expect file
47 +'
48 +
49 +test_expect_success 'apply does not clobber working directory changes' '
50 + git reset --hard &&
51 + echo 4 >file &&
52 + test_must_fail git stash apply &&
53 + echo 4 >expect &&
54 + test_cmp expect file
55 '
56
57 test_expect_success 'apply stashed changes' '
58 + git reset --hard &&
59 + echo 5 >other-file &&
60 git add other-file &&
61 test_tick &&
62 git commit -m other-file &&