Documentation/build-docdep.perl: generate sorted output
[git/debian.git] / t / t2500-untracked-overwriting.sh
blob5c0bf4d21fcbb2a55e2c41c184ccb4c188c88ca4
1 #!/bin/sh
3 test_description='Test handling of overwriting untracked files'
5 . ./test-lib.sh
7 test_setup_reset () {
8 git init reset_$1 &&
10 cd reset_$1 &&
11 test_commit init &&
13 git branch stable &&
14 git branch work &&
16 git checkout work &&
17 test_commit foo &&
19 git checkout stable
23 test_expect_success 'reset --hard will nuke untracked files/dirs' '
24 test_setup_reset hard &&
26 cd reset_hard &&
27 git ls-tree -r stable &&
28 git log --all --name-status --oneline &&
29 git ls-tree -r work &&
31 mkdir foo.t &&
32 echo precious >foo.t/file &&
33 echo foo >expect &&
35 git reset --hard work &&
37 # check that untracked directory foo.t/ was nuked
38 test_path_is_file foo.t &&
39 test_cmp expect foo.t
43 test_expect_success 'reset --merge will preserve untracked files/dirs' '
44 test_setup_reset merge &&
46 cd reset_merge &&
48 mkdir foo.t &&
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 &&
61 cd reset_keep &&
63 mkdir foo.t &&
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 () {
74 git init checkout &&
76 cd checkout &&
77 test_commit init &&
79 test_write_lines file has some >filler &&
80 git add filler &&
81 git commit -m filler &&
83 git branch stable &&
85 git switch -c work &&
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 &&
91 git checkout stable
95 test_expect_success 'checkout -m does not nuke untracked file' '
96 test_setup_checkout_m &&
98 cd checkout &&
100 # Tweak filler
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 &&
114 cd sequencing_$1 &&
115 test_commit init &&
117 test_write_lines this file has some words >filler &&
118 git add filler &&
119 git commit -m filler &&
121 mkdir -p foo/bar &&
122 test_commit foo/bar/baz &&
124 git branch simple &&
125 git branch fooey &&
127 git checkout fooey &&
128 git rm foo/bar/baz.t &&
129 echo stuff >>filler &&
130 git add -u &&
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 &&
148 cat init.t &&
149 git rm init.t &&
150 echo precious >init.t &&
151 cp init.t expect &&
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 &&
162 git checkout init &&
163 echo precious >filler &&
164 cp filler expect &&
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 &&
175 git rm filler &&
176 mkdir filler &&
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 &&
189 git rm filler &&
190 mkdir filler &&
191 echo precious >filler/file &&
192 cp filler/file expect &&
193 git status --porcelain &&
194 git stash push &&
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
208 rm filler &&
210 # Put an unrelated untracked directory there
211 mkdir filler &&
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 &&
229 # Delete newfile
230 rm newfile &&
232 # Put an unrelated untracked directory there
233 mkdir newfile &&
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
244 test_done