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'
61 # clean up the mess in case bad things happen
62 rm -f idontexist untracked1 untracked2 \
63 path
0/idontexist path
0/untracked1 path
0/untracked2 \
67 'adding another file' \
68 'cp "$TEST_DIRECTORY"/../README path0/README &&
69 git add path0/README &&
70 git commit -m add2 -a'
73 'moving whole subdirectory' \
77 'commiting the change' \
78 'git commit -m dir-move -a'
81 'checking the commit' \
82 'git diff-tree -r -M --name-status HEAD^ HEAD | \
83 grep "^R100..*path0/COPYING..*path2/COPYING" &&
84 git diff-tree -r -M --name-status HEAD^ HEAD | \
85 grep "^R100..*path0/README..*path2/README"'
88 'succeed when source is a prefix of destination' \
89 'git mv path2/COPYING path2/COPYING-renamed'
92 'moving whole subdirectory into subdirectory' \
96 'commiting the change' \
97 'git commit -m dir-move -a'
100 'checking the commit' \
101 'git diff-tree -r -M --name-status HEAD^ HEAD | \
102 grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
103 git diff-tree -r -M --name-status HEAD^ HEAD | \
104 grep "^R100..*path2/README..*path1/path2/README"'
106 test_expect_success \
107 'do not move directory over existing directory' \
108 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
110 test_expect_success \
112 'git mv path1/path2/ .'
114 test_expect_success
"Michael Cassar's test case" '
115 rm -fr .git papers partA &&
117 mkdir -p papers/unsorted papers/all-papers partA &&
118 echo a > papers/unsorted/Thesis.pdf &&
119 echo b > partA/outline.txt &&
120 echo c > papers/unsorted/_another &&
121 git add papers partA &&
122 T1=`git write-tree` &&
124 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
126 T=`git write-tree` &&
127 git ls-tree -r $T | grep partA/outline.txt || {
133 rm -fr papers partA path?
135 test_expect_success
"Sergey Vlasov's test case" '
142 git commit -m 'initial
' &&
146 test_expect_success
'absolute pathname' '(
151 test_create_repo one &&
157 git mv sub "$(pwd)/in" &&
160 git ls-files --error-unmatch in/file
165 test_expect_success
'absolute pathname outside should fail' '(
171 test_create_repo one &&
177 test_must_fail git mv sub "$out/out" &&
180 git ls-files --error-unmatch sub/file
184 test_expect_success
'git mv should not change sha1 of moved cache entry' '
190 entry="$(git ls-files --stage dirty | cut -f 1)"
191 git mv dirty dirty2 &&
192 [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
194 git mv dirty2 dirty &&
195 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
201 test_expect_success
'git mv should overwrite symlink to a file' '
206 ln -s moved symlink &&
207 git add moved symlink &&
208 test_must_fail git mv moved symlink &&
209 git mv -f moved symlink &&
212 test "$(cat symlink)" = 1 &&
213 git update-index --refresh &&
214 git diff-files --quiet
220 test_expect_success
'git mv should overwrite file with a symlink' '
225 ln -s moved symlink &&
226 git add moved symlink &&
227 test_must_fail git mv symlink moved &&
228 git mv -f symlink moved &&
231 git update-index --refresh &&
232 git diff-files --quiet