]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9100-git-svn-basic.sh
Merge branch 'jk/complete-branch-force-delete'
[thirdparty/git.git] / t / t9100-git-svn-basic.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 test_description='git svn basic tests'
7 GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
8
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12 . ./lib-git-svn.sh
13
14 case "$GIT_SVN_LC_ALL" in
15 *.UTF-8)
16 test_set_prereq UTF8
17 ;;
18 *)
19 say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
20 ;;
21 esac
22
23 test_expect_success 'git svn --version works anywhere' '
24 nongit git svn --version
25 '
26
27 test_expect_success 'git svn help works anywhere' '
28 nongit git svn help
29 '
30
31 test_expect_success \
32 'initialize git svn' '
33 mkdir import &&
34 (
35 cd import &&
36 echo foo >foo &&
37 ln -s foo foo.link &&
38 mkdir -p dir/a/b/c/d/e &&
39 echo "deep dir" >dir/a/b/c/d/e/file &&
40 mkdir bar &&
41 echo "zzz" >bar/zzz &&
42 echo "#!/bin/sh" >exec.sh &&
43 chmod +x exec.sh &&
44 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
45 ) &&
46 rm -rf import &&
47 git svn init "$svnrepo"'
48
49 test_expect_success \
50 'import an SVN revision into git' \
51 'git svn fetch'
52
53 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
54
55 name='try a deep --rmdir with a commit'
56 test_expect_success "$name" '
57 git checkout -f -b mybranch remotes/git-svn &&
58 mv dir/a/b/c/d/e/file dir/file &&
59 cp dir/file file &&
60 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
61 git commit -m "$name" &&
62 git svn set-tree --find-copies-harder --rmdir \
63 remotes/git-svn..mybranch &&
64 svn_cmd up "$SVN_TREE" &&
65 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
66
67
68 name='detect node change from file to directory #1'
69 test_expect_success "$name" '
70 mkdir dir/new_file &&
71 mv dir/file dir/new_file/file &&
72 mv dir/new_file dir/file &&
73 git update-index --remove dir/file &&
74 git update-index --add dir/file/file &&
75 git commit -m "$name" &&
76 test_must_fail git svn set-tree --find-copies-harder --rmdir \
77 remotes/git-svn..mybranch
78 '
79
80
81 name='detect node change from directory to file #1'
82 test_expect_success "$name" '
83 rm -rf dir "$GIT_DIR"/index &&
84 git checkout -f -b mybranch2 remotes/git-svn &&
85 mv bar/zzz zzz &&
86 rm -rf bar &&
87 mv zzz bar &&
88 git update-index --remove -- bar/zzz &&
89 git update-index --add -- bar &&
90 git commit -m "$name" &&
91 test_must_fail git svn set-tree --find-copies-harder --rmdir \
92 remotes/git-svn..mybranch2
93 '
94
95
96 name='detect node change from file to directory #2'
97 test_expect_success "$name" '
98 rm -f "$GIT_DIR"/index &&
99 git checkout -f -b mybranch3 remotes/git-svn &&
100 rm bar/zzz &&
101 git update-index --remove bar/zzz &&
102 mkdir bar/zzz &&
103 echo yyy > bar/zzz/yyy &&
104 git update-index --add bar/zzz/yyy &&
105 git commit -m "$name" &&
106 git svn set-tree --find-copies-harder --rmdir \
107 remotes/git-svn..mybranch3 &&
108 svn_cmd up "$SVN_TREE" &&
109 test -d "$SVN_TREE"/bar/zzz &&
110 test -e "$SVN_TREE"/bar/zzz/yyy
111 '
112
113 name='detect node change from directory to file #2'
114 test_expect_success "$name" '
115 rm -f "$GIT_DIR"/index &&
116 git checkout -f -b mybranch4 remotes/git-svn &&
117 rm -rf dir &&
118 git update-index --remove -- dir/file &&
119 touch dir &&
120 echo asdf > dir &&
121 git update-index --add -- dir &&
122 git commit -m "$name" &&
123 test_must_fail git svn set-tree --find-copies-harder --rmdir \
124 remotes/git-svn..mybranch4
125 '
126
127
128 name='remove executable bit from a file'
129 test_expect_success POSIXPERM "$name" '
130 rm -f "$GIT_DIR"/index &&
131 git checkout -f -b mybranch5 remotes/git-svn &&
132 chmod -x exec.sh &&
133 git update-index exec.sh &&
134 git commit -m "$name" &&
135 git svn set-tree --find-copies-harder --rmdir \
136 remotes/git-svn..mybranch5 &&
137 svn_cmd up "$SVN_TREE" &&
138 test ! -x "$SVN_TREE"/exec.sh'
139
140
141 name='add executable bit back file'
142 test_expect_success POSIXPERM "$name" '
143 chmod +x exec.sh &&
144 git update-index exec.sh &&
145 git commit -m "$name" &&
146 git svn set-tree --find-copies-harder --rmdir \
147 remotes/git-svn..mybranch5 &&
148 svn_cmd up "$SVN_TREE" &&
149 test -x "$SVN_TREE"/exec.sh'
150
151
152 name='executable file becomes a symlink to file'
153 test_expect_success SYMLINKS "$name" '
154 rm exec.sh &&
155 ln -s file exec.sh &&
156 git update-index exec.sh &&
157 git commit -m "$name" &&
158 git svn set-tree --find-copies-harder --rmdir \
159 remotes/git-svn..mybranch5 &&
160 svn_cmd up "$SVN_TREE" &&
161 test -h "$SVN_TREE"/exec.sh'
162
163 name='new symlink is added to a file that was also just made executable'
164
165 test_expect_success POSIXPERM,SYMLINKS "$name" '
166 chmod +x file &&
167 ln -s file exec-2.sh &&
168 git update-index --add file exec-2.sh &&
169 git commit -m "$name" &&
170 git svn set-tree --find-copies-harder --rmdir \
171 remotes/git-svn..mybranch5 &&
172 svn_cmd up "$SVN_TREE" &&
173 test -x "$SVN_TREE"/file &&
174 test -h "$SVN_TREE"/exec-2.sh'
175
176 name='modify a symlink to become a file'
177 test_expect_success POSIXPERM,SYMLINKS "$name" '
178 echo git help >help &&
179 rm exec-2.sh &&
180 cp help exec-2.sh &&
181 git update-index exec-2.sh &&
182 git commit -m "$name" &&
183 git svn set-tree --find-copies-harder --rmdir \
184 remotes/git-svn..mybranch5 &&
185 svn_cmd up "$SVN_TREE" &&
186 test -f "$SVN_TREE"/exec-2.sh &&
187 test ! -h "$SVN_TREE"/exec-2.sh &&
188 test_cmp help "$SVN_TREE"/exec-2.sh'
189
190 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
191 LC_ALL="$GIT_SVN_LC_ALL"
192 export LC_ALL
193 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
194 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
195 echo '# hello' >> exec-2.sh &&
196 git update-index exec-2.sh &&
197 git commit -m 'éï∏' &&
198 git svn set-tree HEAD"
199 unset LC_ALL
200
201 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
202 GIT_SVN_ID=alt
203 export GIT_SVN_ID
204 test_expect_success "$name" \
205 'git svn init "$svnrepo" && git svn fetch &&
206 git log --format="tree %T %s" remotes/git-svn |
207 awk "!seen[\$0]++ { print \$1, \$2 }" >a &&
208 git log --format="tree %T" alt >b &&
209 test_cmp a b'
210
211 name='check imported tree checksums expected tree checksums'
212 rm -f expected
213 if test_have_prereq UTF8
214 then
215 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected.sha1
216 echo tree b95b55b29d771f5eb73aa9b9d52d02fe11a2538c2feb0829f754ce20a91d98eb > expected.sha256
217 fi
218 cat >> expected.sha1 <<\EOF
219 tree c3322890dcf74901f32d216f05c5044f670ce632
220 tree d3ccd5035feafd17b030c5732e7808cc49122853
221 tree d03e1630363d4881e68929d532746b20b0986b83
222 tree 149d63cd5878155c846e8c55d7d8487de283f89e
223 tree 312b76e4f64ce14893aeac8591eb3960b065e247
224 tree 149d63cd5878155c846e8c55d7d8487de283f89e
225 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
226 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
227 EOF
228 cat >> expected.sha256 <<\EOF
229 tree 8d12756699d0b5b110514240a0ff141f6cbf8891fd69ab05e5594196fb437c9f
230 tree 8187168d33f7d4ccb8c1cc6e99532810aaccb47658f35d19b3803072d1128d7a
231 tree 74e535d85da8ee25eb23d7b506790c5ab3ccdb1ba0826bd57625ed44ef361650
232 tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95
233 tree 1fd6cec6aa95102d69266e20419bb62ec2a06372d614b9850ef23ff204103bb4
234 tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95
235 tree deb2b7ac79cd8ce6f52af6a5a0a08691e94ba74a2ed55966bb27dbec551730eb
236 tree 59e2e936761188476a7752034e8aa0a822b34050c8504b0dfd946407f4bc9215
237 EOF
238
239 test_expect_success POSIXPERM,SYMLINKS "$name" '
240 test_cmp expected.$(test_oid algo) a
241 '
242
243 test_expect_success 'exit if remote refs are ambigious' '
244 git config --add svn-remote.svn.fetch \
245 bar:refs/remotes/git-svn &&
246 test_must_fail git svn migrate
247 '
248
249 test_expect_success 'exit if init-ing a would clobber a URL' '
250 svnadmin create "${PWD}/svnrepo2" &&
251 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
252 git config --unset svn-remote.svn.fetch \
253 "^bar:refs/remotes/git-svn$" &&
254 test_must_fail git svn init "${svnrepo}2/bar"
255 '
256
257 test_expect_success \
258 'init allows us to connect to another directory in the same repo' '
259 git svn init --minimize-url -i bar "$svnrepo/bar" &&
260 git config --get svn-remote.svn.fetch \
261 "^bar:refs/remotes/bar$" &&
262 git config --get svn-remote.svn.fetch \
263 "^:refs/remotes/git-svn$"
264 '
265
266 test_expect_success 'dcommit $rev does not clobber current branch' '
267 git svn fetch -i bar &&
268 git checkout -b my-bar refs/remotes/bar &&
269 echo 1 > foo &&
270 git add foo &&
271 git commit -m "change 1" &&
272 echo 2 > foo &&
273 git add foo &&
274 git commit -m "change 2" &&
275 old_head=$(git rev-parse HEAD) &&
276 git svn dcommit -i bar HEAD^ &&
277 test $old_head = $(git rev-parse HEAD) &&
278 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
279 git log refs/remotes/bar | grep "change 1" &&
280 ! git log refs/remotes/bar | grep "change 2" &&
281 git checkout main &&
282 git branch -D my-bar
283 '
284
285 test_expect_success 'able to dcommit to a subdirectory' '
286 git svn fetch -i bar &&
287 git checkout -b my-bar refs/remotes/bar &&
288 echo abc > d &&
289 git update-index --add d &&
290 git commit -m "/bar/d should be in the log" &&
291 git svn dcommit -i bar &&
292 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
293 mkdir newdir &&
294 echo new > newdir/dir &&
295 git update-index --add newdir/dir &&
296 git commit -m "add a new directory" &&
297 git svn dcommit -i bar &&
298 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
299 echo foo >> newdir/dir &&
300 git update-index newdir/dir &&
301 git commit -m "modify a file in new directory" &&
302 git svn dcommit -i bar &&
303 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
304 '
305
306 test_expect_success 'dcommit should not fail with a touched file' '
307 test_commit "commit-new-file-foo2" foo2 &&
308 test-tool chmtime =-60 foo &&
309 git svn dcommit
310 '
311
312 test_expect_success 'rebase should not fail with a touched file' '
313 test-tool chmtime =-60 foo &&
314 git svn rebase
315 '
316
317 test_expect_success 'able to set-tree to a subdirectory' '
318 echo cba > d &&
319 git update-index d &&
320 git commit -m "update /bar/d" &&
321 git svn set-tree -i bar HEAD &&
322 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
323 '
324
325 test_expect_success 'git-svn works in a bare repository' '
326 mkdir bare-repo &&
327 ( cd bare-repo &&
328 git init --bare &&
329 GIT_DIR=. git svn init "$svnrepo" &&
330 git svn fetch ) &&
331 rm -rf bare-repo
332 '
333 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
334 mkdir worktree gitdir &&
335 ( cd worktree &&
336 git svn init "$svnrepo" &&
337 git init --separate-git-dir ../gitdir &&
338 git svn fetch ) &&
339 rm -rf worktree gitdir
340 '
341
342 test_done