3 test_description
='Test handling of overwriting untracked files'
5 TEST_PASSES_SANITIZE_LEAK
=true
24 test_expect_success
'reset --hard will nuke untracked files/dirs' '
25 test_setup_reset hard &&
28 git ls-tree -r stable &&
29 git log --all --name-status --oneline &&
30 git ls-tree -r work &&
33 echo precious >foo.t/file &&
36 git reset --hard work &&
38 # check that untracked directory foo.t/ was nuked
39 test_path_is_file foo.t &&
44 test_expect_success
'reset --merge will preserve untracked files/dirs' '
45 test_setup_reset merge &&
50 echo precious >foo.t/file &&
51 cp foo.t/file expect &&
53 test_must_fail git reset --merge work 2>error &&
54 test_cmp expect foo.t/file &&
55 grep "Updating .foo.t. would lose untracked files" error
59 test_expect_success
'reset --keep will preserve untracked files/dirs' '
60 test_setup_reset keep &&
65 echo precious >foo.t/file &&
66 cp foo.t/file expect &&
68 test_must_fail git reset --merge work 2>error &&
69 test_cmp expect foo.t/file &&
70 grep "Updating.*foo.t.*would lose untracked files" error
74 test_setup_checkout_m
() {
80 test_write_lines
file has some
>filler
&&
82 git commit
-m filler
&&
87 echo stuff
>notes.txt
&&
88 test_write_lines
file has some words
>filler
&&
89 git add notes.txt filler
&&
90 git commit
-m filler
&&
96 test_expect_success
'checkout -m does not nuke untracked file' '
97 test_setup_checkout_m &&
102 test_write_lines this file has some >filler &&
103 # Make an untracked file, save its contents in "expect"
104 echo precious >notes.txt &&
105 cp notes.txt expect &&
107 test_must_fail git checkout -m work &&
108 test_cmp expect notes.txt
112 test_setup_sequencing
() {
113 git init sequencing_
$1 &&
118 test_write_lines this
file has some words
>filler
&&
120 git commit
-m filler
&&
123 test_commit foo
/bar
/baz
&&
128 git checkout fooey
&&
129 git
rm foo
/bar
/baz.t
&&
130 echo stuff
>>filler
&&
132 git commit
-m "changes" &&
134 git checkout simple
&&
135 echo items
>>filler
&&
136 echo newstuff
>>newfile
&&
137 git add filler newfile
&&
138 git commit
-m another
142 test_expect_success
'git rebase --abort and untracked files' '
143 test_setup_sequencing rebase_abort_and_untracked &&
145 cd sequencing_rebase_abort_and_untracked &&
146 git checkout fooey &&
147 test_must_fail git rebase simple &&
151 echo precious >init.t &&
153 git status --porcelain &&
154 test_must_fail git rebase --abort &&
155 test_cmp expect init.t
159 test_expect_success
'git rebase fast forwarding and untracked files' '
160 test_setup_sequencing rebase_fast_forward_and_untracked &&
162 cd sequencing_rebase_fast_forward_and_untracked &&
164 echo precious >filler &&
166 test_must_fail git rebase init simple &&
167 test_cmp expect filler
171 test_expect_failure
'git rebase --autostash and untracked files' '
172 test_setup_sequencing rebase_autostash_and_untracked &&
174 cd sequencing_rebase_autostash_and_untracked &&
175 git checkout simple &&
178 echo precious >filler/file &&
179 cp filler/file expect &&
180 git rebase --autostash init &&
181 test_path_is_file filler/file
185 test_expect_failure
'git stash and untracked files' '
186 test_setup_sequencing stash_and_untracked_files &&
188 cd sequencing_stash_and_untracked_files &&
189 git checkout simple &&
192 echo precious >filler/file &&
193 cp filler/file expect &&
194 git status --porcelain &&
196 git status --porcelain &&
197 test_path_is_file filler/file
201 test_expect_success
'git am --abort and untracked dir vs. unmerged file' '
202 test_setup_sequencing am_abort_and_untracked &&
204 cd sequencing_am_abort_and_untracked &&
205 git format-patch -1 --stdout fooey >changes.mbox &&
206 test_must_fail git am --3way changes.mbox &&
208 # Delete the conflicted file; we will stage and commit it later
211 # Put an unrelated untracked directory there
213 echo foo >filler/file1 &&
214 echo bar >filler/file2 &&
216 test_must_fail git am --abort 2>errors &&
217 test_path_is_dir filler &&
218 grep "Updating .filler. would lose untracked files in it" errors
222 test_expect_success
'git am --skip and untracked dir vs deleted file' '
223 test_setup_sequencing am_skip_and_untracked &&
225 cd sequencing_am_skip_and_untracked &&
226 git checkout fooey &&
227 git format-patch -1 --stdout simple >changes.mbox &&
228 test_must_fail git am --3way changes.mbox &&
233 # Put an unrelated untracked directory there
235 echo foo >newfile/file1 &&
236 echo bar >newfile/file2 &&
238 # Change our mind about resolutions, just skip this patch
239 test_must_fail git am --skip 2>errors &&
240 test_path_is_dir newfile &&
241 grep "Updating .newfile. would lose untracked files in it" errors