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 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
44 index 0000000..$tracked
49 diff --git a/file2 b/file2
51 index 0000000..$tracked
56 diff --git a/untracked/untracked b/untracked/untracked
58 index 0000000..$untracked
60 +++ b/untracked/untracked
64 cat >expect.lstree <<-EOF &&
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 &&
74 test_cmp expect.diff actual &&
75 git ls-tree --name-only stash^3: >actual &&
76 test_cmp expect.lstree actual
78 test_expect_success 'stash save --patch --include-untracked fails' '
79 test_must_fail git stash --patch --include-untracked
82 test_expect_success 'stash save --patch --all fails' '
83 test_must_fail git stash --patch --all
86 test_expect_success 'clean up untracked/untracked file to prepare for next tests' '
87 git clean --force --quiet
91 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
102 git status --porcelain >actual &&
103 test_cmp expect actual &&
104 test "1" = "$(cat file2)" &&
105 test untracked = "$(cat untracked/untracked)"
108 test_expect_success 'clean up untracked/ directory to prepare for next tests' '
109 git clean --force --quiet -d
112 test_expect_success 'stash save -u dirty index' '
119 test_expect_success 'stash save --include-untracked dirty index got stashed' '
120 blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) &&
121 cat >expect <<-EOF &&
122 diff --git a/file3 b/file3
131 git stash pop --index &&
132 test_when_finished "git reset" &&
133 git diff --cached >actual &&
134 test_cmp expect actual
137 # Must direct output somewhere where it won't be considered an untracked file
138 test_expect_success 'stash save --include-untracked -q is quiet' '
140 git stash save --include-untracked --quiet >.git/stash-output.out 2>&1 &&
141 test_line_count = 0 .git/stash-output.out &&
142 rm -f .git/stash-output.out
145 test_expect_success 'stash save --include-untracked removed files' '
147 git stash save --include-untracked &&
149 test_when_finished "rm -f expect" &&
153 test_expect_success 'stash save --include-untracked removed files got stashed' '
155 test_path_is_missing file
158 test_expect_success 'stash save --include-untracked respects .gitignore' '
159 cat >.gitignore <<-EOF &&
165 echo ignored >ignored &&
167 echo ignored >ignored.d/untracked &&
170 test -s ignored.d/untracked &&
174 test_expect_success 'stash save -u can stash with only untracked files different' '
177 test_path_is_missing file4
180 test_expect_success 'stash save --all does not respect .gitignore' '
182 test_path_is_missing ignored &&
183 test_path_is_missing ignored.d &&
184 test_path_is_missing .gitignore
187 test_expect_success 'stash save --all is stash poppable' '
190 test -s ignored.d/untracked &&
194 test_expect_success 'stash push --include-untracked with pathspec' '
197 git stash push --include-untracked -- foo &&
198 test_path_is_file bar &&
199 test_path_is_missing foo &&
201 test_path_is_file bar &&
202 test_path_is_file foo
205 test_expect_success 'stash push with $IFS character' '
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 &&
215 test_path_is_file "foo bar" &&
216 test_path_is_file foo &&
217 test_path_is_file bar
220 test_expect_success 'stash previously ignored file' '
221 cat >.gitignore <<-EOF &&
227 git add .gitignore &&
228 git commit -m "Add .gitignore" &&
230 echo "!ignored.d/foo" >>.gitignore &&
231 git stash save --include-untracked &&
232 test_path_is_missing ignored.d/foo &&
234 test_path_is_file ignored.d/foo
237 test_expect_success 'stash -u -- <untracked> doesnt print error' '
239 git stash push -u -- untracked 2>actual &&
240 test_path_is_missing untracked &&
241 test_line_count = 0 actual
244 test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' '
248 git stash push -u -- untracked &&
249 test_path_is_missing untracked &&
250 test_path_is_file tracked
253 test_expect_success 'stash -u -- <tracked> <untracked> clears changes in both' '
257 git stash push -u -- tracked untracked &&
258 test_path_is_missing tracked &&
259 test_path_is_missing untracked
262 test_expect_success 'stash --all -- <ignored> stashes ignored file' '
264 git stash push --all -- ignored.d/bar &&
265 test_path_is_missing ignored.d/bar
268 test_expect_success 'stash --all -- <tracked> <ignored> clears changes in both' '
272 git stash push --all -- tracked ignored.d/bar &&
273 test_path_is_missing tracked &&
274 test_path_is_missing ignored.d/bar
277 test_expect_success 'stash -u -- <ignored> leaves ignored file alone' '
279 git stash push -u -- ignored.d/bar &&
280 test_path_is_file ignored.d/bar
283 test_expect_success 'stash -u -- <non-existent> shows no changes when there are none' '
284 git stash push -u -- non-existent >actual &&
285 echo "No local changes to save" >expect &&
286 test_i18ncmp expect actual
289 test_expect_success 'stash -u with globs' '
291 git stash -u -- ":(glob)**/*.txt" &&
292 test_path_is_missing untracked.txt