]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t3905-stash-include-untracked.sh
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 test "1" = "$(cat file2)" &&
107 test untracked = "$(cat untracked/untracked)"
110 test_expect_success
'clean up untracked/ directory to prepare for next tests' '
111 git clean --force --quiet -d
114 test_expect_success
'stash save -u dirty index' '
121 test_expect_success
'stash save --include-untracked dirty index got stashed' '
122 four_blob=$(echo 4 | git hash-object --stdin) &&
123 blob=$(git rev-parse --short "$four_blob") &&
124 cat >expect <<-EOF &&
125 diff --git a/file3 b/file3
134 git stash pop --index &&
135 test_when_finished "git reset" &&
136 git diff --cached >actual &&
137 test_cmp expect actual
140 # Must direct output somewhere where it won't be considered an untracked file
141 test_expect_success
'stash save --include-untracked -q is quiet' '
143 git stash save --include-untracked --quiet >.git/stash-output.out 2>&1 &&
144 test_line_count = 0 .git/stash-output.out &&
145 rm -f .git/stash-output.out
148 test_expect_success
'stash save --include-untracked removed files' '
150 git stash save --include-untracked &&
152 test_when_finished "rm -f expect" &&
156 test_expect_success
'stash save --include-untracked removed files got stashed' '
158 test_path_is_missing file
161 test_expect_success
'stash save --include-untracked respects .gitignore' '
162 cat >.gitignore <<-EOF &&
168 echo ignored >ignored &&
170 echo ignored >ignored.d/untracked &&
173 test -s ignored.d/untracked &&
177 test_expect_success
'stash save -u can stash with only untracked files different' '
180 test_path_is_missing file4
183 test_expect_success
'stash save --all does not respect .gitignore' '
185 test_path_is_missing ignored &&
186 test_path_is_missing ignored.d &&
187 test_path_is_missing .gitignore
190 test_expect_success
'stash save --all is stash poppable' '
193 test -s ignored.d/untracked &&
197 test_expect_success
'stash push --include-untracked with pathspec' '
200 git stash push --include-untracked -- foo &&
201 test_path_is_file bar &&
202 test_path_is_missing foo &&
204 test_path_is_file bar &&
205 test_path_is_file foo
208 test_expect_success
'stash push with $IFS character' '
213 git stash push --include-untracked -- "foo b*" &&
214 test_path_is_missing "foo bar" &&
215 test_path_is_file foo &&
216 test_path_is_file bar &&
218 test_path_is_file "foo bar" &&
219 test_path_is_file foo &&
220 test_path_is_file bar
223 test_expect_success
'stash previously ignored file' '
224 cat >.gitignore <<-EOF &&
230 git add .gitignore &&
231 git commit -m "Add .gitignore" &&
233 echo "!ignored.d/foo" >>.gitignore &&
234 git stash save --include-untracked &&
235 test_path_is_missing ignored.d/foo &&
237 test_path_is_file ignored.d/foo
240 test_expect_success
'stash -u -- <untracked> doesnt print error' '
242 git stash push -u -- untracked 2>actual &&
243 test_path_is_missing untracked &&
244 test_line_count = 0 actual
247 test_expect_success
'stash -u -- <untracked> leaves rest of working tree in place' '
251 git stash push -u -- untracked &&
252 test_path_is_missing untracked &&
253 test_path_is_file tracked
256 test_expect_success
'stash -u -- <tracked> <untracked> clears changes in both' '
260 git stash push -u -- tracked untracked &&
261 test_path_is_missing tracked &&
262 test_path_is_missing untracked
265 test_expect_success
'stash --all -- <ignored> stashes ignored file' '
267 git stash push --all -- ignored.d/bar &&
268 test_path_is_missing ignored.d/bar
271 test_expect_success
'stash --all -- <tracked> <ignored> clears changes in both' '
275 git stash push --all -- tracked ignored.d/bar &&
276 test_path_is_missing tracked &&
277 test_path_is_missing ignored.d/bar
280 test_expect_success
'stash -u -- <ignored> leaves ignored file alone' '
282 git stash push -u -- ignored.d/bar &&
283 test_path_is_file ignored.d/bar
286 test_expect_success
'stash -u -- <non-existent> shows no changes when there are none' '
287 git stash push -u -- non-existent >actual &&
288 echo "No local changes to save" >expect &&
289 test_i18ncmp expect actual
292 test_expect_success
'stash -u with globs' '
294 git stash -u -- ":(glob)**/*.txt" &&
295 test_path_is_missing untracked.txt