3 test_description
='Test handling of overwriting untracked files'
23 test_expect_success
'reset --hard will nuke untracked files/dirs' '
24 test_setup_reset hard &&
27 git ls-tree -r stable &&
28 git log --all --name-status --oneline &&
29 git ls-tree -r work &&
32 echo precious >foo.t/file &&
35 git reset --hard work &&
37 # check that untracked directory foo.t/ was nuked
38 test_path_is_file foo.t &&
43 test_expect_success
'reset --merge will preserve untracked files/dirs' '
44 test_setup_reset merge &&
49 echo precious >foo.t/file &&
50 cp foo.t/file expect &&
52 test_must_fail git reset --merge work 2>error &&
53 test_cmp expect foo.t/file &&
54 grep "Updating .foo.t. would lose untracked files" error
58 test_expect_success
'reset --keep will preserve untracked files/dirs' '
59 test_setup_reset keep &&
64 echo precious >foo.t/file &&
65 cp foo.t/file expect &&
67 test_must_fail git reset --merge work 2>error &&
68 test_cmp expect foo.t/file &&
69 grep "Updating.*foo.t.*would lose untracked files" error
73 test_setup_checkout_m
() {
79 test_write_lines
file has some
>filler
&&
81 git commit
-m filler
&&
86 echo stuff
>notes.txt
&&
87 test_write_lines
file has some words
>filler
&&
88 git add notes.txt filler
&&
89 git commit
-m filler
&&
95 test_expect_success
'checkout -m does not nuke untracked file' '
96 test_setup_checkout_m &&
101 test_write_lines this file has some >filler &&
102 # Make an untracked file, save its contents in "expect"
103 echo precious >notes.txt &&
104 cp notes.txt expect &&
106 test_must_fail git checkout -m work &&
107 test_cmp expect notes.txt
111 test_setup_sequencing
() {
112 git init sequencing_
$1 &&
117 test_write_lines this
file has some words
>filler
&&
119 git commit
-m filler
&&
122 test_commit foo
/bar
/baz
&&
127 git checkout fooey
&&
128 git
rm foo
/bar
/baz.t
&&
129 echo stuff
>>filler
&&
131 git commit
-m "changes" &&
133 git checkout simple
&&
134 echo items
>>filler
&&
135 echo newstuff
>>newfile
&&
136 git add filler newfile
&&
137 git commit
-m another
141 test_expect_success
'git rebase --abort and untracked files' '
142 test_setup_sequencing rebase_abort_and_untracked &&
144 cd sequencing_rebase_abort_and_untracked &&
145 git checkout fooey &&
146 test_must_fail git rebase simple &&
150 echo precious >init.t &&
152 git status --porcelain &&
153 test_must_fail git rebase --abort &&
154 test_cmp expect init.t
158 test_expect_success
'git rebase fast forwarding and untracked files' '
159 test_setup_sequencing rebase_fast_forward_and_untracked &&
161 cd sequencing_rebase_fast_forward_and_untracked &&
163 echo precious >filler &&
165 test_must_fail git rebase init simple &&
166 test_cmp expect filler
170 test_expect_failure
'git rebase --autostash and untracked files' '
171 test_setup_sequencing rebase_autostash_and_untracked &&
173 cd sequencing_rebase_autostash_and_untracked &&
174 git checkout simple &&
177 echo precious >filler/file &&
178 cp filler/file expect &&
179 git rebase --autostash init &&
180 test_path_is_file filler/file
184 test_expect_failure
'git stash and untracked files' '
185 test_setup_sequencing stash_and_untracked_files &&
187 cd sequencing_stash_and_untracked_files &&
188 git checkout simple &&
191 echo precious >filler/file &&
192 cp filler/file expect &&
193 git status --porcelain &&
195 git status --porcelain &&
196 test_path_is_file filler/file
200 test_expect_success
'git am --abort and untracked dir vs. unmerged file' '
201 test_setup_sequencing am_abort_and_untracked &&
203 cd sequencing_am_abort_and_untracked &&
204 git format-patch -1 --stdout fooey >changes.mbox &&
205 test_must_fail git am --3way changes.mbox &&
207 # Delete the conflicted file; we will stage and commit it later
210 # Put an unrelated untracked directory there
212 echo foo >filler/file1 &&
213 echo bar >filler/file2 &&
215 test_must_fail git am --abort 2>errors &&
216 test_path_is_dir filler &&
217 grep "Updating .filler. would lose untracked files in it" errors
221 test_expect_success
'git am --skip and untracked dir vs deleted file' '
222 test_setup_sequencing am_skip_and_untracked &&
224 cd sequencing_am_skip_and_untracked &&
225 git checkout fooey &&
226 git format-patch -1 --stdout simple >changes.mbox &&
227 test_must_fail git am --3way changes.mbox &&
232 # Put an unrelated untracked directory there
234 echo foo >newfile/file1 &&
235 echo bar >newfile/file2 &&
237 # Change our mind about resolutions, just skip this patch
238 test_must_fail git am --skip 2>errors &&
239 test_path_is_dir newfile &&
240 grep "Updating .newfile. would lose untracked files in it" errors