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
33 test_expect_success
'stash save --include-untracked cleaned the untracked files' '
34 git status --porcelain >actual &&
35 test_cmp expect actual
38 tracked
=$
(git rev-parse
--short $
(echo 1 | git hash-object
--stdin))
39 untracked
=$
(git rev-parse
--short $
(echo untracked | git hash-object
--stdin))
40 cat > expect.
diff <<EOF
41 diff --git a/HEAD b/HEAD
43 index 0000000..$tracked
48 diff --git a/file2 b/file2
50 index 0000000..$tracked
55 diff --git a/untracked/untracked b/untracked/untracked
57 index 0000000..$untracked
59 +++ b/untracked/untracked
63 cat > expect.lstree
<<EOF
69 test_expect_success
'stash save --include-untracked stashed the untracked files' '
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 git clean
--force --quiet
97 test_expect_success
'stash pop after save --include-untracked leaves files untracked again' '
99 git status --porcelain >actual &&
100 test_cmp expect actual &&
101 test "1" = "$(cat file2)" &&
102 test untracked = "$(cat untracked/untracked)"
105 git clean
--force --quiet -d
107 test_expect_success
'stash save -u dirty index' '
114 blob
=$
(git rev-parse
--short $
(echo 4 | git hash-object
--stdin))
116 diff --git a/file3 b/file3
125 test_expect_success
'stash save --include-untracked dirty index got stashed' '
126 git stash pop --index &&
127 git diff --cached >actual &&
128 test_cmp expect actual
131 git
reset > /dev
/null
133 # Must direct output somewhere where it won't be considered an untracked file
134 test_expect_success
'stash save --include-untracked -q is quiet' '
136 git stash save --include-untracked --quiet > .git/stash-output.out 2>&1 &&
137 test_line_count = 0 .git/stash-output.out &&
138 rm -f .git/stash-output.out
141 test_expect_success
'stash save --include-untracked removed files' '
143 git stash save --include-untracked &&
150 test_expect_success
'stash save --include-untracked removed files got stashed' '
152 test_path_is_missing file
155 cat > .gitignore
<<EOF
161 test_expect_success
'stash save --include-untracked respects .gitignore' '
162 echo ignored > ignored &&
164 echo ignored >ignored.d/untracked &&
167 test -s ignored.d/untracked &&
171 test_expect_success
'stash save -u can stash with only untracked files different' '
174 test_path_is_missing file4
177 test_expect_success
'stash save --all does not respect .gitignore' '
179 test_path_is_missing ignored &&
180 test_path_is_missing ignored.d &&
181 test_path_is_missing .gitignore
184 test_expect_success
'stash save --all is stash poppable' '
187 test -s ignored.d/untracked &&
191 test_expect_success
'stash push --include-untracked with pathspec' '
194 git stash push --include-untracked -- foo &&
195 test_path_is_file bar &&
196 test_path_is_missing foo &&
198 test_path_is_file bar &&
199 test_path_is_file foo
202 test_expect_success
'stash push with $IFS character' '
207 git stash push --include-untracked -- "foo b*" &&
208 test_path_is_missing "foo bar" &&
209 test_path_is_file foo &&
210 test_path_is_file bar &&
212 test_path_is_file "foo bar" &&
213 test_path_is_file foo &&
214 test_path_is_file bar
217 cat > .gitignore
<<EOF
222 test_expect_success
'stash previously ignored file' '
224 git add .gitignore &&
225 git commit -m "Add .gitignore" &&
227 echo "!ignored.d/foo" >> .gitignore &&
228 git stash save --include-untracked &&
229 test_path_is_missing ignored.d/foo &&
231 test_path_is_file ignored.d/foo
234 test_expect_success
'stash -u -- <untracked> doesnt print error' '
236 git stash push -u -- untracked 2>actual &&
237 test_path_is_missing untracked &&
238 test_line_count = 0 actual
241 test_expect_success
'stash -u -- <untracked> leaves rest of working tree in place' '
245 git stash push -u -- untracked &&
246 test_path_is_missing untracked &&
247 test_path_is_file tracked
250 test_expect_success
'stash -u -- <tracked> <untracked> clears changes in both' '
254 git stash push -u -- tracked untracked &&
255 test_path_is_missing tracked &&
256 test_path_is_missing untracked
259 test_expect_success
'stash --all -- <ignored> stashes ignored file' '
261 git stash push --all -- ignored.d/bar &&
262 test_path_is_missing ignored.d/bar
265 test_expect_success
'stash --all -- <tracked> <ignored> clears changes in both' '
269 git stash push --all -- tracked ignored.d/bar &&
270 test_path_is_missing tracked &&
271 test_path_is_missing ignored.d/bar
274 test_expect_success
'stash -u -- <ignored> leaves ignored file alone' '
276 git stash push -u -- ignored.d/bar &&
277 test_path_is_file ignored.d/bar
280 test_expect_success
'stash -u -- <non-existant> shows no changes when there are none' '
281 git stash push -u -- non-existant >actual &&
282 echo "No local changes to save" >expect &&
283 test_i18ncmp expect actual