]>
Commit | Line | Data |
---|---|---|
8bf2c69c AR |
1 | #!/bin/sh |
2 | ||
5be60078 | 3 | test_description='git mv in subdirs' |
8bf2c69c AR |
4 | . ./test-lib.sh |
5 | ||
6 | test_expect_success \ | |
7 | 'prepare reference tree' \ | |
8 | 'mkdir path0 path1 && | |
9 | cp ../../COPYING path0/COPYING && | |
5be60078 | 10 | git add path0/COPYING && |
d592b315 | 11 | git commit -m add -a' |
8bf2c69c AR |
12 | |
13 | test_expect_success \ | |
90924d55 | 14 | 'moving the file out of subdirectory' \ |
5be60078 | 15 | 'cd path0 && git mv COPYING ../path1/COPYING' |
8bf2c69c AR |
16 | |
17 | # in path0 currently | |
18 | test_expect_success \ | |
19 | 'commiting the change' \ | |
d592b315 | 20 | 'cd .. && git commit -m move-out -a' |
8bf2c69c AR |
21 | |
22 | test_expect_success \ | |
23 | 'checking the commit' \ | |
5be60078 | 24 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 25 | grep "^R100..*path0/COPYING..*path1/COPYING"' |
8bf2c69c | 26 | |
90924d55 JW |
27 | test_expect_success \ |
28 | 'moving the file back into subdirectory' \ | |
5be60078 | 29 | 'cd path0 && git mv ../path1/COPYING COPYING' |
90924d55 JW |
30 | |
31 | # in path0 currently | |
32 | test_expect_success \ | |
33 | 'commiting the change' \ | |
d592b315 | 34 | 'cd .. && git commit -m move-in -a' |
90924d55 JW |
35 | |
36 | test_expect_success \ | |
37 | 'checking the commit' \ | |
5be60078 | 38 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 39 | grep "^R100..*path1/COPYING..*path0/COPYING"' |
90924d55 | 40 | |
3772923f MG |
41 | test_expect_success \ |
42 | 'checking -k on non-existing file' \ | |
43 | 'git mv -k idontexist path0' | |
44 | ||
45 | test_expect_success \ | |
46 | 'checking -k on untracked file' \ | |
47 | 'touch untracked1 && | |
48 | git mv -k untracked1 path0 && | |
49 | test -f untracked1 && | |
50 | test ! -f path0/untracked1' | |
51 | ||
be17262d | 52 | test_expect_success \ |
3772923f MG |
53 | 'checking -k on multiple untracked files' \ |
54 | 'touch untracked2 && | |
55 | git mv -k untracked1 untracked2 path0 && | |
56 | test -f untracked1 && | |
57 | test -f untracked2 && | |
58 | test ! -f path0/untracked1 | |
59 | test ! -f path0/untracked2' | |
60 | ||
61 | # clean up the mess in case bad things happen | |
62 | rm -f idontexist untracked1 untracked2 \ | |
63 | path0/idontexist path0/untracked1 path0/untracked2 \ | |
64 | .git/index.lock | |
65 | ||
afd22296 JW |
66 | test_expect_success \ |
67 | 'adding another file' \ | |
68 | 'cp ../../README path0/README && | |
5be60078 | 69 | git add path0/README && |
d592b315 | 70 | git commit -m add2 -a' |
afd22296 JW |
71 | |
72 | test_expect_success \ | |
73 | 'moving whole subdirectory' \ | |
5be60078 | 74 | 'git mv path0 path2' |
afd22296 JW |
75 | |
76 | test_expect_success \ | |
77 | 'commiting the change' \ | |
d592b315 | 78 | 'git commit -m dir-move -a' |
afd22296 JW |
79 | |
80 | test_expect_success \ | |
81 | 'checking the commit' \ | |
5be60078 | 82 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 83 | grep "^R100..*path0/COPYING..*path2/COPYING" && |
5be60078 | 84 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 85 | grep "^R100..*path0/README..*path2/README"' |
afd22296 | 86 | |
1d6249e6 JS |
87 | test_expect_success \ |
88 | 'succeed when source is a prefix of destination' \ | |
5be60078 | 89 | 'git mv path2/COPYING path2/COPYING-renamed' |
1d6249e6 | 90 | |
a1dad607 JS |
91 | test_expect_success \ |
92 | 'moving whole subdirectory into subdirectory' \ | |
5be60078 | 93 | 'git mv path2 path1' |
a1dad607 JS |
94 | |
95 | test_expect_success \ | |
96 | 'commiting the change' \ | |
d592b315 | 97 | 'git commit -m dir-move -a' |
a1dad607 JS |
98 | |
99 | test_expect_success \ | |
100 | 'checking the commit' \ | |
5be60078 | 101 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 102 | grep "^R100..*path2/COPYING..*path1/path2/COPYING" && |
5be60078 | 103 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 104 | grep "^R100..*path2/README..*path1/path2/README"' |
a1dad607 | 105 | |
41ac414e | 106 | test_expect_success \ |
ac64a722 | 107 | 'do not move directory over existing directory' \ |
d492b31c | 108 | 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0' |
ac64a722 | 109 | |
c5203bdf JS |
110 | test_expect_success \ |
111 | 'move into "."' \ | |
5be60078 | 112 | 'git mv path1/path2/ .' |
c5203bdf | 113 | |
4fddf579 JH |
114 | test_expect_success "Michael Cassar's test case" ' |
115 | rm -fr .git papers partA && | |
5c94f87e | 116 | git init && |
4fddf579 JH |
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` && | |
123 | ||
124 | git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf && | |
125 | ||
126 | T=`git write-tree` && | |
127 | git ls-tree -r $T | grep partA/outline.txt || { | |
128 | git ls-tree -r $T | |
129 | (exit 1) | |
130 | } | |
131 | ' | |
132 | ||
aca085e5 JS |
133 | rm -fr papers partA path? |
134 | ||
135 | test_expect_success "Sergey Vlasov's test case" ' | |
136 | rm -fr .git && | |
5c94f87e | 137 | git init && |
aca085e5 JS |
138 | mkdir ab && |
139 | date >ab.c && | |
140 | date >ab/d && | |
141 | git add ab.c ab && | |
142 | git commit -m 'initial' && | |
143 | git mv ab a | |
144 | ' | |
145 | ||
744dacd3 JH |
146 | test_expect_success 'absolute pathname' '( |
147 | ||
148 | rm -fr mine && | |
149 | mkdir mine && | |
150 | cd mine && | |
151 | test_create_repo one && | |
152 | cd one && | |
153 | mkdir sub && | |
154 | >sub/file && | |
155 | git add sub/file && | |
156 | ||
157 | git mv sub "$(pwd)/in" && | |
158 | ! test -d sub && | |
159 | test -d in && | |
160 | git ls-files --error-unmatch in/file | |
161 | ||
162 | ||
163 | )' | |
164 | ||
165 | test_expect_success 'absolute pathname outside should fail' '( | |
166 | ||
167 | rm -fr mine && | |
168 | mkdir mine && | |
169 | cd mine && | |
170 | out=$(pwd) && | |
171 | test_create_repo one && | |
172 | cd one && | |
173 | mkdir sub && | |
174 | >sub/file && | |
175 | git add sub/file && | |
176 | ||
d492b31c | 177 | test_must_fail git mv sub "$out/out" && |
744dacd3 JH |
178 | test -d sub && |
179 | ! test -d ../in && | |
180 | git ls-files --error-unmatch sub/file | |
181 | ||
182 | )' | |
183 | ||
81dc2307 PB |
184 | test_expect_success 'git mv should not change sha1 of moved cache entry' ' |
185 | ||
186 | rm -fr .git && | |
187 | git init && | |
188 | echo 1 >dirty && | |
189 | git add dirty && | |
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)" ] && | |
193 | echo 2 >dirty2 && | |
194 | git mv dirty2 dirty && | |
195 | [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] | |
196 | ||
197 | ' | |
198 | ||
199 | rm -f dirty dirty2 | |
200 | ||
201 | test_expect_success 'git mv should overwrite symlink to a file' ' | |
202 | ||
203 | rm -fr .git && | |
204 | git init && | |
205 | echo 1 >moved && | |
206 | ln -s moved symlink && | |
207 | git add moved symlink && | |
208 | test_must_fail git mv moved symlink && | |
209 | git mv -f moved symlink && | |
210 | ! test -e moved && | |
211 | test -f symlink && | |
212 | test "$(cat symlink)" = 1 && | |
65c35b22 | 213 | git update-index --refresh && |
81dc2307 PB |
214 | git diff-files --quiet |
215 | ||
216 | ' | |
217 | ||
218 | rm -f moved symlink | |
219 | ||
220 | test_expect_success 'git mv should overwrite file with a symlink' ' | |
221 | ||
222 | rm -fr .git && | |
223 | git init && | |
224 | echo 1 >moved && | |
225 | ln -s moved symlink && | |
226 | git add moved symlink && | |
227 | test_must_fail git mv symlink moved && | |
228 | git mv -f symlink moved && | |
229 | ! test -e symlink && | |
230 | test -h moved && | |
65c35b22 | 231 | git update-index --refresh && |
81dc2307 PB |
232 | git diff-files --quiet |
233 | ||
234 | ' | |
235 | ||
236 | rm -f moved symlink | |
237 | ||
8bf2c69c | 238 | test_done |