3 # Copyright (c) 2006 Eric Wong
6 test_description='git svn basic tests'
7 GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
11 # Make sure timestamps of commits created by Git interleave
12 # with those created by "svn set-tree".
13 unset GIT_COMMITTER_DATE
15 case "$GIT_SVN_LC_ALL" in
20 say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
24 test_expect_success 'git svn --version works anywhere' '
25 nongit git svn --version
28 test_expect_success 'git svn help works anywhere' '
33 'initialize git svn' '
39 mkdir -p dir/a/b/c/d/e &&
40 echo "deep dir" >dir/a/b/c/d/e/file &&
42 echo "zzz" >bar/zzz &&
43 echo "#!/bin/sh" >exec.sh &&
45 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
48 git svn init "$svnrepo"'
51 'import an SVN revision into git' \
54 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
56 name='try a deep --rmdir with a commit'
57 test_expect_success "$name" '
58 git checkout -f -b mybranch remotes/git-svn &&
59 mv dir/a/b/c/d/e/file dir/file &&
61 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
62 git commit -m "$name" &&
63 git svn set-tree --find-copies-harder --rmdir \
64 remotes/git-svn..mybranch &&
65 svn_cmd up "$SVN_TREE" &&
66 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
69 name='detect node change from file to directory #1'
70 test_expect_success "$name" "
72 mv dir/file dir/new_file/file &&
73 mv dir/new_file dir/file &&
74 git update-index --remove dir/file &&
75 git update-index --add dir/file/file &&
76 git commit -m '$name' &&
77 test_must_fail git svn set-tree --find-copies-harder --rmdir \
78 remotes/git-svn..mybranch
82 name='detect node change from directory to file #1'
83 test_expect_success "$name" '
84 rm -rf dir "$GIT_DIR"/index &&
85 git checkout -f -b mybranch2 remotes/git-svn &&
89 git update-index --remove -- bar/zzz &&
90 git update-index --add -- bar &&
91 git commit -m "$name" &&
92 test_must_fail git svn set-tree --find-copies-harder --rmdir \
93 remotes/git-svn..mybranch2
97 name='detect node change from file to directory #2'
98 test_expect_success "$name" '
99 rm -f "$GIT_DIR"/index &&
100 git checkout -f -b mybranch3 remotes/git-svn &&
102 git update-index --remove bar/zzz &&
104 echo yyy > bar/zzz/yyy &&
105 git update-index --add bar/zzz/yyy &&
106 git commit -m "$name" &&
107 git svn set-tree --find-copies-harder --rmdir \
108 remotes/git-svn..mybranch3 &&
109 svn_cmd up "$SVN_TREE" &&
110 test -d "$SVN_TREE"/bar/zzz &&
111 test -e "$SVN_TREE"/bar/zzz/yyy
114 name='detect node change from directory to file #2'
115 test_expect_success "$name" '
116 rm -f "$GIT_DIR"/index &&
117 git checkout -f -b mybranch4 remotes/git-svn &&
119 git update-index --remove -- dir/file &&
122 git update-index --add -- dir &&
123 git commit -m "$name" &&
124 test_must_fail git svn set-tree --find-copies-harder --rmdir \
125 remotes/git-svn..mybranch4
129 name='remove executable bit from a file'
130 test_expect_success POSIXPERM "$name" '
131 rm -f "$GIT_DIR"/index &&
132 git checkout -f -b mybranch5 remotes/git-svn &&
134 git update-index exec.sh &&
135 git commit -m "$name" &&
136 git svn set-tree --find-copies-harder --rmdir \
137 remotes/git-svn..mybranch5 &&
138 svn_cmd up "$SVN_TREE" &&
139 test ! -x "$SVN_TREE"/exec.sh'
142 name='add executable bit back file'
143 test_expect_success POSIXPERM "$name" '
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='executable file becomes a symlink to file'
154 test_expect_success SYMLINKS "$name" '
156 ln -s file exec.sh &&
157 git update-index exec.sh &&
158 git commit -m "$name" &&
159 git svn set-tree --find-copies-harder --rmdir \
160 remotes/git-svn..mybranch5 &&
161 svn_cmd up "$SVN_TREE" &&
162 test -h "$SVN_TREE"/exec.sh'
164 name='new symlink is added to a file that was also just made executable'
166 test_expect_success POSIXPERM,SYMLINKS "$name" '
168 ln -s file exec-2.sh &&
169 git update-index --add file exec-2.sh &&
170 git commit -m "$name" &&
171 git svn set-tree --find-copies-harder --rmdir \
172 remotes/git-svn..mybranch5 &&
173 svn_cmd up "$SVN_TREE" &&
174 test -x "$SVN_TREE"/file &&
175 test -h "$SVN_TREE"/exec-2.sh'
177 name='modify a symlink to become a file'
178 test_expect_success POSIXPERM,SYMLINKS "$name" '
179 echo git help >help &&
182 git update-index exec-2.sh &&
183 git commit -m "$name" &&
184 git svn set-tree --find-copies-harder --rmdir \
185 remotes/git-svn..mybranch5 &&
186 svn_cmd up "$SVN_TREE" &&
187 test -f "$SVN_TREE"/exec-2.sh &&
188 test ! -h "$SVN_TREE"/exec-2.sh &&
189 test_cmp help "$SVN_TREE"/exec-2.sh'
191 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
192 LC_ALL="$GIT_SVN_LC_ALL"
194 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
195 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
196 echo '# hello' >> exec-2.sh &&
197 git update-index exec-2.sh &&
198 git commit -m 'éï∏' &&
199 git svn set-tree HEAD"
202 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
205 test_expect_success "$name" \
206 'git svn init "$svnrepo" && git svn fetch &&
207 git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
208 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
211 name='check imported tree checksums expected tree checksums'
213 if test_have_prereq UTF8
215 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
217 cat >> expected <<\EOF
218 tree c3322890dcf74901f32d216f05c5044f670ce632
219 tree d3ccd5035feafd17b030c5732e7808cc49122853
220 tree d03e1630363d4881e68929d532746b20b0986b83
221 tree 149d63cd5878155c846e8c55d7d8487de283f89e
222 tree 312b76e4f64ce14893aeac8591eb3960b065e247
223 tree 149d63cd5878155c846e8c55d7d8487de283f89e
224 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
225 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
228 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp expected a"
230 test_expect_success 'exit if remote refs are ambigious' '
231 git config --add svn-remote.svn.fetch \
232 bar:refs/remotes/git-svn &&
233 test_must_fail git svn migrate
236 test_expect_success 'exit if init-ing a would clobber a URL' '
237 svnadmin create "${PWD}/svnrepo2" &&
238 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
239 git config --unset svn-remote.svn.fetch \
240 "^bar:refs/remotes/git-svn$" &&
241 test_must_fail git svn init "${svnrepo}2/bar"
244 test_expect_success \
245 'init allows us to connect to another directory in the same repo' '
246 git svn init --minimize-url -i bar "$svnrepo/bar" &&
247 git config --get svn-remote.svn.fetch \
248 "^bar:refs/remotes/bar$" &&
249 git config --get svn-remote.svn.fetch \
250 "^:refs/remotes/git-svn$"
253 test_expect_success 'dcommit $rev does not clobber current branch' '
254 git svn fetch -i bar &&
255 git checkout -b my-bar refs/remotes/bar &&
258 git commit -m "change 1" &&
261 git commit -m "change 2" &&
262 old_head=$(git rev-parse HEAD) &&
263 git svn dcommit -i bar HEAD^ &&
264 test $old_head = $(git rev-parse HEAD) &&
265 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
266 git log refs/remotes/bar | grep "change 1" &&
267 ! git log refs/remotes/bar | grep "change 2" &&
268 git checkout master &&
272 test_expect_success 'able to dcommit to a subdirectory' '
273 git svn fetch -i bar &&
274 git checkout -b my-bar refs/remotes/bar &&
276 git update-index --add d &&
277 git commit -m "/bar/d should be in the log" &&
278 git svn dcommit -i bar &&
279 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
281 echo new > newdir/dir &&
282 git update-index --add newdir/dir &&
283 git commit -m "add a new directory" &&
284 git svn dcommit -i bar &&
285 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
286 echo foo >> newdir/dir &&
287 git update-index newdir/dir &&
288 git commit -m "modify a file in new directory" &&
289 git svn dcommit -i bar &&
290 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
293 test_expect_success 'dcommit should not fail with a touched file' '
294 test_commit "commit-new-file-foo2" foo2 &&
295 test-tool chmtime =-60 foo &&
299 test_expect_success 'rebase should not fail with a touched file' '
300 test-tool chmtime =-60 foo &&
304 test_expect_success 'able to set-tree to a subdirectory' '
306 git update-index d &&
307 git commit -m "update /bar/d" &&
308 git svn set-tree -i bar HEAD &&
309 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
312 test_expect_success 'git-svn works in a bare repository' '
316 GIT_DIR=. git svn init "$svnrepo" &&
320 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
321 mkdir worktree gitdir &&
323 git svn init "$svnrepo" &&
324 git init --separate-git-dir ../gitdir &&
326 rm -rf worktree gitdir