1#!/bin/sh
23
test_description='git mv in subdirs'
4. ./test-lib.sh
56
test_expect_success \
7'prepare reference tree' \
8'mkdir path0 path1 &&
9cp ../../COPYING path0/COPYING &&
10git add path0/COPYING &&
11git-commit -m add -a'
1213
test_expect_success \
14'moving the file out of subdirectory' \
15'cd path0 && git mv COPYING ../path1/COPYING'
1617
# in path0 currently
18test_expect_success \
19'commiting the change' \
20'cd .. && git-commit -m move-out -a'
2122
test_expect_success \
23'checking the commit' \
24'git diff-tree -r -M --name-status HEAD^ HEAD | \
25grep "^R100..*path0/COPYING..*path1/COPYING"'
2627
test_expect_success \
28'moving the file back into subdirectory' \
29'cd path0 && git mv ../path1/COPYING COPYING'
3031
# in path0 currently
32test_expect_success \
33'commiting the change' \
34'cd .. && git-commit -m move-in -a'
3536
test_expect_success \
37'checking the commit' \
38'git diff-tree -r -M --name-status HEAD^ HEAD | \
39grep "^R100..*path1/COPYING..*path0/COPYING"'
4041
test_expect_success \
42'adding another file' \
43'cp ../../README path0/README &&
44git add path0/README &&
45git-commit -m add2 -a'
4647
test_expect_success \
48'moving whole subdirectory' \
49'git mv path0 path2'
5051
test_expect_success \
52'commiting the change' \
53'git-commit -m dir-move -a'
5455
test_expect_success \
56'checking the commit' \
57'git diff-tree -r -M --name-status HEAD^ HEAD | \
58grep "^R100..*path0/COPYING..*path2/COPYING" &&
59git diff-tree -r -M --name-status HEAD^ HEAD | \
60grep "^R100..*path0/README..*path2/README"'
6162
test_expect_success \
63'succeed when source is a prefix of destination' \
64'git mv path2/COPYING path2/COPYING-renamed'
6566
test_expect_success \
67'moving whole subdirectory into subdirectory' \
68'git mv path2 path1'
6970
test_expect_success \
71'commiting the change' \
72'git-commit -m dir-move -a'
7374
test_expect_success \
75'checking the commit' \
76'git diff-tree -r -M --name-status HEAD^ HEAD | \
77grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
78git diff-tree -r -M --name-status HEAD^ HEAD | \
79grep "^R100..*path2/README..*path1/path2/README"'
8081
test_expect_success \
82'do not move directory over existing directory' \
83'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
8485
test_expect_success \
86'move into "."' \
87'git mv path1/path2/ .'
8889
test_expect_success "Michael Cassar's test case" '
90rm -fr .git papers partA &&
91git init &&
92mkdir -p papers/unsorted papers/all-papers partA &&
93echo a > papers/unsorted/Thesis.pdf &&
94echo b > partA/outline.txt &&
95echo c > papers/unsorted/_another &&
96git add papers partA &&
97T1=`git write-tree` &&
9899
git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
100101
T=`git write-tree` &&
102git ls-tree -r $T | grep partA/outline.txt || {
103git ls-tree -r $T
104(exit 1)
105}
106'
107108
rm -fr papers partA path?
109110
test_expect_success "Sergey Vlasov's test case" '
111rm -fr .git &&
112git init &&
113mkdir ab &&
114date >ab.c &&
115date >ab/d &&
116git add ab.c ab &&
117git commit -m 'initial' &&
118git mv ab a
119'
120121
test_expect_success 'absolute pathname' '(
122123
rm -fr mine &&
124mkdir mine &&
125cd mine &&
126test_create_repo one &&
127cd one &&
128mkdir sub &&
129>sub/file &&
130git add sub/file &&
131132
git mv sub "$(pwd)/in" &&
133! test -d sub &&
134test -d in &&
135git ls-files --error-unmatch in/file
136137
138
)'
139140
test_expect_success 'absolute pathname outside should fail' '(
141142
rm -fr mine &&
143mkdir mine &&
144cd mine &&
145out=$(pwd) &&
146test_create_repo one &&
147cd one &&
148mkdir sub &&
149>sub/file &&
150git add sub/file &&
151152
test_must_fail git mv sub "$out/out" &&
153test -d sub &&
154! test -d ../in &&
155git ls-files --error-unmatch sub/file
156157
)'
158159
test_expect_success 'git mv should not change sha1 of moved cache entry' '
160161
rm -fr .git &&
162git init &&
163echo 1 >dirty &&
164git add dirty &&
165entry="$(git ls-files --stage dirty | cut -f 1)"
166git mv dirty dirty2 &&
167[ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
168echo 2 >dirty2 &&
169git mv dirty2 dirty &&
170[ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
171172
'
173174
rm -f dirty dirty2
175176
test_expect_success 'git mv should overwrite symlink to a file' '
177178
rm -fr .git &&
179git init &&
180echo 1 >moved &&
181ln -s moved symlink &&
182git add moved symlink &&
183test_must_fail git mv moved symlink &&
184git mv -f moved symlink &&
185! test -e moved &&
186test -f symlink &&
187test "$(cat symlink)" = 1 &&
188git diff-files --quiet
189190
'
191192
rm -f moved symlink
193194
test_expect_success 'git mv should overwrite file with a symlink' '
195196
rm -fr .git &&
197git init &&
198echo 1 >moved &&
199ln -s moved symlink &&
200git add moved symlink &&
201test_must_fail git mv symlink moved &&
202git mv -f symlink moved &&
203! test -e symlink &&
204test -h moved &&
205git diff-files --quiet
206207
'
208209
rm -f moved symlink
210211
test_done