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