t/t91*: do not say how to avoid the tests
[git] / t / t9100-git-svn-basic.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 test_description='git svn basic tests'
7 GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
8
9 . ./lib-git-svn.sh
10
11 case "$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         ;;
18 esac
19
20 test_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
38 test_expect_success \
39     'import an SVN revision into git' \
40     'git svn fetch'
41
42 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
43
44 name='try a deep --rmdir with a commit'
45 test_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
57 name='detect node change from file to directory #1'
58 test_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
70 name='detect node change from directory to file #1'
71 test_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
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} &&
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
102 name='detect node change from directory to file #2'
103 test_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
117 name='remove executable bit from a file'
118 test_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
130 name='add executable bit back file'
131 test_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
141 name='executable file becomes a symlink to file'
142 test_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
152 name='new symlink is added to a file that was also just made executable'
153
154 test_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
165 name='modify a symlink to become a file'
166 test_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
179 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
180 LC_ALL="$GIT_SVN_LC_ALL"
181 export LC_ALL
182 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
183 test_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"
188 unset LC_ALL
189
190 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
191 GIT_SVN_ID=alt
192 export GIT_SVN_ID
193 test_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
199 name='check imported tree checksums expected tree checksums'
200 rm -f expected
201 if test_have_prereq UTF8
202 then
203         echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
204 fi
205 cat >> expected <<\EOF
206 tree c3322890dcf74901f32d216f05c5044f670ce632
207 tree d3ccd5035feafd17b030c5732e7808cc49122853
208 tree d03e1630363d4881e68929d532746b20b0986b83
209 tree 149d63cd5878155c846e8c55d7d8487de283f89e
210 tree 312b76e4f64ce14893aeac8591eb3960b065e247
211 tree 149d63cd5878155c846e8c55d7d8487de283f89e
212 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
213 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
214 EOF
215
216 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected"
217
218 test_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
224 test_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
232 test_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
241 test_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
260 test_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
281 test_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
287 test_expect_success 'rebase should not fail with a touched file' '
288         test-chmtime =-60 foo &&
289         git svn rebase
290 '
291
292 test_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
300 test_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         '
308 test_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
317 test_done