]>
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 && | |
720ec6b8 | 58 | test ! -f path0/untracked1 && |
3772923f MG |
59 | test ! -f path0/untracked2' |
60 | ||
5aed3c6a | 61 | test_expect_success \ |
c8ba6b1b MM |
62 | 'checking -f on untracked file with existing target' \ |
63 | 'touch path0/untracked1 && | |
64 | git mv -f untracked1 path0 | |
65 | test ! -f .git/index.lock && | |
66 | test -f untracked1 && | |
67 | test -f path0/untracked1' | |
68 | ||
3772923f MG |
69 | # clean up the mess in case bad things happen |
70 | rm -f idontexist untracked1 untracked2 \ | |
71 | path0/idontexist path0/untracked1 path0/untracked2 \ | |
72 | .git/index.lock | |
73 | ||
afd22296 JW |
74 | test_expect_success \ |
75 | 'adding another file' \ | |
76 | 'cp ../../README path0/README && | |
5be60078 | 77 | git add path0/README && |
d592b315 | 78 | git commit -m add2 -a' |
afd22296 JW |
79 | |
80 | test_expect_success \ | |
81 | 'moving whole subdirectory' \ | |
5be60078 | 82 | 'git mv path0 path2' |
afd22296 JW |
83 | |
84 | test_expect_success \ | |
85 | 'commiting the change' \ | |
d592b315 | 86 | 'git commit -m dir-move -a' |
afd22296 JW |
87 | |
88 | test_expect_success \ | |
89 | 'checking the commit' \ | |
5be60078 | 90 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 91 | grep "^R100..*path0/COPYING..*path2/COPYING" && |
5be60078 | 92 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 93 | grep "^R100..*path0/README..*path2/README"' |
afd22296 | 94 | |
1d6249e6 JS |
95 | test_expect_success \ |
96 | 'succeed when source is a prefix of destination' \ | |
5be60078 | 97 | 'git mv path2/COPYING path2/COPYING-renamed' |
1d6249e6 | 98 | |
a1dad607 JS |
99 | test_expect_success \ |
100 | 'moving whole subdirectory into subdirectory' \ | |
5be60078 | 101 | 'git mv path2 path1' |
a1dad607 JS |
102 | |
103 | test_expect_success \ | |
104 | 'commiting the change' \ | |
d592b315 | 105 | 'git commit -m dir-move -a' |
a1dad607 JS |
106 | |
107 | test_expect_success \ | |
108 | 'checking the commit' \ | |
5be60078 | 109 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 110 | grep "^R100..*path2/COPYING..*path1/path2/COPYING" && |
5be60078 | 111 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
90ed6c05 | 112 | grep "^R100..*path2/README..*path1/path2/README"' |
a1dad607 | 113 | |
41ac414e | 114 | test_expect_success \ |
ac64a722 | 115 | 'do not move directory over existing directory' \ |
d492b31c | 116 | 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0' |
ac64a722 | 117 | |
c5203bdf JS |
118 | test_expect_success \ |
119 | 'move into "."' \ | |
5be60078 | 120 | 'git mv path1/path2/ .' |
c5203bdf | 121 | |
4fddf579 JH |
122 | test_expect_success "Michael Cassar's test case" ' |
123 | rm -fr .git papers partA && | |
5c94f87e | 124 | git init && |
4fddf579 JH |
125 | mkdir -p papers/unsorted papers/all-papers partA && |
126 | echo a > papers/unsorted/Thesis.pdf && | |
127 | echo b > partA/outline.txt && | |
128 | echo c > papers/unsorted/_another && | |
129 | git add papers partA && | |
130 | T1=`git write-tree` && | |
131 | ||
132 | git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf && | |
133 | ||
134 | T=`git write-tree` && | |
135 | git ls-tree -r $T | grep partA/outline.txt || { | |
136 | git ls-tree -r $T | |
137 | (exit 1) | |
138 | } | |
139 | ' | |
140 | ||
aca085e5 JS |
141 | rm -fr papers partA path? |
142 | ||
143 | test_expect_success "Sergey Vlasov's test case" ' | |
144 | rm -fr .git && | |
5c94f87e | 145 | git init && |
aca085e5 JS |
146 | mkdir ab && |
147 | date >ab.c && | |
148 | date >ab/d && | |
149 | git add ab.c ab && | |
150 | git commit -m 'initial' && | |
151 | git mv ab a | |
152 | ' | |
153 | ||
744dacd3 JH |
154 | test_expect_success 'absolute pathname' '( |
155 | ||
156 | rm -fr mine && | |
157 | mkdir mine && | |
158 | cd mine && | |
159 | test_create_repo one && | |
160 | cd one && | |
161 | mkdir sub && | |
162 | >sub/file && | |
163 | git add sub/file && | |
164 | ||
165 | git mv sub "$(pwd)/in" && | |
166 | ! test -d sub && | |
167 | test -d in && | |
168 | git ls-files --error-unmatch in/file | |
169 | ||
170 | ||
171 | )' | |
172 | ||
173 | test_expect_success 'absolute pathname outside should fail' '( | |
174 | ||
175 | rm -fr mine && | |
176 | mkdir mine && | |
177 | cd mine && | |
178 | out=$(pwd) && | |
179 | test_create_repo one && | |
180 | cd one && | |
181 | mkdir sub && | |
182 | >sub/file && | |
183 | git add sub/file && | |
184 | ||
d492b31c | 185 | test_must_fail git mv sub "$out/out" && |
744dacd3 JH |
186 | test -d sub && |
187 | ! test -d ../in && | |
188 | git ls-files --error-unmatch sub/file | |
189 | ||
190 | )' | |
191 | ||
81dc2307 PB |
192 | test_expect_success 'git mv should not change sha1 of moved cache entry' ' |
193 | ||
194 | rm -fr .git && | |
195 | git init && | |
196 | echo 1 >dirty && | |
197 | git add dirty && | |
198 | entry="$(git ls-files --stage dirty | cut -f 1)" | |
199 | git mv dirty dirty2 && | |
200 | [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && | |
201 | echo 2 >dirty2 && | |
202 | git mv dirty2 dirty && | |
203 | [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] | |
204 | ||
205 | ' | |
206 | ||
207 | rm -f dirty dirty2 | |
208 | ||
209 | test_expect_success 'git mv should overwrite symlink to a file' ' | |
210 | ||
211 | rm -fr .git && | |
212 | git init && | |
213 | echo 1 >moved && | |
214 | ln -s moved symlink && | |
215 | git add moved symlink && | |
216 | test_must_fail git mv moved symlink && | |
217 | git mv -f moved symlink && | |
218 | ! test -e moved && | |
219 | test -f symlink && | |
220 | test "$(cat symlink)" = 1 && | |
65c35b22 | 221 | git update-index --refresh && |
81dc2307 PB |
222 | git diff-files --quiet |
223 | ||
224 | ' | |
225 | ||
226 | rm -f moved symlink | |
227 | ||
228 | test_expect_success 'git mv should overwrite file with a symlink' ' | |
229 | ||
230 | rm -fr .git && | |
231 | git init && | |
232 | echo 1 >moved && | |
233 | ln -s moved symlink && | |
234 | git add moved symlink && | |
235 | test_must_fail git mv symlink moved && | |
236 | git mv -f symlink moved && | |
237 | ! test -e symlink && | |
238 | test -h moved && | |
65c35b22 | 239 | git update-index --refresh && |
81dc2307 PB |
240 | git diff-files --quiet |
241 | ||
242 | ' | |
243 | ||
244 | rm -f moved symlink | |
245 | ||
8bf2c69c | 246 | test_done |