3 # Copyright (c) 2006 Eric Wong
6 test_description
='git svn basic tests'
7 GIT_SVN_LC_ALL
=${LC_ALL:-$LANG}
11 say
'define NO_SVN_TESTS to skip git svn tests'
13 case "$GIT_SVN_LC_ALL" in
18 say
"# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
23 'initialize git svn' '
29 mkdir -p dir/a/b/c/d/e &&
30 echo "deep dir" >dir/a/b/c/d/e/file &&
32 echo "zzz" >bar/zzz &&
33 echo "#!/bin/sh" >exec.sh &&
35 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
38 git svn init "$svnrepo"'
41 'import an SVN revision into git' \
44 test_expect_success
"checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
46 name
='try a deep --rmdir with a commit'
47 test_expect_success
"$name" '
48 git checkout -f -b mybranch ${remotes_git_svn} &&
49 mv dir/a/b/c/d/e/file dir/file &&
51 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
52 git commit -m "$name" &&
53 git svn set-tree --find-copies-harder --rmdir \
54 ${remotes_git_svn}..mybranch &&
55 svn_cmd up "$SVN_TREE" &&
56 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
59 name
='detect node change from file to directory #1'
60 test_expect_success
"$name" "
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 &&
66 git commit -m '$name' &&
67 test_must_fail git svn set-tree --find-copies-harder --rmdir \
68 ${remotes_git_svn}..mybranch
72 name
='detect node change from directory to file #1'
73 test_expect_success
"$name" '
74 rm -rf dir "$GIT_DIR"/index &&
75 git checkout -f -b mybranch2 ${remotes_git_svn} &&
79 git update-index --remove -- bar/zzz &&
80 git update-index --add -- bar &&
81 git commit -m "$name" &&
82 test_must_fail git svn set-tree --find-copies-harder --rmdir \
83 ${remotes_git_svn}..mybranch2
87 name
='detect node change from file to directory #2'
88 test_expect_success
"$name" '
89 rm -f "$GIT_DIR"/index &&
90 git checkout -f -b mybranch3 ${remotes_git_svn} &&
92 git update-index --remove bar/zzz &&
94 echo yyy > bar/zzz/yyy &&
95 git update-index --add bar/zzz/yyy &&
96 git commit -m "$name" &&
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 &&
101 test -e "$SVN_TREE"/bar/zzz/yyy
104 name
='detect node change from directory to file #2'
105 test_expect_success
"$name" '
106 rm -f "$GIT_DIR"/index &&
107 git checkout -f -b mybranch4 ${remotes_git_svn} &&
109 git update-index --remove -- dir/file &&
112 git update-index --add -- dir &&
113 git commit -m "$name" &&
114 test_must_fail git svn set-tree --find-copies-harder --rmdir \
115 ${remotes_git_svn}..mybranch4
119 name
='remove executable bit from a file'
120 test_expect_success
"$name" '
121 rm -f "$GIT_DIR"/index &&
122 git checkout -f -b mybranch5 ${remotes_git_svn} &&
124 git update-index exec.sh &&
125 git commit -m "$name" &&
126 git svn set-tree --find-copies-harder --rmdir \
127 ${remotes_git_svn}..mybranch5 &&
128 svn_cmd up "$SVN_TREE" &&
129 test ! -x "$SVN_TREE"/exec.sh'
132 name
='add executable bit back file'
133 test_expect_success
"$name" '
135 git update-index exec.sh &&
136 git commit -m "$name" &&
137 git svn set-tree --find-copies-harder --rmdir \
138 ${remotes_git_svn}..mybranch5 &&
139 svn_cmd up "$SVN_TREE" &&
140 test -x "$SVN_TREE"/exec.sh'
143 name
='executable file becomes a symlink to file'
144 test_expect_success
"$name" '
146 ln -s file exec.sh &&
147 git update-index exec.sh &&
148 git commit -m "$name" &&
149 git svn set-tree --find-copies-harder --rmdir \
150 ${remotes_git_svn}..mybranch5 &&
151 svn_cmd up "$SVN_TREE" &&
152 test -h "$SVN_TREE"/exec.sh'
154 name
='new symlink is added to a file that was also just made executable'
156 test_expect_success
"$name" '
158 ln -s file exec-2.sh &&
159 git update-index --add file exec-2.sh &&
160 git commit -m "$name" &&
161 git svn set-tree --find-copies-harder --rmdir \
162 ${remotes_git_svn}..mybranch5 &&
163 svn_cmd up "$SVN_TREE" &&
164 test -x "$SVN_TREE"/file &&
165 test -h "$SVN_TREE"/exec-2.sh'
167 name
='modify a symlink to become a file'
168 test_expect_success
"$name" '
169 echo git help >help &&
172 git update-index exec-2.sh &&
173 git commit -m "$name" &&
174 git svn set-tree --find-copies-harder --rmdir \
175 ${remotes_git_svn}..mybranch5 &&
176 svn_cmd up "$SVN_TREE" &&
177 test -f "$SVN_TREE"/exec-2.sh &&
178 test ! -h "$SVN_TREE"/exec-2.sh &&
179 test_cmp help "$SVN_TREE"/exec-2.sh'
181 name
="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
182 LC_ALL
="$GIT_SVN_LC_ALL"
184 test_expect_success UTF8
"$name" "
185 echo '# hello' >> exec-2.sh &&
186 git update-index exec-2.sh &&
187 git commit -m 'éï∏' &&
188 git svn set-tree HEAD"
191 name
='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
194 test_expect_success
"$name" \
195 'git svn init "$svnrepo" && git svn fetch &&
196 git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a &&
197 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
200 name
='check imported tree checksums expected tree checksums'
202 if test_have_prereq UTF8
204 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e
> expected
206 cat >> expected
<<\EOF
207 tree c3322890dcf74901f32d216f05c5044f670ce632
208 tree d3ccd5035feafd17b030c5732e7808cc49122853
209 tree d03e1630363d4881e68929d532746b20b0986b83
210 tree
149d63cd5878155c846e8c55d7d8487de283f89e
211 tree
312b76e4f64ce14893aeac8591eb3960b065e247
212 tree
149d63cd5878155c846e8c55d7d8487de283f89e
213 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
214 tree
8f51f74cf0163afc9ad68a4b1537288c4558b5a4
217 test_expect_success
"$name" "test_cmp a expected"
219 test_expect_success
'exit if remote refs are ambigious' "
220 git config --add svn-remote.svn.fetch \
221 bar:refs/${remotes_git_svn} &&
222 test_must_fail git svn migrate
225 test_expect_success
'exit if init-ing a would clobber a URL' '
226 svnadmin create "${PWD}/svnrepo2" &&
227 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
228 git config --unset svn-remote.svn.fetch \
229 "^bar:refs/${remotes_git_svn}$" &&
230 test_must_fail git svn init "${svnrepo}2/bar"
233 test_expect_success \
234 'init allows us to connect to another directory in the same repo' '
235 git svn init --minimize-url -i bar "$svnrepo/bar" &&
236 git config --get svn-remote.svn.fetch \
237 "^bar:refs/remotes/bar$" &&
238 git config --get svn-remote.svn.fetch \
239 "^:refs/${remotes_git_svn}$"
242 test_expect_success
'dcommit $rev does not clobber current branch' '
243 git svn fetch -i bar &&
244 git checkout -b my-bar refs/remotes/bar &&
247 git commit -m "change 1" &&
250 git commit -m "change 2" &&
251 old_head=$(git rev-parse HEAD) &&
252 git svn dcommit -i bar HEAD^ &&
253 test $old_head = $(git rev-parse HEAD) &&
254 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
255 git log refs/remotes/bar | grep "change 1" &&
256 ! git log refs/remotes/bar | grep "change 2" &&
257 git checkout master &&
261 test_expect_success
'able to dcommit to a subdirectory' "
262 git svn fetch -i bar &&
263 git checkout -b my-bar refs/remotes/bar &&
265 git update-index --add d &&
266 git commit -m '/bar/d should be in the log' &&
267 git svn dcommit -i bar &&
268 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
270 echo new > newdir/dir &&
271 git update-index --add newdir/dir &&
272 git commit -m 'add a new directory' &&
273 git svn dcommit -i bar &&
274 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
275 echo foo >> newdir/dir &&
276 git update-index newdir/dir &&
277 git commit -m 'modify a file in new directory' &&
278 git svn dcommit -i bar &&
279 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
282 test_expect_success
'dcommit should not fail with a touched file' '
283 test_commit "commit-new-file-foo2" foo2 &&
284 test-chmtime =-60 foo &&
288 test_expect_success
'rebase should not fail with a touched file' '
289 test-chmtime =-60 foo &&
293 test_expect_success
'able to set-tree to a subdirectory' "
295 git update-index d &&
296 git commit -m 'update /bar/d' &&
297 git svn set-tree -i bar HEAD &&
298 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
301 test_expect_success
'git-svn works in a bare repository' '
305 GIT_DIR=. git svn init "$svnrepo" &&
309 test_expect_success
'git-svn works in in a repository with a gitdir: link' '
310 mkdir worktree gitdir &&
312 git svn init "$svnrepo" &&
313 git init --separate-git-dir ../gitdir &&
315 rm -rf worktree gitdir