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