3 # Copyright (c) 2007 Johannes E Schindelin
6 test_description
='Test git stash'
10 test_expect_success
'stash some dirty working directory' '
14 git commit -m initial &&
20 git diff-files --quiet &&
21 git diff-index --cached --quiet HEAD
25 diff --git a/file b/file
26 index 0cfbf08..00750ed 100644
34 test_expect_success
'parents of stash' '
35 test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
36 git diff stash^2..stash > output &&
37 test_cmp output expect
40 test_expect_success
'apply needs clean working directory' '
41 echo 4 > other-file &&
43 echo 5 > other-file &&
44 test_must_fail git stash apply
47 test_expect_success
'apply stashed changes' '
50 git commit -m other-file &&
52 test 3 = $(cat file) &&
53 test 1 = $(git show :file) &&
54 test 1 = $(git show HEAD:file)
57 test_expect_success
'apply stashed changes (including index)' '
58 git reset --hard HEAD^ &&
59 echo 6 > other-file &&
62 git commit -m other-file &&
63 git stash apply --index &&
64 test 3 = $(cat file) &&
65 test 2 = $(git show :file) &&
66 test 1 = $(git show HEAD:file)
69 test_expect_success
'unstashing in a subdirectory' '
70 git reset --hard HEAD &&
77 test_expect_success
'drop top stash' '
79 git stash list > stashlist1 &&
83 git stash list > stashlist2 &&
84 diff stashlist1 stashlist2 &&
86 test 3 = $(cat file) &&
87 test 1 = $(git show :file) &&
88 test 1 = $(git show HEAD:file)
91 test_expect_success
'drop middle stash' '
98 git stash drop stash@{1} &&
99 test 2 = $(git stash list | wc -l) &&
101 test 9 = $(cat file) &&
102 test 1 = $(git show :file) &&
103 test 1 = $(git show HEAD:file) &&
107 test 3 = $(cat file) &&
108 test 1 = $(git show :file) &&
109 test 1 = $(git show HEAD:file)
112 test_expect_success
'stash pop' '
115 test 3 = $(cat file) &&
116 test 1 = $(git show :file) &&
117 test 1 = $(git show HEAD:file) &&
118 test 0 = $(git stash list | wc -l)
122 diff --git a/file2 b/file2
124 index 0000000..1fe912c
132 diff --git a/file b/file
133 index 257cc56..5716ca5 100644
142 diff --git a/file b/file
143 index 7601807..5716ca5 100644
149 diff --git a/file2 b/file2
151 index 0000000..1fe912c
158 test_expect_success
'stash branch' '
160 git commit file -m first
166 git commit file -m second &&
167 git stash branch stashbranch &&
168 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
169 test $(git rev-parse HEAD) = $(git rev-parse master^) &&
170 git diff --cached > output &&
171 test_cmp output expect &&
173 test_cmp output expect1 &&
175 git commit -m alternate\ second &&
176 git diff master..stashbranch > output &&
177 test_cmp output expect2 &&
178 test 0 = $(git stash list | wc -l)