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 test_cmp 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' '
97 git stash drop stash@{1} &&
98 test 2 = $(git stash list | wc -l) &&
100 test 9 = $(cat file) &&
101 test 1 = $(git show :file) &&
102 test 1 = $(git show HEAD:file) &&
106 test 3 = $(cat file) &&
107 test 1 = $(git show :file) &&
108 test 1 = $(git show HEAD:file)
111 test_expect_success
'stash pop' '
114 test 3 = $(cat file) &&
115 test 1 = $(git show :file) &&
116 test 1 = $(git show HEAD:file) &&
117 test 0 = $(git stash list | wc -l)
121 diff --git a/file2 b/file2
123 index 0000000..1fe912c
131 diff --git a/file b/file
132 index 257cc56..5716ca5 100644
141 diff --git a/file b/file
142 index 7601807..5716ca5 100644
148 diff --git a/file2 b/file2
150 index 0000000..1fe912c
157 test_expect_success
'stash branch' '
159 git commit file -m first
165 git commit file -m second &&
166 git stash branch stashbranch &&
167 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
168 test $(git rev-parse HEAD) = $(git rev-parse master^) &&
169 git diff --cached > output &&
170 test_cmp output expect &&
172 test_cmp output expect1 &&
174 git commit -m alternate\ second &&
175 git diff master..stashbranch > output &&
176 test_cmp output expect2 &&
177 test 0 = $(git stash list | wc -l)
180 test_expect_success
'apply -q is quiet' '
183 git stash apply -q > output.out 2>&1 &&
187 test_expect_success
'save -q is quiet' '
188 git stash save --quiet > output.out 2>&1 &&
192 test_expect_success
'pop -q is quiet' '
193 git stash pop -q > output.out 2>&1 &&
197 test_expect_success
'pop -q --index works and is quiet' '
200 git stash save --quiet &&
201 git stash pop -q --index > output.out 2>&1 &&
202 test foo = "$(git show :file)" &&
206 test_expect_success
'drop -q is quiet' '
208 git stash drop -q > output.out 2>&1 &&
212 test_expect_success
'stash -k' '
217 test bar,bar4 = $(cat file),$(cat file2)
220 test_expect_success
'stash --invalid-option' '
224 test_must_fail git stash --invalid-option &&
225 test_must_fail git stash save --invalid-option &&
226 test bar5,bar6 = $(cat file),$(cat file2) &&
227 git stash -- -message-starting-with-dash &&
228 test bar,bar2 = $(cat file),$(cat file2)
231 test_expect_success
'stash an added file' '
235 git stash save "added file" &&
238 test new = "$(cat file3)"
241 test_expect_success
'stash rm then recreate' '
245 git stash save "rm then recreate" &&
246 test bar = "$(cat file)" &&
248 test bar7 = "$(cat file)"
251 test_expect_success
'stash rm and ignore' '
254 echo file >.gitignore &&
255 git stash save "rm and ignore" &&
256 test bar = "$(cat file)" &&
257 test file = "$(cat .gitignore)"
260 test file = "$(cat .gitignore)"
263 test_expect_success
'stash rm and ignore (stage .gitignore)' '
266 echo file >.gitignore &&
267 git add .gitignore &&
268 git stash save "rm and ignore (stage .gitignore)" &&
269 test bar = "$(cat file)" &&
273 test file = "$(cat .gitignore)"
276 test_expect_success SYMLINKS
'stash file to symlink' '
280 git stash save "file to symlink" &&
282 test bar = "$(cat file)" &&
284 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
287 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
291 git stash save "file to symlink (stage rm)" &&
293 test bar = "$(cat file)" &&
295 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
298 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
303 git stash save "file to symlink (full stage)" &&
305 test bar = "$(cat file)" &&
307 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
310 # This test creates a commit with a symlink used for the following tests
312 test_expect_success SYMLINKS
'stash symlink to file' '
314 ln -s file filelink &&
316 git commit -m "Add symlink" &&
319 git stash save "symlink to file" &&
321 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
323 ! test -h filelink &&
324 test bar = "$(cat file)"
327 test_expect_success SYMLINKS
'stash symlink to file (stage rm)' '
331 git stash save "symlink to file (stage rm)" &&
333 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
335 ! test -h filelink &&
336 test bar = "$(cat file)"
339 test_expect_success SYMLINKS
'stash symlink to file (full stage)' '
344 git stash save "symlink to file (full stage)" &&
346 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
348 ! test -h filelink &&
349 test bar = "$(cat file)"
352 test_expect_failure
'stash directory to file' '
355 echo foo >dir/file &&
357 git commit -m "Add file in dir" &&
360 git stash save "directory to file" &&
362 test foo = "$(cat dir/file)" &&
363 test_must_fail git stash apply &&
364 test bar = "$(cat dir)" &&
365 git reset --soft HEAD^
368 test_expect_failure
'stash file to directory' '
372 echo foo >file/file &&
373 git stash save "file to directory" &&
375 test bar = "$(cat file)" &&
378 test foo = "$(cat file/file)"