]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7001-mv.sh
tests: use "git xyzzy" form (t3600 - t6999)
[thirdparty/git.git] / t / t7001-mv.sh
CommitLineData
8bf2c69c
AR
1#!/bin/sh
2
5be60078 3test_description='git mv in subdirs'
8bf2c69c
AR
4. ./test-lib.sh
5
6test_expect_success \
7 'prepare reference tree' \
8 'mkdir path0 path1 &&
9 cp ../../COPYING path0/COPYING &&
5be60078 10 git add path0/COPYING &&
8bf2c69c
AR
11 git-commit -m add -a'
12
13test_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
18test_expect_success \
19 'commiting the change' \
90924d55 20 'cd .. && git-commit -m move-out -a'
8bf2c69c
AR
21
22test_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
27test_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
32test_expect_success \
33 'commiting the change' \
34 'cd .. && git-commit -m move-in -a'
35
36test_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
afd22296
JW
41test_expect_success \
42 'adding another file' \
43 'cp ../../README path0/README &&
5be60078 44 git add path0/README &&
afd22296
JW
45 git-commit -m add2 -a'
46
47test_expect_success \
48 'moving whole subdirectory' \
5be60078 49 'git mv path0 path2'
afd22296
JW
50
51test_expect_success \
52 'commiting the change' \
53 'git-commit -m dir-move -a'
54
55test_expect_success \
56 'checking the commit' \
5be60078 57 'git diff-tree -r -M --name-status HEAD^ HEAD | \
90ed6c05 58 grep "^R100..*path0/COPYING..*path2/COPYING" &&
5be60078 59 git diff-tree -r -M --name-status HEAD^ HEAD | \
90ed6c05 60 grep "^R100..*path0/README..*path2/README"'
afd22296 61
1d6249e6
JS
62test_expect_success \
63 'succeed when source is a prefix of destination' \
5be60078 64 'git mv path2/COPYING path2/COPYING-renamed'
1d6249e6 65
a1dad607
JS
66test_expect_success \
67 'moving whole subdirectory into subdirectory' \
5be60078 68 'git mv path2 path1'
a1dad607
JS
69
70test_expect_success \
71 'commiting the change' \
72 'git-commit -m dir-move -a'
73
74test_expect_success \
75 'checking the commit' \
5be60078 76 'git diff-tree -r -M --name-status HEAD^ HEAD | \
90ed6c05 77 grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
5be60078 78 git diff-tree -r -M --name-status HEAD^ HEAD | \
90ed6c05 79 grep "^R100..*path2/README..*path1/path2/README"'
a1dad607 80
41ac414e 81test_expect_success \
ac64a722 82 'do not move directory over existing directory' \
d492b31c 83 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
ac64a722 84
c5203bdf
JS
85test_expect_success \
86 'move into "."' \
5be60078 87 'git mv path1/path2/ .'
c5203bdf 88
4fddf579
JH
89test_expect_success "Michael Cassar's test case" '
90 rm -fr .git papers partA &&
5c94f87e 91 git init &&
4fddf579
JH
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` &&
98
99 git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
100
101 T=`git write-tree` &&
102 git ls-tree -r $T | grep partA/outline.txt || {
103 git ls-tree -r $T
104 (exit 1)
105 }
106'
107
aca085e5
JS
108rm -fr papers partA path?
109
110test_expect_success "Sergey Vlasov's test case" '
111 rm -fr .git &&
5c94f87e 112 git init &&
aca085e5
JS
113 mkdir ab &&
114 date >ab.c &&
115 date >ab/d &&
116 git add ab.c ab &&
117 git commit -m 'initial' &&
118 git mv ab a
119'
120
744dacd3
JH
121test_expect_success 'absolute pathname' '(
122
123 rm -fr mine &&
124 mkdir mine &&
125 cd mine &&
126 test_create_repo one &&
127 cd one &&
128 mkdir sub &&
129 >sub/file &&
130 git add sub/file &&
131
132 git mv sub "$(pwd)/in" &&
133 ! test -d sub &&
134 test -d in &&
135 git ls-files --error-unmatch in/file
136
137
138)'
139
140test_expect_success 'absolute pathname outside should fail' '(
141
142 rm -fr mine &&
143 mkdir mine &&
144 cd mine &&
145 out=$(pwd) &&
146 test_create_repo one &&
147 cd one &&
148 mkdir sub &&
149 >sub/file &&
150 git add sub/file &&
151
d492b31c 152 test_must_fail git mv sub "$out/out" &&
744dacd3
JH
153 test -d sub &&
154 ! test -d ../in &&
155 git ls-files --error-unmatch sub/file
156
157)'
158
81dc2307
PB
159test_expect_success 'git mv should not change sha1 of moved cache entry' '
160
161 rm -fr .git &&
162 git init &&
163 echo 1 >dirty &&
164 git add dirty &&
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)" ] &&
168 echo 2 >dirty2 &&
169 git mv dirty2 dirty &&
170 [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
171
172'
173
174rm -f dirty dirty2
175
176test_expect_success 'git mv should overwrite symlink to a file' '
177
178 rm -fr .git &&
179 git init &&
180 echo 1 >moved &&
181 ln -s moved symlink &&
182 git add moved symlink &&
183 test_must_fail git mv moved symlink &&
184 git mv -f moved symlink &&
185 ! test -e moved &&
186 test -f symlink &&
187 test "$(cat symlink)" = 1 &&
65c35b22 188 git update-index --refresh &&
81dc2307
PB
189 git diff-files --quiet
190
191'
192
193rm -f moved symlink
194
195test_expect_success 'git mv should overwrite file with a symlink' '
196
197 rm -fr .git &&
198 git init &&
199 echo 1 >moved &&
200 ln -s moved symlink &&
201 git add moved symlink &&
202 test_must_fail git mv symlink moved &&
203 git mv -f symlink moved &&
204 ! test -e symlink &&
205 test -h moved &&
65c35b22 206 git update-index --refresh &&
81dc2307
PB
207 git diff-files --quiet
208
209'
210
211rm -f moved symlink
212
8bf2c69c 213test_done