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 'adding another file' \
43 'cp "$TEST_DIRECTORY"/../README path0/README &&
44 git add path0/README &&
45 git commit -m add2 -a'
48 'moving whole subdirectory' \
52 'commiting the change' \
53 'git commit -m dir-move -a'
56 'checking the commit' \
57 'git diff-tree -r -M --name-status HEAD^ HEAD | \
58 grep "^R100..*path0/COPYING..*path2/COPYING" &&
59 git diff-tree -r -M --name-status HEAD^ HEAD | \
60 grep "^R100..*path0/README..*path2/README"'
63 'succeed when source is a prefix of destination' \
64 'git mv path2/COPYING path2/COPYING-renamed'
67 'moving whole subdirectory into subdirectory' \
71 'commiting the change' \
72 'git commit -m dir-move -a'
75 'checking the commit' \
76 'git diff-tree -r -M --name-status HEAD^ HEAD | \
77 grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
78 git diff-tree -r -M --name-status HEAD^ HEAD | \
79 grep "^R100..*path2/README..*path1/path2/README"'
82 'do not move directory over existing directory' \
83 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
87 'git mv path1/path2/ .'
89 test_expect_success
"Michael Cassar's test case" '
90 rm -fr .git papers partA &&
92 mkdir -p papers/unsorted papers/all-papers partA &&
93 echo a > papers/unsorted/Thesis.pdf &&
94 echo b > partA/outline.txt &&
95 echo c > papers/unsorted/_another &&
96 git add papers partA &&
97 T1=`git write-tree` &&
99 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
101 T=`git write-tree` &&
102 git ls-tree -r $T | grep partA/outline.txt || {
108 rm -fr papers partA path?
110 test_expect_success
"Sergey Vlasov's test case" '
117 git commit -m 'initial
' &&
121 test_expect_success
'absolute pathname' '(
126 test_create_repo one &&
132 git mv sub "$(pwd)/in" &&
135 git ls-files --error-unmatch in/file
140 test_expect_success
'absolute pathname outside should fail' '(
146 test_create_repo one &&
152 test_must_fail git mv sub "$out/out" &&
155 git ls-files --error-unmatch sub/file
159 test_expect_success
'git mv should not change sha1 of moved cache entry' '
165 entry="$(git ls-files --stage dirty | cut -f 1)"
166 git mv dirty dirty2 &&
167 [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
169 git mv dirty2 dirty &&
170 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
176 test_expect_success
'git mv should overwrite symlink to a file' '
181 ln -s moved symlink &&
182 git add moved symlink &&
183 test_must_fail git mv moved symlink &&
184 git mv -f moved symlink &&
187 test "$(cat symlink)" = 1 &&
188 git update-index --refresh &&
189 git diff-files --quiet
195 test_expect_success
'git mv should overwrite file with a symlink' '
200 ln -s moved symlink &&
201 git add moved symlink &&
202 test_must_fail git mv symlink moved &&
203 git mv -f symlink moved &&
206 git update-index --refresh &&
207 git diff-files --quiet