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 | \
25 grep "^R100..*path0/COPYING..*path1/COPYING"'
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 | \
39 grep "^R100..*path1/COPYING..*path0/COPYING"'
42 'checking -k on non-existing file' \
43 'git mv -k idontexist path0'
46 'checking -k on untracked file' \
48 git mv -k untracked1 path0 &&
50 test ! -f path0/untracked1'
53 'checking -k on multiple untracked files' \
55 git mv -k untracked1 untracked2 path0 &&
58 test ! -f path0/untracked1 &&
59 test ! -f path0/untracked2'
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 &&
67 test -f path0/untracked1'
69 # clean up the mess in case bad things happen
70 rm -f idontexist untracked1 untracked2 \
71 path
0/idontexist path
0/untracked1 path
0/untracked2 \
76 'moving to absent target with trailing slash' \
77 'test_must_fail git mv path0/COPYING no-such-dir/ &&
78 test_must_fail git mv path0/COPYING no-such-dir// &&
79 git mv path0/ no-such-dir/ &&
80 test_path_is_dir no-such-dir'
87 'moving to existing untracked target with trailing slash' \
89 git mv path0/ path1/ &&
90 test_path_is_dir path1/path0/'
93 'moving to existing tracked target with trailing slash' \
95 >path2/file && git add path2/file &&
96 git mv path1/path0/ path2/ &&
97 test_path_is_dir path2/path0/'
103 test_expect_success \
104 'adding another file' \
105 'cp "$TEST_DIRECTORY"/../README.md path0/README &&
106 git add path0/README &&
107 git commit -m add2 -a'
109 test_expect_success \
110 'moving whole subdirectory' \
113 test_expect_success \
114 'commiting the change' \
115 'git commit -m dir-move -a'
117 test_expect_success \
118 'checking the commit' \
119 'git diff-tree -r -M --name-status HEAD^ HEAD | \
120 grep "^R100..*path0/COPYING..*path2/COPYING" &&
121 git diff-tree -r -M --name-status HEAD^ HEAD | \
122 grep "^R100..*path0/README..*path2/README"'
124 test_expect_success \
125 'succeed when source is a prefix of destination' \
126 'git mv path2/COPYING path2/COPYING-renamed'
128 test_expect_success \
129 'moving whole subdirectory into subdirectory' \
132 test_expect_success \
133 'commiting the change' \
134 'git commit -m dir-move -a'
136 test_expect_success \
137 'checking the commit' \
138 'git diff-tree -r -M --name-status HEAD^ HEAD | \
139 grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
140 git diff-tree -r -M --name-status HEAD^ HEAD | \
141 grep "^R100..*path2/README..*path1/path2/README"'
143 test_expect_success \
144 'do not move directory over existing directory' \
145 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
147 test_expect_success \
149 'git mv path1/path2/ .'
151 test_expect_success
"Michael Cassar's test case" '
152 rm -fr .git papers partA &&
154 mkdir -p papers/unsorted papers/all-papers partA &&
155 echo a > papers/unsorted/Thesis.pdf &&
156 echo b > partA/outline.txt &&
157 echo c > papers/unsorted/_another &&
158 git add papers partA &&
159 T1=$(git write-tree) &&
161 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
163 T=$(git write-tree) &&
164 git ls-tree -r $T | verbose grep partA/outline.txt
167 rm -fr papers partA path?
169 test_expect_success
"Sergey Vlasov's test case" '
176 git commit -m 'initial
' &&
180 test_expect_success
'absolute pathname' '(
185 test_create_repo one &&
191 git mv sub "$(pwd)/in" &&
194 git ls-files --error-unmatch in/file
199 test_expect_success
'absolute pathname outside should fail' '(
205 test_create_repo one &&
211 test_must_fail git mv sub "$out/out" &&
214 git ls-files --error-unmatch sub/file
218 test_expect_success
'git mv to move multiple sources into a directory' '
219 rm -fr .git && git init &&
224 git mv dir/a.txt dir/b.txt other &&
225 git ls-files >actual &&
226 { echo other/a.txt; echo other/b.txt; } >expect &&
227 test_cmp expect actual
230 test_expect_success
'git mv should not change sha1 of moved cache entry' '
236 entry="$(git ls-files --stage dirty | cut -f 1)" &&
237 git mv dirty dirty2 &&
238 [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
240 git mv dirty2 dirty &&
241 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
247 test_expect_success
'git mv should overwrite symlink to a file' '
252 test_ln_s_add moved symlink &&
254 test_must_fail git mv moved symlink &&
255 git mv -f moved symlink &&
258 test "$(cat symlink)" = 1 &&
259 git update-index --refresh &&
260 git diff-files --quiet
266 test_expect_success
'git mv should overwrite file with a symlink' '
271 test_ln_s_add moved symlink &&
273 test_must_fail git mv symlink moved &&
274 git mv -f symlink moved &&
276 git update-index --refresh &&
277 git diff-files --quiet
281 test_expect_success SYMLINKS
'check moved symlink' '
288 test_expect_success
'setup submodule' '
289 git commit -m initial &&
291 git submodule add ./. sub &&
292 echo content >file &&
294 git commit -m "added sub and file" &&
298 test_expect_success
'git mv cannot move a submodule in a file' '
299 test_must_fail git mv sub file
302 test_expect_success
'git mv moves a submodule with a .git directory and no .gitmodules' '
303 entry="$(git ls-files --stage sub | cut -f 1)" &&
304 git rm .gitmodules &&
308 cp -R -P -p ../.git/modules/sub .git &&
309 GIT_WORK_TREE=. git config --unset core.worktree
312 git mv sub mod/sub &&
314 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
319 git update-index --refresh &&
320 git diff-files --quiet
323 test_expect_success
'git mv moves a submodule with a .git directory and .gitmodules' '
326 git submodule update &&
327 entry="$(git ls-files --stage sub | cut -f 1)" &&
331 cp -R -P -p ../.git/modules/sub .git &&
332 GIT_WORK_TREE=. git config --unset core.worktree
335 git mv sub mod/sub &&
337 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
342 echo mod/sub >expected &&
343 git config -f .gitmodules submodule.sub.path >actual &&
344 test_cmp expected actual &&
345 git update-index --refresh &&
346 git diff-files --quiet
349 test_expect_success
'git mv moves a submodule with gitfile' '
352 git submodule update &&
353 entry="$(git ls-files --stage sub | cut -f 1)" &&
360 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
365 echo mod/sub >expected &&
366 git config -f .gitmodules submodule.sub.path >actual &&
367 test_cmp expected actual &&
368 git update-index --refresh &&
369 git diff-files --quiet
372 test_expect_success
'mv does not complain when no .gitmodules file is found' '
375 git submodule update &&
376 git rm .gitmodules &&
377 entry="$(git ls-files --stage sub | cut -f 1)" &&
379 git mv sub mod/sub 2>actual.err &&
380 ! test -s actual.err &&
382 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
387 git update-index --refresh &&
388 git diff-files --quiet
391 test_expect_success
'mv will error out on a modified .gitmodules file unless staged' '
394 git submodule update &&
395 git config -f .gitmodules foo.bar true &&
396 entry="$(git ls-files --stage sub | cut -f 1)" &&
398 test_must_fail git mv sub mod/sub 2>actual.err &&
399 test -s actual.err &&
401 git diff-files --quiet -- sub &&
402 git add .gitmodules &&
403 git mv sub mod/sub 2>actual.err &&
404 ! test -s actual.err &&
406 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
411 git update-index --refresh &&
412 git diff-files --quiet
415 test_expect_success
'mv issues a warning when section is not found in .gitmodules' '
418 git submodule update &&
419 git config -f .gitmodules --remove-section submodule.sub &&
420 git add .gitmodules &&
421 entry="$(git ls-files --stage sub | cut -f 1)" &&
422 echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
424 git mv sub mod/sub 2>actual.err &&
425 test_i18ncmp expect.err actual.err &&
427 [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
432 git update-index --refresh &&
433 git diff-files --quiet
436 test_expect_success
'mv --dry-run does not touch the submodule or .gitmodules' '
439 git submodule update &&
441 git mv -n sub mod/sub 2>actual.err &&
443 git diff-index --exit-code HEAD &&
444 git update-index --refresh &&
445 git diff-files --quiet -- sub .gitmodules
448 test_expect_success
'checking out a commit before submodule moved needs manual updates' '
450 git commit -m "moved sub to sub2" &&
451 git checkout -q HEAD^ 2>actual &&
452 test_i18ngrep "^warning: unable to rmdir sub2:" actual &&
453 git status -s sub2 >actual &&
454 echo "?? sub2/" >expected &&
455 test_cmp expected actual &&
456 ! test -f sub/.git &&
458 git submodule update &&
461 git diff-index --exit-code HEAD &&
462 git update-index --refresh &&
463 git diff-files --quiet -- sub .gitmodules &&
464 git status -s sub2 >actual &&
468 test_expect_success
'mv -k does not accidentally destroy submodules' '
469 git checkout submodule &&
471 git mv -k dummy sub dest &&
472 git status --porcelain >actual &&
473 grep "^R sub -> dest/sub" actual &&