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)"
25 test_expect_success 'git svn --version works anywhere' '
26 mkdir -p "$deepdir" && (
27 GIT_CEILING_DIRECTORIES="$ceiling" &&
28 export GIT_CEILING_DIRECTORIES &&
34 test_expect_success 'git svn help works anywhere' '
35 mkdir -p "$deepdir" && (
36 GIT_CEILING_DIRECTORIES="$ceiling" &&
37 export GIT_CEILING_DIRECTORIES &&
44 'initialize git svn' '
50 mkdir -p dir/a/b/c/d/e &&
51 echo "deep dir" >dir/a/b/c/d/e/file &&
53 echo "zzz" >bar/zzz &&
54 echo "#!/bin/sh" >exec.sh &&
56 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
59 git svn init "$svnrepo"'
62 'import an SVN revision into git' \
65 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
67 name='try a deep --rmdir with a commit'
68 test_expect_success "$name" '
69 git checkout -f -b mybranch remotes/git-svn &&
70 mv dir/a/b/c/d/e/file dir/file &&
72 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
73 git commit -m "$name" &&
74 git svn set-tree --find-copies-harder --rmdir \
75 remotes/git-svn..mybranch &&
76 svn_cmd up "$SVN_TREE" &&
77 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
80 name='detect node change from file to directory #1'
81 test_expect_success "$name" "
83 mv dir/file dir/new_file/file &&
84 mv dir/new_file dir/file &&
85 git update-index --remove dir/file &&
86 git update-index --add dir/file/file &&
87 git commit -m '$name' &&
88 test_must_fail git svn set-tree --find-copies-harder --rmdir \
89 remotes/git-svn..mybranch
93 name='detect node change from directory to file #1'
94 test_expect_success "$name" '
95 rm -rf dir "$GIT_DIR"/index &&
96 git checkout -f -b mybranch2 remotes/git-svn &&
100 git update-index --remove -- bar/zzz &&
101 git update-index --add -- bar &&
102 git commit -m "$name" &&
103 test_must_fail git svn set-tree --find-copies-harder --rmdir \
104 remotes/git-svn..mybranch2
108 name='detect node change from file to directory #2'
109 test_expect_success "$name" '
110 rm -f "$GIT_DIR"/index &&
111 git checkout -f -b mybranch3 remotes/git-svn &&
113 git update-index --remove bar/zzz &&
115 echo yyy > bar/zzz/yyy &&
116 git update-index --add bar/zzz/yyy &&
117 git commit -m "$name" &&
118 git svn set-tree --find-copies-harder --rmdir \
119 remotes/git-svn..mybranch3 &&
120 svn_cmd up "$SVN_TREE" &&
121 test -d "$SVN_TREE"/bar/zzz &&
122 test -e "$SVN_TREE"/bar/zzz/yyy
125 name='detect node change from directory to file #2'
126 test_expect_success "$name" '
127 rm -f "$GIT_DIR"/index &&
128 git checkout -f -b mybranch4 remotes/git-svn &&
130 git update-index --remove -- dir/file &&
133 git update-index --add -- dir &&
134 git commit -m "$name" &&
135 test_must_fail git svn set-tree --find-copies-harder --rmdir \
136 remotes/git-svn..mybranch4
140 name='remove executable bit from a file'
141 test_expect_success POSIXPERM "$name" '
142 rm -f "$GIT_DIR"/index &&
143 git checkout -f -b mybranch5 remotes/git-svn &&
145 git update-index exec.sh &&
146 git commit -m "$name" &&
147 git svn set-tree --find-copies-harder --rmdir \
148 remotes/git-svn..mybranch5 &&
149 svn_cmd up "$SVN_TREE" &&
150 test ! -x "$SVN_TREE"/exec.sh'
153 name='add executable bit back file'
154 test_expect_success POSIXPERM "$name" '
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 -x "$SVN_TREE"/exec.sh'
164 name='executable file becomes a symlink to file'
165 test_expect_success SYMLINKS "$name" '
167 ln -s file exec.sh &&
168 git update-index exec.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 -h "$SVN_TREE"/exec.sh'
175 name='new symlink is added to a file that was also just made executable'
177 test_expect_success POSIXPERM,SYMLINKS "$name" '
179 ln -s file exec-2.sh &&
180 git update-index --add file exec-2.sh &&
181 git commit -m "$name" &&
182 git svn set-tree --find-copies-harder --rmdir \
183 remotes/git-svn..mybranch5 &&
184 svn_cmd up "$SVN_TREE" &&
185 test -x "$SVN_TREE"/file &&
186 test -h "$SVN_TREE"/exec-2.sh'
188 name='modify a symlink to become a file'
189 test_expect_success POSIXPERM,SYMLINKS "$name" '
190 echo git help >help &&
193 git update-index exec-2.sh &&
194 git commit -m "$name" &&
195 git svn set-tree --find-copies-harder --rmdir \
196 remotes/git-svn..mybranch5 &&
197 svn_cmd up "$SVN_TREE" &&
198 test -f "$SVN_TREE"/exec-2.sh &&
199 test ! -h "$SVN_TREE"/exec-2.sh &&
200 test_cmp help "$SVN_TREE"/exec-2.sh'
202 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
203 LC_ALL="$GIT_SVN_LC_ALL"
205 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
206 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
207 echo '# hello' >> exec-2.sh &&
208 git update-index exec-2.sh &&
209 git commit -m 'éï∏' &&
210 git svn set-tree HEAD"
213 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
216 test_expect_success "$name" \
217 'git svn init "$svnrepo" && git svn fetch &&
218 git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
219 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
222 name='check imported tree checksums expected tree checksums'
224 if test_have_prereq UTF8
226 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
228 cat >> expected <<\EOF
229 tree c3322890dcf74901f32d216f05c5044f670ce632
230 tree d3ccd5035feafd17b030c5732e7808cc49122853
231 tree d03e1630363d4881e68929d532746b20b0986b83
232 tree 149d63cd5878155c846e8c55d7d8487de283f89e
233 tree 312b76e4f64ce14893aeac8591eb3960b065e247
234 tree 149d63cd5878155c846e8c55d7d8487de283f89e
235 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
236 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
239 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected"
241 test_expect_success 'exit if remote refs are ambigious' '
242 git config --add svn-remote.svn.fetch \
243 bar:refs/remotes/git-svn &&
244 test_must_fail git svn migrate
247 test_expect_success 'exit if init-ing a would clobber a URL' '
248 svnadmin create "${PWD}/svnrepo2" &&
249 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
250 git config --unset svn-remote.svn.fetch \
251 "^bar:refs/remotes/git-svn$" &&
252 test_must_fail git svn init "${svnrepo}2/bar"
255 test_expect_success \
256 'init allows us to connect to another directory in the same repo' '
257 git svn init --minimize-url -i bar "$svnrepo/bar" &&
258 git config --get svn-remote.svn.fetch \
259 "^bar:refs/remotes/bar$" &&
260 git config --get svn-remote.svn.fetch \
261 "^:refs/remotes/git-svn$"
264 test_expect_success 'dcommit $rev does not clobber current branch' '
265 git svn fetch -i bar &&
266 git checkout -b my-bar refs/remotes/bar &&
269 git commit -m "change 1" &&
272 git commit -m "change 2" &&
273 old_head=$(git rev-parse HEAD) &&
274 git svn dcommit -i bar HEAD^ &&
275 test $old_head = $(git rev-parse HEAD) &&
276 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
277 git log refs/remotes/bar | grep "change 1" &&
278 ! git log refs/remotes/bar | grep "change 2" &&
279 git checkout master &&
283 test_expect_success 'able to dcommit to a subdirectory' '
284 git svn fetch -i bar &&
285 git checkout -b my-bar refs/remotes/bar &&
287 git update-index --add d &&
288 git commit -m "/bar/d should be in the log" &&
289 git svn dcommit -i bar &&
290 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
292 echo new > newdir/dir &&
293 git update-index --add newdir/dir &&
294 git commit -m "add a new directory" &&
295 git svn dcommit -i bar &&
296 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
297 echo foo >> newdir/dir &&
298 git update-index newdir/dir &&
299 git commit -m "modify a file in new directory" &&
300 git svn dcommit -i bar &&
301 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
304 test_expect_success 'dcommit should not fail with a touched file' '
305 test_commit "commit-new-file-foo2" foo2 &&
306 test-chmtime =-60 foo &&
310 test_expect_success 'rebase should not fail with a touched file' '
311 test-chmtime =-60 foo &&
315 test_expect_success 'able to set-tree to a subdirectory' '
317 git update-index d &&
318 git commit -m "update /bar/d" &&
319 git svn set-tree -i bar HEAD &&
320 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
323 test_expect_success 'git-svn works in a bare repository' '
327 GIT_DIR=. git svn init "$svnrepo" &&
331 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
332 mkdir worktree gitdir &&
334 git svn init "$svnrepo" &&
335 git init --separate-git-dir ../gitdir &&
337 rm -rf worktree gitdir