git-p4: fix typos
[git/gitster.git] / t / t2500-untracked-overwriting.sh
blob714feb83be5b36640008a96921b4b091e798df88
1 #!/bin/sh
3 test_description='Test handling of overwriting untracked files'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_setup_reset () {
9 git init reset_$1 &&
11 cd reset_$1 &&
12 test_commit init &&
14 git branch stable &&
15 git branch work &&
17 git checkout work &&
18 test_commit foo &&
20 git checkout stable
24 test_expect_success 'reset --hard will nuke untracked files/dirs' '
25 test_setup_reset hard &&
27 cd reset_hard &&
28 git ls-tree -r stable &&
29 git log --all --name-status --oneline &&
30 git ls-tree -r work &&
32 mkdir foo.t &&
33 echo precious >foo.t/file &&
34 echo foo >expect &&
36 git reset --hard work &&
38 # check that untracked directory foo.t/ was nuked
39 test_path_is_file foo.t &&
40 test_cmp expect foo.t
44 test_expect_success 'reset --merge will preserve untracked files/dirs' '
45 test_setup_reset merge &&
47 cd reset_merge &&
49 mkdir foo.t &&
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 &&
62 cd reset_keep &&
64 mkdir foo.t &&
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 () {
75 git init checkout &&
77 cd checkout &&
78 test_commit init &&
80 test_write_lines file has some >filler &&
81 git add filler &&
82 git commit -m filler &&
84 git branch stable &&
86 git switch -c work &&
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 &&
92 git checkout stable
96 test_expect_success 'checkout -m does not nuke untracked file' '
97 test_setup_checkout_m &&
99 cd checkout &&
101 # Tweak filler
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 &&
115 cd sequencing_$1 &&
116 test_commit init &&
118 test_write_lines this file has some words >filler &&
119 git add filler &&
120 git commit -m filler &&
122 mkdir -p foo/bar &&
123 test_commit foo/bar/baz &&
125 git branch simple &&
126 git branch fooey &&
128 git checkout fooey &&
129 git rm foo/bar/baz.t &&
130 echo stuff >>filler &&
131 git add -u &&
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 &&
149 cat init.t &&
150 git rm init.t &&
151 echo precious >init.t &&
152 cp init.t expect &&
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 &&
163 git checkout init &&
164 echo precious >filler &&
165 cp filler expect &&
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 &&
176 git rm filler &&
177 mkdir filler &&
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 &&
190 git rm filler &&
191 mkdir filler &&
192 echo precious >filler/file &&
193 cp filler/file expect &&
194 git status --porcelain &&
195 git stash push &&
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
209 rm filler &&
211 # Put an unrelated untracked directory there
212 mkdir filler &&
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 &&
230 # Delete newfile
231 rm newfile &&
233 # Put an unrelated untracked directory there
234 mkdir newfile &&
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
245 test_done