t9100: explicitly unset GIT_COMMITTER_DATE
[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 # Make sure timestamps of commits created by Git interleave
12 # with those created by "svn set-tree".
13 unset GIT_COMMITTER_DATE
14
15 case "$GIT_SVN_LC_ALL" in
16 *.UTF-8)
17         test_set_prereq UTF8
18         ;;
19 *)
20         say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
21         ;;
22 esac
23
24 test_expect_success 'git svn --version works anywhere' '
25         nongit git svn --version
26 '
27
28 test_expect_success 'git svn help works anywhere' '
29         nongit git svn help
30 '
31
32 test_expect_success \
33     'initialize git svn' '
34         mkdir import &&
35         (
36                 cd import &&
37                 echo foo >foo &&
38                 ln -s foo foo.link &&
39                 mkdir -p dir/a/b/c/d/e &&
40                 echo "deep dir" >dir/a/b/c/d/e/file &&
41                 mkdir bar &&
42                 echo "zzz" >bar/zzz &&
43                 echo "#!/bin/sh" >exec.sh &&
44                 chmod +x exec.sh &&
45                 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
46         ) &&
47         rm -rf import &&
48         git svn init "$svnrepo"'
49
50 test_expect_success \
51     'import an SVN revision into git' \
52     'git svn fetch'
53
54 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
55
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 &&
60         cp dir/file 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'
67
68
69 name='detect node change from file to directory #1'
70 test_expect_success "$name" "
71         mkdir dir/new_file &&
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
79 "
80
81
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 &&
86         mv bar/zzz zzz &&
87         rm -rf bar &&
88         mv zzz bar &&
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
94 '
95
96
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 &&
101         rm bar/zzz &&
102         git update-index --remove bar/zzz &&
103         mkdir 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
112 '
113
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 &&
118         rm -rf dir &&
119         git update-index --remove -- dir/file &&
120         touch dir &&
121         echo asdf > dir &&
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
126 '
127
128
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 &&
133         chmod -x exec.sh &&
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'
140
141
142 name='add executable bit back file'
143 test_expect_success POSIXPERM "$name" '
144         chmod +x 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 -x "$SVN_TREE"/exec.sh'
151
152
153 name='executable file becomes a symlink to file'
154 test_expect_success SYMLINKS "$name" '
155         rm exec.sh &&
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'
163
164 name='new symlink is added to a file that was also just made executable'
165
166 test_expect_success POSIXPERM,SYMLINKS "$name" '
167         chmod +x file &&
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'
176
177 name='modify a symlink to become a file'
178 test_expect_success POSIXPERM,SYMLINKS "$name" '
179         echo git help >help &&
180         rm exec-2.sh &&
181         cp help exec-2.sh &&
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'
190
191 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
192 LC_ALL="$GIT_SVN_LC_ALL"
193 export 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"
200 unset LC_ALL
201
202 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
203 GIT_SVN_ID=alt
204 export 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 &&
209      test_cmp a b'
210
211 name='check imported tree checksums expected tree checksums'
212 rm -f expected
213 if test_have_prereq UTF8
214 then
215         echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
216 fi
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
226 EOF
227
228 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp expected a"
229
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
234 '
235
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"
242         '
243
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$"
251         '
252
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 &&
256         echo 1 > foo &&
257         git add foo &&
258         git commit -m "change 1" &&
259         echo 2 > foo &&
260         git add foo &&
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 &&
269         git branch -D my-bar
270         '
271
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 &&
275         echo abc > d &&
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)" &&
280         mkdir newdir &&
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)"
291 '
292
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 &&
296         git svn dcommit
297 '
298
299 test_expect_success 'rebase should not fail with a touched file' '
300         test-tool chmtime =-60 foo &&
301         git svn rebase
302 '
303
304 test_expect_success 'able to set-tree to a subdirectory' '
305         echo cba > d &&
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)"
310 '
311
312 test_expect_success 'git-svn works in a bare repository' '
313         mkdir bare-repo &&
314         ( cd bare-repo &&
315         git init --bare &&
316         GIT_DIR=. git svn init "$svnrepo" &&
317         git svn fetch ) &&
318         rm -rf bare-repo
319         '
320 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
321         mkdir worktree gitdir &&
322         ( cd worktree &&
323         git svn init "$svnrepo" &&
324         git init --separate-git-dir ../gitdir &&
325         git svn fetch ) &&
326         rm -rf worktree gitdir
327         '
328
329 test_done