Merge branch 'rc/maint-http-no-head-pack-check' into maint
[git/jnareb-git/bp-gitweb.git] / t / t3903-stash.sh
blob7a3fb679571a9fc79135f8b9495462f723b663af
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E Schindelin
6 test_description='Test git stash'
8 . ./test-lib.sh
10 test_expect_success 'stash some dirty working directory' '
11 echo 1 > file &&
12 git add file &&
13 test_tick &&
14 git commit -m initial &&
15 echo 2 > file &&
16 git add file &&
17 echo 3 > file &&
18 test_tick &&
19 git stash &&
20 git diff-files --quiet &&
21 git diff-index --cached --quiet HEAD
24 cat > expect << EOF
25 diff --git a/file b/file
26 index 0cfbf08..00750ed 100644
27 --- a/file
28 +++ b/file
29 @@ -1 +1 @@
32 EOF
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 &&
42 git add other-file &&
43 echo 5 > other-file &&
44 test_must_fail git stash apply
47 test_expect_success 'apply stashed changes' '
48 git add other-file &&
49 test_tick &&
50 git commit -m other-file &&
51 git stash apply &&
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 &&
60 git add other-file &&
61 test_tick &&
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 &&
71 mkdir subdir &&
72 cd subdir &&
73 git stash apply &&
74 cd ..
77 test_expect_success 'drop top stash' '
78 git reset --hard &&
79 git stash list > stashlist1 &&
80 echo 7 > file &&
81 git stash &&
82 git stash drop &&
83 git stash list > stashlist2 &&
84 diff stashlist1 stashlist2 &&
85 git stash apply &&
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' '
92 git reset --hard &&
93 echo 8 > file &&
94 git stash &&
95 echo 9 > file &&
96 git stash &&
97 git stash drop stash@{1} &&
98 test 2 = $(git stash list | wc -l) &&
99 git stash apply &&
100 test 9 = $(cat file) &&
101 test 1 = $(git show :file) &&
102 test 1 = $(git show HEAD:file) &&
103 git reset --hard &&
104 git stash drop &&
105 git stash apply &&
106 test 3 = $(cat file) &&
107 test 1 = $(git show :file) &&
108 test 1 = $(git show HEAD:file)
111 test_expect_success 'stash pop' '
112 git reset --hard &&
113 git 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)
120 cat > expect << EOF
121 diff --git a/file2 b/file2
122 new file mode 100644
123 index 0000000..1fe912c
124 --- /dev/null
125 +++ b/file2
126 @@ -0,0 +1 @@
127 +bar2
130 cat > expect1 << EOF
131 diff --git a/file b/file
132 index 257cc56..5716ca5 100644
133 --- a/file
134 +++ b/file
135 @@ -1 +1 @@
136 -foo
137 +bar
140 cat > expect2 << EOF
141 diff --git a/file b/file
142 index 7601807..5716ca5 100644
143 --- a/file
144 +++ b/file
145 @@ -1 +1 @@
146 -baz
147 +bar
148 diff --git a/file2 b/file2
149 new file mode 100644
150 index 0000000..1fe912c
151 --- /dev/null
152 +++ b/file2
153 @@ -0,0 +1 @@
154 +bar2
157 test_expect_success 'stash branch' '
158 echo foo > file &&
159 git commit file -m first
160 echo bar > file &&
161 echo bar2 > file2 &&
162 git add file2 &&
163 git stash &&
164 echo baz > file &&
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 &&
171 git diff > output &&
172 test_cmp output expect1 &&
173 git add file &&
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' '
181 echo foo > file &&
182 git stash &&
183 git stash apply -q > output.out 2>&1 &&
184 test ! -s output.out
187 test_expect_success 'save -q is quiet' '
188 git stash save --quiet > output.out 2>&1 &&
189 test ! -s output.out
192 test_expect_success 'pop -q is quiet' '
193 git stash pop -q > output.out 2>&1 &&
194 test ! -s output.out
197 test_expect_success 'drop -q is quiet' '
198 git stash &&
199 git stash drop -q > output.out 2>&1 &&
200 test ! -s output.out
203 test_done