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