3 test_description='git mv in subdirs'
7 'prepare reference tree' \
9 cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
10 git add path0/COPYING &&
14 'moving the file out of subdirectory' \
15 'cd path0 && git mv COPYING ../path1/COPYING'
19 'commiting the change' \
20 'cd .. && git commit -m move-out -a'
23 'checking the commit' \
24 'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
25 grep "^R100..*path0/COPYING..*path1/COPYING" actual'
28 'moving the file back into subdirectory' \
29 'cd path0 && git mv ../path1/COPYING COPYING'
33 'commiting the change' \
34 'cd .. && git commit -m move-in -a'
37 'checking the commit' \
38 'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
39 grep "^R100..*path1/COPYING..*path0/COPYING" actual'
42 'mv --dry-run does not move file' \
43 'git mv -n path0/COPYING MOVED &&
44 test -f path0/COPYING &&
48 'checking -k on non-existing file' \
49 'git mv -k idontexist path0'
52 'checking -k on untracked file' \
54 git mv -k untracked1 path0 &&
56 test ! -f path0/untracked1'
59 'checking -k on multiple untracked files' \
61 git mv -k untracked1 untracked2 path0 &&
64 test ! -f path0/untracked1 &&
65 test ! -f path0/untracked2'
68 'checking -f on untracked file with existing target' \
69 'touch path0/untracked1 &&
70 test_must_fail git mv -f untracked1 path0 &&
71 test ! -f .git/index.lock &&
73 test -f path0/untracked1'
75 # clean up the mess in case bad things happen
76 rm -f idontexist untracked1 untracked2 \
77 path0/idontexist path0/untracked1 path0/untracked2 \
82 'moving to absent target with trailing slash' \
83 'test_must_fail git mv path0/COPYING no-such-dir/ &&
84 test_must_fail git mv path0/COPYING no-such-dir// &&
85 git mv path0/ no-such-dir/ &&
86 test_path_is_dir no-such-dir'
93 'moving to existing untracked target with trailing slash' \
95 git mv path0/ path1/ &&
96 test_path_is_dir path1/path0/'
99 'moving to existing tracked target with trailing slash' \
101 >path2/file && git add path2/file &&
102 git mv path1/path0/ path2/ &&
103 test_path_is_dir path2/path0/'
105 test_expect_success \
109 test_expect_success \
110 'adding another file' \
111 'cp "$TEST_DIRECTORY"/../README.md path0/README &&
112 git add path0/README &&
113 git commit -m add2 -a'
115 test_expect_success \
116 'moving whole subdirectory' \
119 test_expect_success \
120 'commiting the change' \
121 'git commit -m dir-move -a'
123 test_expect_success \
124 'checking the commit' \
125 'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
126 grep "^R100..*path0/COPYING..*path2/COPYING" actual &&
127 grep "^R100..*path0/README..*path2/README" actual'
129 test_expect_success \
130 'succeed when source is a prefix of destination' \
131 'git mv path2/COPYING path2/COPYING-renamed'
133 test_expect_success \
134 'moving whole subdirectory into subdirectory' \
137 test_expect_success \
138 'commiting the change' \
139 'git commit -m dir-move -a'
141 test_expect_success \
142 'checking the commit' \
143 'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
144 grep "^R100..*path2/COPYING..*path1/path2/COPYING" actual &&
145 grep "^R100..*path2/README..*path1/path2/README" actual'
147 test_expect_success \
148 'do not move directory over existing directory' \
149 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
151 test_expect_success \
153 'git mv path1/path2/ .'
155 test_expect_success "Michael Cassar's test case" '
156 rm -fr .git papers partA &&
158 mkdir -p papers/unsorted papers/all-papers partA &&
159 echo a > papers/unsorted/Thesis.pdf &&
160 echo b > partA/outline.txt &&
161 echo c > papers/unsorted/_another &&
162 git add papers partA &&
163 T1=$(git write-tree) &&
165 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
167 T=$(git write-tree) &&
168 git ls-tree -r $T | verbose grep partA/outline.txt
171 rm -fr papers partA path?
173 test_expect_success "Sergey Vlasov's test case" '
180 git commit -m 'initial' &&
184 test_expect_success 'absolute pathname' '(
189 test_create_repo one &&
195 git mv sub "$(pwd)/in" &&
198 git ls-files --error-unmatch in/file
203 test_expect_success 'absolute pathname outside should fail' '(
209 test_create_repo one &&
215 test_must_fail git mv sub "$out/out" &&
218 git ls-files --error-unmatch sub/file
222 test_expect_success 'git mv to move multiple sources into a directory' '
223 rm -fr .git && git init &&
228 git mv dir/a.txt dir/b.txt other &&
229 git ls-files >actual &&
230 { echo other/a.txt; echo other/b.txt; } >expect &&
231 test_cmp expect actual
234 test_expect_success 'git mv should not change sha1 of moved cache entry' '
240 entry="$(git ls-files --stage dirty | cut -f 1)" &&
241 git mv dirty dirty2 &&
242 [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
244 git mv dirty2 dirty &&
245 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
251 test_expect_success 'git mv should overwrite symlink to a file' '
256 test_ln_s_add moved symlink &&
258 test_must_fail git mv moved symlink &&
259 git mv -f moved symlink &&
262 test "$(cat symlink)" = 1 &&
263 git update-index --refresh &&
264 git diff-files --quiet
270 test_expect_success 'git mv should overwrite file with a symlink' '
275 test_ln_s_add moved symlink &&
277 test_must_fail git mv symlink moved &&
278 git mv -f symlink moved &&
280 git update-index --refresh &&
281 git diff-files --quiet
285 test_expect_success SYMLINKS 'check moved symlink' '
292 test_expect_success 'setup submodule' '
293 git commit -m initial &&
295 git submodule add ./. sub &&
296 echo content >file &&
298 git commit -m "added sub and file" &&
299 mkdir -p deep/directory/hierarchy &&
300 git submodule add ./. deep/directory/hierarchy/sub &&
301 git commit -m "added another submodule" &&
305 test_expect_success 'git mv cannot move a submodule in a file' '
306 test_must_fail git mv sub file
309 test_expect_success 'git mv moves a submodule with a .git directory and no .gitmodules' '
310 entry="$(git ls-files --stage sub | cut -f 1)" &&
311 git rm .gitmodules &&
315 cp -R -P -p ../.git/modules/sub .git &&
316 GIT_WORK_TREE=. git config --unset core.worktree
319 git mv sub mod/sub &&
321 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
326 git update-index --refresh &&
327 git diff-files --quiet
330 test_expect_success 'git mv moves a submodule with a .git directory and .gitmodules' '
333 git submodule update &&
334 entry="$(git ls-files --stage sub | cut -f 1)" &&
338 cp -R -P -p ../.git/modules/sub .git &&
339 GIT_WORK_TREE=. git config --unset core.worktree
342 git mv sub mod/sub &&
344 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
349 echo mod/sub >expected &&
350 git config -f .gitmodules submodule.sub.path >actual &&
351 test_cmp expected actual &&
352 git update-index --refresh &&
353 git diff-files --quiet
356 test_expect_success 'git mv moves a submodule with gitfile' '
359 git submodule update &&
360 entry="$(git ls-files --stage sub | cut -f 1)" &&
367 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
372 echo mod/sub >expected &&
373 git config -f .gitmodules submodule.sub.path >actual &&
374 test_cmp expected actual &&
375 git update-index --refresh &&
376 git diff-files --quiet
379 test_expect_success 'mv does not complain when no .gitmodules file is found' '
382 git submodule update &&
383 git rm .gitmodules &&
384 entry="$(git ls-files --stage sub | cut -f 1)" &&
386 git mv sub mod/sub 2>actual.err &&
387 test_must_be_empty actual.err &&
389 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
394 git update-index --refresh &&
395 git diff-files --quiet
398 test_expect_success 'mv will error out on a modified .gitmodules file unless staged' '
401 git submodule update &&
402 git config -f .gitmodules foo.bar true &&
403 entry="$(git ls-files --stage sub | cut -f 1)" &&
405 test_must_fail git mv sub mod/sub 2>actual.err &&
406 test -s actual.err &&
408 git diff-files --quiet -- sub &&
409 git add .gitmodules &&
410 git mv sub mod/sub 2>actual.err &&
411 test_must_be_empty actual.err &&
413 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
418 git update-index --refresh &&
419 git diff-files --quiet
422 test_expect_success 'mv issues a warning when section is not found in .gitmodules' '
425 git submodule update &&
426 git config -f .gitmodules --remove-section submodule.sub &&
427 git add .gitmodules &&
428 entry="$(git ls-files --stage sub | cut -f 1)" &&
429 echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
431 git mv sub mod/sub 2>actual.err &&
432 test_i18ncmp expect.err actual.err &&
434 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
439 git update-index --refresh &&
440 git diff-files --quiet
443 test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
446 git submodule update &&
448 git mv -n sub mod/sub 2>actual.err &&
450 git diff-index --exit-code HEAD &&
451 git update-index --refresh &&
452 git diff-files --quiet -- sub .gitmodules
455 test_expect_success 'checking out a commit before submodule moved needs manual updates' '
457 git commit -m "moved sub to sub2" &&
458 git checkout -q HEAD^ 2>actual &&
459 test_i18ngrep "^warning: unable to rmdir '\''sub2'\'':" actual &&
460 git status -s sub2 >actual &&
461 echo "?? sub2/" >expected &&
462 test_cmp expected actual &&
463 ! test -f sub/.git &&
465 git submodule update &&
468 git diff-index --exit-code HEAD &&
469 git update-index --refresh &&
470 git diff-files --quiet -- sub .gitmodules &&
471 git status -s sub2 >actual &&
472 test_must_be_empty actual
475 test_expect_success 'mv -k does not accidentally destroy submodules' '
476 git checkout submodule &&
478 git mv -k dummy sub dest &&
479 git status --porcelain >actual &&
480 grep "^R sub -> dest/sub" actual &&
485 test_expect_success 'moving a submodule in nested directories' '
488 git mv directory ../ &&
489 # git status would fail if the update of linking git dir to
490 # work dir of the submodule failed.
492 git config -f ../.gitmodules submodule.deep/directory/hierarchy/sub.path >../actual &&
493 echo "directory/hierarchy/sub" >../expect
495 test_cmp expect actual
498 test_expect_success 'moving nested submodules' '
499 git commit -am "cleanup commit" &&
500 mkdir sub_nested_nested &&
501 (cd sub_nested_nested &&
502 touch nested_level2 &&
505 git commit -m "nested level 2"
509 touch nested_level1 &&
512 git commit -m "nested level 1" &&
513 git submodule add ../sub_nested_nested &&
514 git commit -m "add nested level 2"
516 git submodule add ./sub_nested nested_move &&
517 git commit -m "add nested_move" &&
518 git submodule update --init --recursive &&
519 git mv nested_move sub_nested_moved &&