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" || true
71 name
='detect node change from directory to file #1'
72 test_expect_success
"$name" '
73 rm -rf dir "$GIT_DIR"/index &&
74 git checkout -f -b mybranch2 ${remotes_git_svn} &&
78 git update-index --remove -- bar/zzz &&
79 git update-index --add -- bar &&
80 git commit -m "$name" &&
81 test_must_fail git svn set-tree --find-copies-harder --rmdir \
82 ${remotes_git_svn}..mybranch2' || true
85 name
='detect node change from file to directory #2'
86 test_expect_success
"$name" '
87 rm -f "$GIT_DIR"/index &&
88 git checkout -f -b mybranch3 ${remotes_git_svn} &&
90 git update-index --remove bar/zzz &&
92 echo yyy > bar/zzz/yyy &&
93 git update-index --add bar/zzz/yyy &&
94 git commit -m "$name" &&
95 test_must_fail git svn set-tree --find-copies-harder --rmdir \
96 ${remotes_git_svn}..mybranch3' || true
99 name
='detect node change from directory to file #2'
100 test_expect_success
"$name" '
101 rm -f "$GIT_DIR"/index &&
102 git checkout -f -b mybranch4 ${remotes_git_svn} &&
104 git update-index --remove -- dir/file &&
107 git update-index --add -- dir &&
108 git commit -m "$name" &&
109 test_must_fail git svn set-tree --find-copies-harder --rmdir \
110 ${remotes_git_svn}..mybranch4' || true
113 name
='remove executable bit from a file'
114 test_expect_success
"$name" '
115 rm -f "$GIT_DIR"/index &&
116 git checkout -f -b mybranch5 ${remotes_git_svn} &&
118 git update-index exec.sh &&
119 git commit -m "$name" &&
120 git svn set-tree --find-copies-harder --rmdir \
121 ${remotes_git_svn}..mybranch5 &&
122 svn_cmd up "$SVN_TREE" &&
123 test ! -x "$SVN_TREE"/exec.sh'
126 name
='add executable bit back file'
127 test_expect_success
"$name" '
129 git update-index exec.sh &&
130 git commit -m "$name" &&
131 git svn set-tree --find-copies-harder --rmdir \
132 ${remotes_git_svn}..mybranch5 &&
133 svn_cmd up "$SVN_TREE" &&
134 test -x "$SVN_TREE"/exec.sh'
137 name
='executable file becomes a symlink to bar/zzz (file)'
138 test_expect_success
"$name" '
140 ln -s bar/zzz exec.sh &&
141 git update-index exec.sh &&
142 git commit -m "$name" &&
143 git svn set-tree --find-copies-harder --rmdir \
144 ${remotes_git_svn}..mybranch5 &&
145 svn_cmd up "$SVN_TREE" &&
146 test -h "$SVN_TREE"/exec.sh'
148 name
='new symlink is added to a file that was also just made executable'
150 test_expect_success
"$name" '
152 ln -s bar/zzz exec-2.sh &&
153 git update-index --add bar/zzz exec-2.sh &&
154 git commit -m "$name" &&
155 git svn set-tree --find-copies-harder --rmdir \
156 ${remotes_git_svn}..mybranch5 &&
157 svn_cmd up "$SVN_TREE" &&
158 test -x "$SVN_TREE"/bar/zzz &&
159 test -h "$SVN_TREE"/exec-2.sh'
161 name
='modify a symlink to become a file'
162 test_expect_success
"$name" '
163 echo git help > help || true &&
166 git update-index exec-2.sh &&
167 git commit -m "$name" &&
168 git svn set-tree --find-copies-harder --rmdir \
169 ${remotes_git_svn}..mybranch5 &&
170 svn_cmd up "$SVN_TREE" &&
171 test -f "$SVN_TREE"/exec-2.sh &&
172 test ! -h "$SVN_TREE"/exec-2.sh &&
173 test_cmp help "$SVN_TREE"/exec-2.sh'
175 name
="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
176 LC_ALL
="$GIT_SVN_LC_ALL"
178 test_expect_success UTF8
"$name" "
179 echo '# hello' >> exec-2.sh &&
180 git update-index exec-2.sh &&
181 git commit -m 'éï∏' &&
182 git svn set-tree HEAD"
185 name
='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
188 test_expect_success
"$name" \
189 'git svn init "$svnrepo" && git svn fetch &&
190 git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a &&
191 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
194 name
='check imported tree checksums expected tree checksums'
196 if test_have_prereq UTF8
198 echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9
> expected
200 cat >> expected
<<\EOF
201 tree
83654bb36f019ae4fe77a0171f81075972087624
202 tree
031b8d557afc6fea52894eaebb45bec52f1ba6d1
203 tree
0b094cbff17168f24c302e297f55bfac65eb8bd3
204 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
205 tree
56a30b966619b863674f5978696f4a3594f2fca9
206 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
207 tree
8f51f74cf0163afc9ad68a4b1537288c4558b5a4
210 test_expect_success
"$name" "test_cmp a expected"
212 test_expect_success
'exit if remote refs are ambigious' "
213 git config --add svn-remote.svn.fetch \
214 bar:refs/${remotes_git_svn} &&
215 test_must_fail git svn migrate
218 test_expect_success
'exit if init-ing a would clobber a URL' '
219 svnadmin create "${PWD}/svnrepo2" &&
220 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
221 git config --unset svn-remote.svn.fetch \
222 "^bar:refs/${remotes_git_svn}$" &&
223 test_must_fail git svn init "${svnrepo}2/bar"
226 test_expect_success \
227 'init allows us to connect to another directory in the same repo' '
228 git svn init --minimize-url -i bar "$svnrepo/bar" &&
229 git config --get svn-remote.svn.fetch \
230 "^bar:refs/remotes/bar$" &&
231 git config --get svn-remote.svn.fetch \
232 "^:refs/${remotes_git_svn}$"
235 test_expect_success
'dcommit $rev does not clobber current branch' '
236 git svn fetch -i bar &&
237 git checkout -b my-bar refs/remotes/bar &&
240 git commit -m "change 1" &&
243 git commit -m "change 2" &&
244 old_head=$(git rev-parse HEAD) &&
245 git svn dcommit -i bar HEAD^ &&
246 test $old_head = $(git rev-parse HEAD) &&
247 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
248 git log refs/remotes/bar | grep "change 1" &&
249 ! git log refs/remotes/bar | grep "change 2" &&
250 git checkout master &&
254 test_expect_success
'able to dcommit to a subdirectory' "
255 git svn fetch -i bar &&
256 git checkout -b my-bar refs/remotes/bar &&
258 git update-index --add d &&
259 git commit -m '/bar/d should be in the log' &&
260 git svn dcommit -i bar &&
261 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
263 echo new > newdir/dir &&
264 git update-index --add newdir/dir &&
265 git commit -m 'add a new directory' &&
266 git svn dcommit -i bar &&
267 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
268 echo foo >> newdir/dir &&
269 git update-index newdir/dir &&
270 git commit -m 'modify a file in new directory' &&
271 git svn dcommit -i bar &&
272 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
275 test_expect_success
'dcommit should not fail with a touched file' '
276 test_commit "commit-new-file-foo2" foo2 &&
277 test-chmtime =-60 foo &&
281 test_expect_success
'rebase should not fail with a touched file' '
282 test-chmtime =-60 foo &&
286 test_expect_success
'able to set-tree to a subdirectory' "
288 git update-index d &&
289 git commit -m 'update /bar/d' &&
290 git svn set-tree -i bar HEAD &&
291 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
294 test_expect_success
'git-svn works in a bare repository' '
298 GIT_DIR=. git svn init "$svnrepo" &&