]>
Commit | Line | Data |
---|---|---|
78751302 DC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2011 David Caldwell | |
4 | # | |
5 | ||
6 | test_description='Test git stash --include-untracked' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | test_expect_success 'stash save --include-untracked some dirty working directory' ' | |
32b7385e | 11 | echo 1 >file && |
78751302 DC |
12 | git add file && |
13 | test_tick && | |
14 | git commit -m initial && | |
32b7385e | 15 | echo 2 >file && |
78751302 | 16 | git add file && |
32b7385e | 17 | echo 3 >file && |
78751302 | 18 | test_tick && |
32b7385e DL |
19 | echo 1 >file2 && |
20 | echo 1 >HEAD && | |
7474b8b4 BC |
21 | mkdir untracked && |
22 | echo untracked >untracked/untracked && | |
78751302 DC |
23 | git stash --include-untracked && |
24 | git diff-files --quiet && | |
25 | git diff-index --cached --quiet HEAD | |
26 | ' | |
27 | ||
78751302 | 28 | test_expect_success 'stash save --include-untracked cleaned the untracked files' ' |
bbaa45c3 DL |
29 | cat >expect <<-EOF && |
30 | ?? actual | |
31 | ?? expect | |
32 | EOF | |
33 | ||
c995ef49 | 34 | git status --porcelain >actual && |
4fd73124 | 35 | test_cmp expect actual |
78751302 DC |
36 | ' |
37 | ||
78751302 | 38 | test_expect_success 'stash save --include-untracked stashed the untracked files' ' |
bbaa45c3 DL |
39 | tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) && |
40 | untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) && | |
41 | cat >expect.diff <<-EOF && | |
42 | diff --git a/HEAD b/HEAD | |
43 | new file mode 100644 | |
44 | index 0000000..$tracked | |
45 | --- /dev/null | |
46 | +++ b/HEAD | |
47 | @@ -0,0 +1 @@ | |
48 | +1 | |
49 | diff --git a/file2 b/file2 | |
50 | new file mode 100644 | |
51 | index 0000000..$tracked | |
52 | --- /dev/null | |
53 | +++ b/file2 | |
54 | @@ -0,0 +1 @@ | |
55 | +1 | |
56 | diff --git a/untracked/untracked b/untracked/untracked | |
57 | new file mode 100644 | |
58 | index 0000000..$untracked | |
59 | --- /dev/null | |
60 | +++ b/untracked/untracked | |
61 | @@ -0,0 +1 @@ | |
62 | +untracked | |
63 | EOF | |
64 | cat >expect.lstree <<-EOF && | |
65 | HEAD | |
66 | file2 | |
67 | untracked | |
68 | EOF | |
69 | ||
44df2e29 JM |
70 | test_path_is_missing file2 && |
71 | test_path_is_missing untracked && | |
72 | test_path_is_missing HEAD && | |
73 | git diff HEAD stash^3 -- HEAD file2 untracked >actual && | |
4fd73124 BC |
74 | test_cmp expect.diff actual && |
75 | git ls-tree --name-only stash^3: >actual && | |
76 | test_cmp expect.lstree actual | |
78751302 DC |
77 | ' |
78 | test_expect_success 'stash save --patch --include-untracked fails' ' | |
79 | test_must_fail git stash --patch --include-untracked | |
80 | ' | |
81 | ||
82 | test_expect_success 'stash save --patch --all fails' ' | |
83 | test_must_fail git stash --patch --all | |
84 | ' | |
85 | ||
bbaa45c3 DL |
86 | test_expect_success 'clean up untracked/untracked file to prepare for next tests' ' |
87 | git clean --force --quiet | |
78751302 | 88 | |
bbaa45c3 | 89 | ' |
78751302 DC |
90 | |
91 | test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' | |
bbaa45c3 DL |
92 | cat >expect <<-EOF && |
93 | M file | |
94 | ?? HEAD | |
95 | ?? actual | |
96 | ?? expect | |
97 | ?? file2 | |
98 | ?? untracked/ | |
99 | EOF | |
100 | ||
78751302 | 101 | git stash pop && |
c995ef49 | 102 | git status --porcelain >actual && |
7474b8b4 | 103 | test_cmp expect actual && |
cba12621 EP |
104 | test "1" = "$(cat file2)" && |
105 | test untracked = "$(cat untracked/untracked)" | |
78751302 DC |
106 | ' |
107 | ||
bbaa45c3 DL |
108 | test_expect_success 'clean up untracked/ directory to prepare for next tests' ' |
109 | git clean --force --quiet -d | |
110 | ' | |
78751302 DC |
111 | |
112 | test_expect_success 'stash save -u dirty index' ' | |
32b7385e | 113 | echo 4 >file3 && |
78751302 DC |
114 | git add file3 && |
115 | test_tick && | |
116 | git stash -u | |
117 | ' | |
118 | ||
78751302 | 119 | test_expect_success 'stash save --include-untracked dirty index got stashed' ' |
bbaa45c3 DL |
120 | blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) && |
121 | cat >expect <<-EOF && | |
122 | diff --git a/file3 b/file3 | |
123 | new file mode 100644 | |
124 | index 0000000..$blob | |
125 | --- /dev/null | |
126 | +++ b/file3 | |
127 | @@ -0,0 +1 @@ | |
128 | +4 | |
129 | EOF | |
130 | ||
78751302 | 131 | git stash pop --index && |
bbaa45c3 | 132 | test_when_finished "git reset" && |
4fd73124 BC |
133 | git diff --cached >actual && |
134 | test_cmp expect actual | |
78751302 DC |
135 | ' |
136 | ||
44df2e29 | 137 | # Must direct output somewhere where it won't be considered an untracked file |
78751302 | 138 | test_expect_success 'stash save --include-untracked -q is quiet' ' |
32b7385e DL |
139 | echo 1 >file5 && |
140 | git stash save --include-untracked --quiet >.git/stash-output.out 2>&1 && | |
44df2e29 JM |
141 | test_line_count = 0 .git/stash-output.out && |
142 | rm -f .git/stash-output.out | |
78751302 DC |
143 | ' |
144 | ||
145 | test_expect_success 'stash save --include-untracked removed files' ' | |
146 | rm -f file && | |
147 | git stash save --include-untracked && | |
32b7385e | 148 | echo 1 >expect && |
bbaa45c3 | 149 | test_when_finished "rm -f expect" && |
dcbaa0b3 | 150 | test_cmp expect file |
78751302 DC |
151 | ' |
152 | ||
78751302 DC |
153 | test_expect_success 'stash save --include-untracked removed files got stashed' ' |
154 | git stash pop && | |
44df2e29 | 155 | test_path_is_missing file |
78751302 DC |
156 | ' |
157 | ||
78751302 | 158 | test_expect_success 'stash save --include-untracked respects .gitignore' ' |
bbaa45c3 DL |
159 | cat >.gitignore <<-EOF && |
160 | .gitignore | |
161 | ignored | |
162 | ignored.d/ | |
163 | EOF | |
164 | ||
32b7385e | 165 | echo ignored >ignored && |
7474b8b4 BC |
166 | mkdir ignored.d && |
167 | echo ignored >ignored.d/untracked && | |
78751302 DC |
168 | git stash -u && |
169 | test -s ignored && | |
7474b8b4 | 170 | test -s ignored.d/untracked && |
78751302 DC |
171 | test -s .gitignore |
172 | ' | |
173 | ||
174 | test_expect_success 'stash save -u can stash with only untracked files different' ' | |
32b7385e | 175 | echo 4 >file4 && |
c995ef49 | 176 | git stash -u && |
44df2e29 | 177 | test_path_is_missing file4 |
78751302 DC |
178 | ' |
179 | ||
180 | test_expect_success 'stash save --all does not respect .gitignore' ' | |
181 | git stash -a && | |
44df2e29 JM |
182 | test_path_is_missing ignored && |
183 | test_path_is_missing ignored.d && | |
184 | test_path_is_missing .gitignore | |
78751302 DC |
185 | ' |
186 | ||
187 | test_expect_success 'stash save --all is stash poppable' ' | |
188 | git stash pop && | |
189 | test -s ignored && | |
7474b8b4 | 190 | test -s ignored.d/untracked && |
78751302 DC |
191 | test -s .gitignore |
192 | ' | |
193 | ||
df6bba09 TG |
194 | test_expect_success 'stash push --include-untracked with pathspec' ' |
195 | >foo && | |
196 | >bar && | |
197 | git stash push --include-untracked -- foo && | |
198 | test_path_is_file bar && | |
199 | test_path_is_missing foo && | |
200 | git stash pop && | |
201 | test_path_is_file bar && | |
202 | test_path_is_file foo | |
203 | ' | |
204 | ||
205 | test_expect_success 'stash push with $IFS character' ' | |
206 | >"foo bar" && | |
207 | >foo && | |
208 | >bar && | |
209 | git add foo* && | |
210 | git stash push --include-untracked -- "foo b*" && | |
211 | test_path_is_missing "foo bar" && | |
212 | test_path_is_file foo && | |
213 | test_path_is_file bar && | |
214 | git stash pop && | |
215 | test_path_is_file "foo bar" && | |
216 | test_path_is_file foo && | |
217 | test_path_is_file bar | |
218 | ' | |
219 | ||
bbffd87d | 220 | test_expect_success 'stash previously ignored file' ' |
bbaa45c3 DL |
221 | cat >.gitignore <<-EOF && |
222 | ignored | |
223 | ignored.d/* | |
224 | EOF | |
225 | ||
bbffd87d NMC |
226 | git reset HEAD && |
227 | git add .gitignore && | |
228 | git commit -m "Add .gitignore" && | |
229 | >ignored.d/foo && | |
32b7385e | 230 | echo "!ignored.d/foo" >>.gitignore && |
bbffd87d NMC |
231 | git stash save --include-untracked && |
232 | test_path_is_missing ignored.d/foo && | |
233 | git stash pop && | |
234 | test_path_is_file ignored.d/foo | |
235 | ' | |
236 | ||
833622a9 TG |
237 | test_expect_success 'stash -u -- <untracked> doesnt print error' ' |
238 | >untracked && | |
239 | git stash push -u -- untracked 2>actual && | |
240 | test_path_is_missing untracked && | |
241 | test_line_count = 0 actual | |
242 | ' | |
243 | ||
244 | test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' ' | |
245 | >tracked && | |
246 | git add tracked && | |
247 | >untracked && | |
248 | git stash push -u -- untracked && | |
249 | test_path_is_missing untracked && | |
250 | test_path_is_file tracked | |
251 | ' | |
252 | ||
253 | test_expect_success 'stash -u -- <tracked> <untracked> clears changes in both' ' | |
254 | >tracked && | |
255 | git add tracked && | |
256 | >untracked && | |
257 | git stash push -u -- tracked untracked && | |
258 | test_path_is_missing tracked && | |
259 | test_path_is_missing untracked | |
260 | ' | |
261 | ||
262 | test_expect_success 'stash --all -- <ignored> stashes ignored file' ' | |
263 | >ignored.d/bar && | |
264 | git stash push --all -- ignored.d/bar && | |
265 | test_path_is_missing ignored.d/bar | |
266 | ' | |
267 | ||
268 | test_expect_success 'stash --all -- <tracked> <ignored> clears changes in both' ' | |
269 | >tracked && | |
270 | git add tracked && | |
271 | >ignored.d/bar && | |
272 | git stash push --all -- tracked ignored.d/bar && | |
273 | test_path_is_missing tracked && | |
274 | test_path_is_missing ignored.d/bar | |
275 | ' | |
276 | ||
277 | test_expect_success 'stash -u -- <ignored> leaves ignored file alone' ' | |
278 | >ignored.d/bar && | |
279 | git stash push -u -- ignored.d/bar && | |
280 | test_path_is_file ignored.d/bar | |
281 | ' | |
282 | ||
aa74be31 EN |
283 | test_expect_success 'stash -u -- <non-existent> shows no changes when there are none' ' |
284 | git stash push -u -- non-existent >actual && | |
d319bb18 TG |
285 | echo "No local changes to save" >expect && |
286 | test_i18ncmp expect actual | |
287 | ' | |
288 | ||
1366c78c JS |
289 | test_expect_success 'stash -u with globs' ' |
290 | >untracked.txt && | |
291 | git stash -u -- ":(glob)**/*.txt" && | |
292 | test_path_is_missing untracked.txt | |
293 | ' | |
294 | ||
78751302 | 295 | test_done |