Remove the line length limit for graft files
[git/debian.git] / t / t7001-mv.sh
blobb90e985a48efbf8cdb16c6166356f6984ffbcea8
1 #!/bin/sh
3 test_description='git mv in subdirs'
4 . ./test-lib.sh
6 test_expect_success \
7 'prepare reference tree' \
8 'mkdir path0 path1 &&
9 cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
10 git add path0/COPYING &&
11 git commit -m add -a'
13 test_expect_success \
14 'moving the file out of subdirectory' \
15 'cd path0 && git mv COPYING ../path1/COPYING'
17 # in path0 currently
18 test_expect_success \
19 'commiting the change' \
20 'cd .. && git commit -m move-out -a'
22 test_expect_success \
23 'checking the commit' \
24 'git diff-tree -r -M --name-status HEAD^ HEAD | \
25 grep "^R100..*path0/COPYING..*path1/COPYING"'
27 test_expect_success \
28 'moving the file back into subdirectory' \
29 'cd path0 && git mv ../path1/COPYING COPYING'
31 # in path0 currently
32 test_expect_success \
33 'commiting the change' \
34 'cd .. && git commit -m move-in -a'
36 test_expect_success \
37 'checking the commit' \
38 'git diff-tree -r -M --name-status HEAD^ HEAD | \
39 grep "^R100..*path1/COPYING..*path0/COPYING"'
41 test_expect_success \
42 'checking -k on non-existing file' \
43 'git mv -k idontexist path0'
45 test_expect_success \
46 'checking -k on untracked file' \
47 'touch untracked1 &&
48 git mv -k untracked1 path0 &&
49 test -f untracked1 &&
50 test ! -f path0/untracked1'
52 test_expect_success \
53 'checking -k on multiple untracked files' \
54 'touch untracked2 &&
55 git mv -k untracked1 untracked2 path0 &&
56 test -f untracked1 &&
57 test -f untracked2 &&
58 test ! -f path0/untracked1 &&
59 test ! -f path0/untracked2'
61 test_expect_success \
62 'checking -f on untracked file with existing target' \
63 'touch path0/untracked1 &&
64 test_must_fail git mv -f untracked1 path0 &&
65 test ! -f .git/index.lock &&
66 test -f untracked1 &&
67 test -f path0/untracked1'
69 # clean up the mess in case bad things happen
70 rm -f idontexist untracked1 untracked2 \
71 path0/idontexist path0/untracked1 path0/untracked2 \
72 .git/index.lock
74 test_expect_success \
75 'adding another file' \
76 'cp "$TEST_DIRECTORY"/../README path0/README &&
77 git add path0/README &&
78 git commit -m add2 -a'
80 test_expect_success \
81 'moving whole subdirectory' \
82 'git mv path0 path2'
84 test_expect_success \
85 'commiting the change' \
86 'git commit -m dir-move -a'
88 test_expect_success \
89 'checking the commit' \
90 'git diff-tree -r -M --name-status HEAD^ HEAD | \
91 grep "^R100..*path0/COPYING..*path2/COPYING" &&
92 git diff-tree -r -M --name-status HEAD^ HEAD | \
93 grep "^R100..*path0/README..*path2/README"'
95 test_expect_success \
96 'succeed when source is a prefix of destination' \
97 'git mv path2/COPYING path2/COPYING-renamed'
99 test_expect_success \
100 'moving whole subdirectory into subdirectory' \
101 'git mv path2 path1'
103 test_expect_success \
104 'commiting the change' \
105 'git commit -m dir-move -a'
107 test_expect_success \
108 'checking the commit' \
109 'git diff-tree -r -M --name-status HEAD^ HEAD | \
110 grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
111 git diff-tree -r -M --name-status HEAD^ HEAD | \
112 grep "^R100..*path2/README..*path1/path2/README"'
114 test_expect_success \
115 'do not move directory over existing directory' \
116 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
118 test_expect_success \
119 'move into "."' \
120 'git mv path1/path2/ .'
122 test_expect_success "Michael Cassar's test case" '
123 rm -fr .git papers partA &&
124 git init &&
125 mkdir -p papers/unsorted papers/all-papers partA &&
126 echo a > papers/unsorted/Thesis.pdf &&
127 echo b > partA/outline.txt &&
128 echo c > papers/unsorted/_another &&
129 git add papers partA &&
130 T1=`git write-tree` &&
132 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
134 T=`git write-tree` &&
135 git ls-tree -r $T | grep partA/outline.txt || {
136 git ls-tree -r $T
137 (exit 1)
141 rm -fr papers partA path?
143 test_expect_success "Sergey Vlasov's test case" '
144 rm -fr .git &&
145 git init &&
146 mkdir ab &&
147 date >ab.c &&
148 date >ab/d &&
149 git add ab.c ab &&
150 git commit -m 'initial' &&
151 git mv ab a
154 test_expect_success 'absolute pathname' '(
156 rm -fr mine &&
157 mkdir mine &&
158 cd mine &&
159 test_create_repo one &&
160 cd one &&
161 mkdir sub &&
162 >sub/file &&
163 git add sub/file &&
165 git mv sub "$(pwd)/in" &&
166 ! test -d sub &&
167 test -d in &&
168 git ls-files --error-unmatch in/file
173 test_expect_success 'absolute pathname outside should fail' '(
175 rm -fr mine &&
176 mkdir mine &&
177 cd mine &&
178 out=$(pwd) &&
179 test_create_repo one &&
180 cd one &&
181 mkdir sub &&
182 >sub/file &&
183 git add sub/file &&
185 test_must_fail git mv sub "$out/out" &&
186 test -d sub &&
187 ! test -d ../in &&
188 git ls-files --error-unmatch sub/file
192 test_expect_success 'git mv to move multiple sources into a directory' '
193 rm -fr .git && git init &&
194 mkdir dir other &&
195 >dir/a.txt &&
196 >dir/b.txt &&
197 git add dir/?.txt &&
198 git mv dir/a.txt dir/b.txt other &&
199 git ls-files >actual &&
200 { echo other/a.txt; echo other/b.txt; } >expect &&
201 test_cmp expect actual
204 test_expect_success 'git mv should not change sha1 of moved cache entry' '
206 rm -fr .git &&
207 git init &&
208 echo 1 >dirty &&
209 git add dirty &&
210 entry="$(git ls-files --stage dirty | cut -f 1)" &&
211 git mv dirty dirty2 &&
212 [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
213 echo 2 >dirty2 &&
214 git mv dirty2 dirty &&
215 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
219 rm -f dirty dirty2
221 test_expect_success 'git mv should overwrite symlink to a file' '
223 rm -fr .git &&
224 git init &&
225 echo 1 >moved &&
226 test_ln_s_add moved symlink &&
227 git add moved &&
228 test_must_fail git mv moved symlink &&
229 git mv -f moved symlink &&
230 ! test -e moved &&
231 test -f symlink &&
232 test "$(cat symlink)" = 1 &&
233 git update-index --refresh &&
234 git diff-files --quiet
238 rm -f moved symlink
240 test_expect_success 'git mv should overwrite file with a symlink' '
242 rm -fr .git &&
243 git init &&
244 echo 1 >moved &&
245 test_ln_s_add moved symlink &&
246 git add moved &&
247 test_must_fail git mv symlink moved &&
248 git mv -f symlink moved &&
249 ! test -e symlink &&
250 git update-index --refresh &&
251 git diff-files --quiet
255 test_expect_success SYMLINKS 'check moved symlink' '
257 test -h moved
260 rm -f moved symlink
262 test_expect_success 'setup submodule' '
263 git commit -m initial &&
264 git reset --hard &&
265 git submodule add ./. sub &&
266 echo content >file &&
267 git add file &&
268 git commit -m "added sub and file"
271 test_expect_success 'git mv cannot move a submodule in a file' '
272 test_must_fail git mv sub file
275 test_expect_success 'git mv moves a submodule with a .git directory and no .gitmodules' '
276 entry="$(git ls-files --stage sub | cut -f 1)" &&
277 git rm .gitmodules &&
279 cd sub &&
280 rm -f .git &&
281 cp -a ../.git/modules/sub .git &&
282 GIT_WORK_TREE=. git config --unset core.worktree
283 ) &&
284 mkdir mod &&
285 git mv sub mod/sub &&
286 ! test -e sub &&
287 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
289 cd mod/sub &&
290 git status
291 ) &&
292 git update-index --refresh &&
293 git diff-files --quiet
296 test_expect_success 'git mv moves a submodule with a .git directory and .gitmodules' '
297 rm -rf mod &&
298 git reset --hard &&
299 git submodule update &&
300 entry="$(git ls-files --stage sub | cut -f 1)" &&
302 cd sub &&
303 rm -f .git &&
304 cp -a ../.git/modules/sub .git &&
305 GIT_WORK_TREE=. git config --unset core.worktree
306 ) &&
307 mkdir mod &&
308 git mv sub mod/sub &&
309 ! test -e sub &&
310 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
312 cd mod/sub &&
313 git status
314 ) &&
315 echo mod/sub >expected &&
316 git config -f .gitmodules submodule.sub.path >actual &&
317 test_cmp expected actual &&
318 git update-index --refresh &&
319 git diff-files --quiet
322 test_expect_success 'git mv moves a submodule with gitfile' '
323 rm -rf mod/sub &&
324 git reset --hard &&
325 git submodule update &&
326 entry="$(git ls-files --stage sub | cut -f 1)" &&
328 cd mod &&
329 git mv ../sub/ .
330 ) &&
331 ! test -e sub &&
332 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
334 cd mod/sub &&
335 git status
336 ) &&
337 echo mod/sub >expected &&
338 git config -f .gitmodules submodule.sub.path >actual &&
339 test_cmp expected actual &&
340 git update-index --refresh &&
341 git diff-files --quiet
344 test_expect_success 'mv does not complain when no .gitmodules file is found' '
345 rm -rf mod/sub &&
346 git reset --hard &&
347 git submodule update &&
348 git rm .gitmodules &&
349 entry="$(git ls-files --stage sub | cut -f 1)" &&
350 git mv sub mod/sub 2>actual.err &&
351 ! test -s actual.err &&
352 ! test -e sub &&
353 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
355 cd mod/sub &&
356 git status
357 ) &&
358 git update-index --refresh &&
359 git diff-files --quiet
362 test_expect_success 'mv will error out on a modified .gitmodules file unless staged' '
363 rm -rf mod/sub &&
364 git reset --hard &&
365 git submodule update &&
366 git config -f .gitmodules foo.bar true &&
367 entry="$(git ls-files --stage sub | cut -f 1)" &&
368 test_must_fail git mv sub mod/sub 2>actual.err &&
369 test -s actual.err &&
370 test -e sub &&
371 git diff-files --quiet -- sub &&
372 git add .gitmodules &&
373 git mv sub mod/sub 2>actual.err &&
374 ! test -s actual.err &&
375 ! test -e sub &&
376 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
378 cd mod/sub &&
379 git status
380 ) &&
381 git update-index --refresh &&
382 git diff-files --quiet
385 test_expect_success 'mv issues a warning when section is not found in .gitmodules' '
386 rm -rf mod/sub &&
387 git reset --hard &&
388 git submodule update &&
389 git config -f .gitmodules --remove-section submodule.sub &&
390 git add .gitmodules &&
391 entry="$(git ls-files --stage sub | cut -f 1)" &&
392 echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
393 git mv sub mod/sub 2>actual.err &&
394 test_i18ncmp expect.err actual.err &&
395 ! test -e sub &&
396 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
398 cd mod/sub &&
399 git status
400 ) &&
401 git update-index --refresh &&
402 git diff-files --quiet
405 test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
406 rm -rf mod/sub &&
407 git reset --hard &&
408 git submodule update &&
409 git mv -n sub mod/sub 2>actual.err &&
410 test -f sub/.git &&
411 git diff-index --exit-code HEAD &&
412 git update-index --refresh &&
413 git diff-files --quiet -- sub .gitmodules
416 test_done