3 # Copyright (c) 2011 David Caldwell
6 test_description
='Test git stash --include-untracked'
10 test_expect_success
'stash save --include-untracked some dirty working directory' '
14 git commit -m initial &&
22 echo untracked >untracked/untracked &&
23 git stash --include-untracked &&
24 git diff-files --quiet &&
25 git diff-index --cached --quiet HEAD
28 test_expect_success
'stash save --include-untracked cleaned the untracked files' '
34 git status --porcelain >actual &&
35 test_cmp expect actual
38 test_expect_success
'stash save --include-untracked stashed the untracked files' '
39 one_blob=$(echo 1 | git hash-object --stdin) &&
40 tracked=$(git rev-parse --short "$one_blob") &&
41 untracked_blob=$(echo untracked | git hash-object --stdin) &&
42 untracked=$(git rev-parse --short "$untracked_blob") &&
43 cat >expect.diff <<-EOF &&
44 diff --git a/HEAD b/HEAD
46 index 0000000..$tracked
51 diff --git a/file2 b/file2
53 index 0000000..$tracked
58 diff --git a/untracked/untracked b/untracked/untracked
60 index 0000000..$untracked
62 +++ b/untracked/untracked
66 cat >expect.lstree <<-EOF &&
72 test_path_is_missing file2 &&
73 test_path_is_missing untracked &&
74 test_path_is_missing HEAD &&
75 git diff HEAD stash^3 -- HEAD file2 untracked >actual &&
76 test_cmp expect.diff actual &&
77 git ls-tree --name-only stash^3: >actual &&
78 test_cmp expect.lstree actual
80 test_expect_success
'stash save --patch --include-untracked fails' '
81 test_must_fail git stash --patch --include-untracked
84 test_expect_success
'stash save --patch --all fails' '
85 test_must_fail git stash --patch --all
88 test_expect_success
'clean up untracked/untracked file to prepare for next tests' '
89 git clean --force --quiet
93 test_expect_success
'stash pop after save --include-untracked leaves files untracked again' '
104 git status --porcelain >actual &&
105 test_cmp expect actual &&
106 echo 1 >expect_file2 &&
107 test_cmp expect_file2 file2 &&
108 echo untracked >untracked_expect &&
109 test_cmp untracked_expect untracked/untracked
112 test_expect_success
'clean up untracked/ directory to prepare for next tests' '
113 git clean --force --quiet -d
116 test_expect_success
'stash save -u dirty index' '
123 test_expect_success
'stash save --include-untracked dirty index got stashed' '
124 four_blob=$(echo 4 | git hash-object --stdin) &&
125 blob=$(git rev-parse --short "$four_blob") &&
126 cat >expect <<-EOF &&
127 diff --git a/file3 b/file3
136 git stash pop --index &&
137 test_when_finished "git reset" &&
138 git diff --cached >actual &&
139 test_cmp expect actual
142 # Must direct output somewhere where it won't be considered an untracked file
143 test_expect_success
'stash save --include-untracked -q is quiet' '
145 git stash save --include-untracked --quiet >.git/stash-output.out 2>&1 &&
146 test_line_count = 0 .git/stash-output.out &&
147 rm -f .git/stash-output.out
150 test_expect_success
'stash save --include-untracked removed files' '
152 git stash save --include-untracked &&
154 test_when_finished "rm -f expect" &&
158 test_expect_success
'stash save --include-untracked removed files got stashed' '
160 test_path_is_missing file
163 test_expect_success
'stash save --include-untracked respects .gitignore' '
164 cat >.gitignore <<-EOF &&
170 echo ignored >ignored &&
172 echo ignored >ignored.d/untracked &&
174 test_file_not_empty ignored &&
175 test_file_not_empty ignored.d/untracked &&
176 test_file_not_empty .gitignore
179 test_expect_success
'stash save -u can stash with only untracked files different' '
182 test_path_is_missing file4
185 test_expect_success
'stash save --all does not respect .gitignore' '
187 test_path_is_missing ignored &&
188 test_path_is_missing ignored.d &&
189 test_path_is_missing .gitignore
192 test_expect_success
'stash save --all is stash poppable' '
194 test_file_not_empty ignored &&
195 test_file_not_empty ignored.d/untracked &&
196 test_file_not_empty .gitignore
199 test_expect_success
'stash push --include-untracked with pathspec' '
202 git stash push --include-untracked -- foo &&
203 test_path_is_file bar &&
204 test_path_is_missing foo &&
206 test_path_is_file bar &&
207 test_path_is_file foo
210 test_expect_success
'stash push with $IFS character' '
215 git stash push --include-untracked -- "foo b*" &&
216 test_path_is_missing "foo bar" &&
217 test_path_is_file foo &&
218 test_path_is_file bar &&
220 test_path_is_file "foo bar" &&
221 test_path_is_file foo &&
222 test_path_is_file bar
225 test_expect_success
'stash previously ignored file' '
226 cat >.gitignore <<-EOF &&
232 git add .gitignore &&
233 git commit -m "Add .gitignore" &&
235 echo "!ignored.d/foo" >>.gitignore &&
236 git stash save --include-untracked &&
237 test_path_is_missing ignored.d/foo &&
239 test_path_is_file ignored.d/foo
242 test_expect_success
'stash -u -- <untracked> doesnt print error' '
244 git stash push -u -- untracked 2>actual &&
245 test_path_is_missing untracked &&
246 test_line_count = 0 actual
249 test_expect_success
'stash -u -- <untracked> leaves rest of working tree in place' '
253 git stash push -u -- untracked &&
254 test_path_is_missing untracked &&
255 test_path_is_file tracked
258 test_expect_success
'stash -u -- <tracked> <untracked> clears changes in both' '
262 git stash push -u -- tracked untracked &&
263 test_path_is_missing tracked &&
264 test_path_is_missing untracked
267 test_expect_success
'stash --all -- <ignored> stashes ignored file' '
269 git stash push --all -- ignored.d/bar &&
270 test_path_is_missing ignored.d/bar
273 test_expect_success
'stash --all -- <tracked> <ignored> clears changes in both' '
277 git stash push --all -- tracked ignored.d/bar &&
278 test_path_is_missing tracked &&
279 test_path_is_missing ignored.d/bar
282 test_expect_success
'stash -u -- <ignored> leaves ignored file alone' '
284 git stash push -u -- ignored.d/bar &&
285 test_path_is_file ignored.d/bar
288 test_expect_success
'stash -u -- <non-existent> shows no changes when there are none' '
289 git stash push -u -- non-existent >actual &&
290 echo "No local changes to save" >expect &&
291 test_cmp expect actual
294 test_expect_success
'stash -u with globs' '
296 git stash -u -- ":(glob)**/*.txt" &&
297 test_path_is_missing untracked.txt