blob: b041516a1d6316dd36657b582c15100c0a7359d0 [file] [log] [blame]
Eric Wong96a40b22006-02-20 10:57:29 -08001#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
Nanako Shiraishi1364ff22008-09-08 19:02:08 +09006test_description='git svn basic tests'
Ramsay Jones952182b2008-07-08 23:59:25 +01007GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
Eric Wongdc62e252006-06-28 03:07:14 -07008
Eric Wong36f5b1f2006-05-23 19:23:41 -07009. ./lib-git-svn.sh
Eric Wong96a40b22006-02-20 10:57:29 -080010
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090011say 'define NO_SVN_TESTS to skip git svn tests'
Eric Wong60d02cc2006-07-06 00:14:16 -070012
Johannes Sixt7b7247b2009-02-24 21:13:39 +010013case "$GIT_SVN_LC_ALL" in
14*.UTF-8)
15 test_set_prereq UTF8
16 ;;
17*)
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +000018 say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
Johannes Sixt7b7247b2009-02-24 21:13:39 +010019 ;;
20esac
21
Eric Wong96a40b22006-02-20 10:57:29 -080022test_expect_success \
Nanako Shiraishif9647322008-09-10 06:25:27 +090023 'initialize git svn' '
Eric Wong39ed7c12006-12-26 16:27:37 -080024 mkdir import &&
Jonathan Nieder18a82692010-09-06 20:42:54 -050025 (
26 cd import &&
27 echo foo >foo &&
28 ln -s foo foo.link
29 mkdir -p dir/a/b/c/d/e &&
30 echo "deep dir" >dir/a/b/c/d/e/file &&
31 mkdir bar &&
32 echo "zzz" >bar/zzz &&
33 echo "#!/bin/sh" >exec.sh &&
34 chmod +x exec.sh &&
35 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +020036 ) &&
Eric Wong39ed7c12006-12-26 16:27:37 -080037 rm -rf import &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090038 git svn init "$svnrepo"'
Eric Wong96a40b22006-02-20 10:57:29 -080039
40test_expect_success \
41 'import an SVN revision into git' \
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090042 'git svn fetch'
Eric Wong96a40b22006-02-20 10:57:29 -080043
Bryan Donlanf69e8362008-05-04 01:37:59 -040044test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
Eric Wong96a40b22006-02-20 10:57:29 -080045
46name='try a deep --rmdir with a commit'
Bryan Donlanf69e8362008-05-04 01:37:59 -040047test_expect_success "$name" '
Nanako Shiraishi16805d32008-09-08 19:02:05 +090048 git checkout -f -b mybranch ${remotes_git_svn} &&
Eric Wong39ed7c12006-12-26 16:27:37 -080049 mv dir/a/b/c/d/e/file dir/file &&
50 cp dir/file file &&
51 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
Bryan Donlanf69e8362008-05-04 01:37:59 -040052 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090053 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +090054 ${remotes_git_svn}..mybranch &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040055 svn_cmd up "$SVN_TREE" &&
Bryan Donlanf69e8362008-05-04 01:37:59 -040056 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
Eric Wong96a40b22006-02-20 10:57:29 -080057
58
59name='detect node change from file to directory #1'
Junio C Hamano41ac4142008-02-01 01:50:53 -080060test_expect_success "$name" "
Eric Wong39ed7c12006-12-26 16:27:37 -080061 mkdir dir/new_file &&
62 mv dir/file dir/new_file/file &&
63 mv dir/new_file dir/file &&
64 git update-index --remove dir/file &&
65 git update-index --add dir/file/file &&
Junio C Hamano41ac4142008-02-01 01:50:53 -080066 git commit -m '$name' &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090067 test_must_fail git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +090068 ${remotes_git_svn}..mybranch" || true
Eric Wong96a40b22006-02-20 10:57:29 -080069
70
71name='detect node change from directory to file #1'
Bryan Donlanf69e8362008-05-04 01:37:59 -040072test_expect_success "$name" '
73 rm -rf dir "$GIT_DIR"/index &&
Nanako Shiraishi16805d32008-09-08 19:02:05 +090074 git checkout -f -b mybranch2 ${remotes_git_svn} &&
Eric Wong39ed7c12006-12-26 16:27:37 -080075 mv bar/zzz zzz &&
76 rm -rf bar &&
77 mv zzz bar &&
78 git update-index --remove -- bar/zzz &&
79 git update-index --add -- bar &&
Bryan Donlanf69e8362008-05-04 01:37:59 -040080 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090081 test_must_fail git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +090082 ${remotes_git_svn}..mybranch2' || true
Eric Wong96a40b22006-02-20 10:57:29 -080083
84
85name='detect node change from file to directory #2'
Bryan Donlanf69e8362008-05-04 01:37:59 -040086test_expect_success "$name" '
87 rm -f "$GIT_DIR"/index &&
Nanako Shiraishi16805d32008-09-08 19:02:05 +090088 git checkout -f -b mybranch3 ${remotes_git_svn} &&
Eric Wong39ed7c12006-12-26 16:27:37 -080089 rm bar/zzz &&
Junio C Hamano5be60072007-07-02 22:52:14 -070090 git update-index --remove bar/zzz &&
Eric Wong39ed7c12006-12-26 16:27:37 -080091 mkdir bar/zzz &&
92 echo yyy > bar/zzz/yyy &&
Junio C Hamano5be60072007-07-02 22:52:14 -070093 git update-index --add bar/zzz/yyy &&
Bryan Donlanf69e8362008-05-04 01:37:59 -040094 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090095 test_must_fail git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +090096 ${remotes_git_svn}..mybranch3' || true
Eric Wong96a40b22006-02-20 10:57:29 -080097
98
99name='detect node change from directory to file #2'
Bryan Donlanf69e8362008-05-04 01:37:59 -0400100test_expect_success "$name" '
101 rm -f "$GIT_DIR"/index &&
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900102 git checkout -f -b mybranch4 ${remotes_git_svn} &&
Eric Wong39ed7c12006-12-26 16:27:37 -0800103 rm -rf dir &&
104 git update-index --remove -- dir/file &&
105 touch dir &&
106 echo asdf > dir &&
107 git update-index --add -- dir &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400108 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900109 test_must_fail git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900110 ${remotes_git_svn}..mybranch4' || true
Eric Wong96a40b22006-02-20 10:57:29 -0800111
112
113name='remove executable bit from a file'
Bryan Donlanf69e8362008-05-04 01:37:59 -0400114test_expect_success "$name" '
115 rm -f "$GIT_DIR"/index &&
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900116 git checkout -f -b mybranch5 ${remotes_git_svn} &&
Eric Wong39ed7c12006-12-26 16:27:37 -0800117 chmod -x exec.sh &&
118 git update-index exec.sh &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400119 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900120 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900121 ${remotes_git_svn}..mybranch5 &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400122 svn_cmd up "$SVN_TREE" &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400123 test ! -x "$SVN_TREE"/exec.sh'
Eric Wong96a40b22006-02-20 10:57:29 -0800124
125
126name='add executable bit back file'
Bryan Donlanf69e8362008-05-04 01:37:59 -0400127test_expect_success "$name" '
Eric Wong39ed7c12006-12-26 16:27:37 -0800128 chmod +x exec.sh &&
129 git update-index exec.sh &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400130 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900131 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900132 ${remotes_git_svn}..mybranch5 &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400133 svn_cmd up "$SVN_TREE" &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400134 test -x "$SVN_TREE"/exec.sh'
Eric Wong96a40b22006-02-20 10:57:29 -0800135
136
Eric Wong5bd38702006-12-31 21:49:46 -0800137name='executable file becomes a symlink to bar/zzz (file)'
Bryan Donlanf69e8362008-05-04 01:37:59 -0400138test_expect_success "$name" '
Eric Wong5bd38702006-12-31 21:49:46 -0800139 rm exec.sh &&
140 ln -s bar/zzz exec.sh &&
141 git update-index exec.sh &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400142 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900143 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900144 ${remotes_git_svn}..mybranch5 &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400145 svn_cmd up "$SVN_TREE" &&
Jeff Kingafa08762010-09-21 20:35:59 -0400146 test -h "$SVN_TREE"/exec.sh'
Eric Wong96a40b22006-02-20 10:57:29 -0800147
Eric Wong5bd38702006-12-31 21:49:46 -0800148name='new symlink is added to a file that was also just made executable'
Eric Wong96a40b22006-02-20 10:57:29 -0800149
Bryan Donlanf69e8362008-05-04 01:37:59 -0400150test_expect_success "$name" '
Eric Wong5bd38702006-12-31 21:49:46 -0800151 chmod +x bar/zzz &&
152 ln -s bar/zzz exec-2.sh &&
153 git update-index --add bar/zzz exec-2.sh &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400154 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900155 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900156 ${remotes_git_svn}..mybranch5 &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400157 svn_cmd up "$SVN_TREE" &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400158 test -x "$SVN_TREE"/bar/zzz &&
Jeff Kingafa08762010-09-21 20:35:59 -0400159 test -h "$SVN_TREE"/exec-2.sh'
Eric Wong96a40b22006-02-20 10:57:29 -0800160
Eric Wong5bd38702006-12-31 21:49:46 -0800161name='modify a symlink to become a file'
Bryan Donlanf69e8362008-05-04 01:37:59 -0400162test_expect_success "$name" '
Eric Wong5bd38702006-12-31 21:49:46 -0800163 echo git help > help || true &&
164 rm exec-2.sh &&
165 cp help exec-2.sh &&
166 git update-index exec-2.sh &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400167 git commit -m "$name" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900168 git svn set-tree --find-copies-harder --rmdir \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900169 ${remotes_git_svn}..mybranch5 &&
Eygene Ryabinkinda083d62009-05-08 12:06:16 +0400170 svn_cmd up "$SVN_TREE" &&
Bryan Donlanf69e8362008-05-04 01:37:59 -0400171 test -f "$SVN_TREE"/exec-2.sh &&
Jeff Kingafa08762010-09-21 20:35:59 -0400172 test ! -h "$SVN_TREE"/exec-2.sh &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700173 test_cmp help "$SVN_TREE"/exec-2.sh'
Eric Wong96a40b22006-02-20 10:57:29 -0800174
Johannes Sixt7b7247b2009-02-24 21:13:39 +0100175name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
176LC_ALL="$GIT_SVN_LC_ALL"
177export LC_ALL
178test_expect_success UTF8 "$name" "
179 echo '# hello' >> exec-2.sh &&
180 git update-index exec-2.sh &&
181 git commit -m 'éï∏' &&
182 git svn set-tree HEAD"
183unset LC_ALL
Eric Wong96a40b22006-02-20 10:57:29 -0800184
185name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
186GIT_SVN_ID=alt
187export GIT_SVN_ID
188test_expect_success "$name" \
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900189 'git svn init "$svnrepo" && git svn fetch &&
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900190 git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700191 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700192 test_cmp a b'
Eric Wong96a40b22006-02-20 10:57:29 -0800193
Eric Wong42d32872006-06-13 04:02:23 -0700194name='check imported tree checksums expected tree checksums'
Eric Wong86f36372006-06-15 19:13:56 -0700195rm -f expected
Johannes Sixt7b7247b2009-02-24 21:13:39 +0100196if test_have_prereq UTF8
Eric Wong86f36372006-06-15 19:13:56 -0700197then
Ramsay Allan Jones822a7d52006-07-30 22:42:25 +0100198 echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected
Eric Wong86f36372006-06-15 19:13:56 -0700199fi
200cat >> expected <<\EOF
Ramsay Allan Jones822a7d52006-07-30 22:42:25 +0100201tree 83654bb36f019ae4fe77a0171f81075972087624
Eric Wong42d32872006-06-13 04:02:23 -0700202tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
203tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
204tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
205tree 56a30b966619b863674f5978696f4a3594f2fca9
206tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
207tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
208EOF
Eric Wonge1516112006-11-27 21:46:50 -0800209
Junio C Hamano3af82862008-05-23 22:28:56 -0700210test_expect_success "$name" "test_cmp a expected"
Eric Wong42d32872006-06-13 04:02:23 -0700211
Junio C Hamano41ac4142008-02-01 01:50:53 -0800212test_expect_success 'exit if remote refs are ambigious' "
Junio C Hamano5be60072007-07-02 22:52:14 -0700213 git config --add svn-remote.svn.fetch \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900214 bar:refs/${remotes_git_svn} &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900215 test_must_fail git svn migrate
Junio C Hamano41ac4142008-02-01 01:50:53 -0800216"
Eric Wonge6434f82007-01-23 16:29:23 -0800217
Bryan Donlanf69e8362008-05-04 01:37:59 -0400218test_expect_success 'exit if init-ing a would clobber a URL' '
219 svnadmin create "${PWD}/svnrepo2" &&
220 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700221 git config --unset svn-remote.svn.fetch \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900222 "^bar:refs/${remotes_git_svn}$" &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900223 test_must_fail git svn init "${svnrepo}2/bar"
Bryan Donlanf69e8362008-05-04 01:37:59 -0400224 '
Eric Wonge6434f82007-01-23 16:29:23 -0800225
226test_expect_success \
Bryan Donlanf69e8362008-05-04 01:37:59 -0400227 'init allows us to connect to another directory in the same repo' '
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900228 git svn init --minimize-url -i bar "$svnrepo/bar" &&
Eric Wongccb6b6f2007-02-13 17:38:58 -0800229 git config --get svn-remote.svn.fetch \
Bryan Donlanf69e8362008-05-04 01:37:59 -0400230 "^bar:refs/remotes/bar$" &&
Eric Wongccb6b6f2007-02-13 17:38:58 -0800231 git config --get svn-remote.svn.fetch \
Nanako Shiraishi16805d32008-09-08 19:02:05 +0900232 "^:refs/${remotes_git_svn}$"
Bryan Donlanf69e8362008-05-04 01:37:59 -0400233 '
Eric Wongb805b442007-01-22 13:52:04 -0800234
Thomas Rast5eec27e2009-05-29 17:09:42 +0200235test_expect_success 'dcommit $rev does not clobber current branch' '
236 git svn fetch -i bar &&
237 git checkout -b my-bar refs/remotes/bar &&
238 echo 1 > foo &&
239 git add foo &&
240 git commit -m "change 1" &&
241 echo 2 > foo &&
242 git add foo &&
243 git commit -m "change 2" &&
244 old_head=$(git rev-parse HEAD) &&
245 git svn dcommit -i bar HEAD^ &&
246 test $old_head = $(git rev-parse HEAD) &&
247 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
248 git log refs/remotes/bar | grep "change 1" &&
249 ! git log refs/remotes/bar | grep "change 2" &&
250 git checkout master &&
251 git branch -D my-bar
252 '
253
Eric Wongd3a840d2007-01-26 01:32:45 -0800254test_expect_success 'able to dcommit to a subdirectory' "
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900255 git svn fetch -i bar &&
Eric Wongd3a840d2007-01-26 01:32:45 -0800256 git checkout -b my-bar refs/remotes/bar &&
257 echo abc > d &&
258 git update-index --add d &&
259 git commit -m '/bar/d should be in the log' &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900260 git svn dcommit -i bar &&
Eric Wongd3a840d2007-01-26 01:32:45 -0800261 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
262 mkdir newdir &&
263 echo new > newdir/dir &&
264 git update-index --add newdir/dir &&
265 git commit -m 'add a new directory' &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900266 git svn dcommit -i bar &&
Eric Wongd3a840d2007-01-26 01:32:45 -0800267 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
268 echo foo >> newdir/dir &&
269 git update-index newdir/dir &&
270 git commit -m 'modify a file in new directory' &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900271 git svn dcommit -i bar &&
Eric Wongd3a840d2007-01-26 01:32:45 -0800272 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
273 "
274
David D. Kilzer181264a2010-08-02 12:58:19 -0700275test_expect_success 'dcommit should not fail with a touched file' '
276 test_commit "commit-new-file-foo2" foo2 &&
277 test-chmtime =-60 foo &&
278 git svn dcommit
279'
280
281test_expect_success 'rebase should not fail with a touched file' '
282 test-chmtime =-60 foo &&
283 git svn rebase
284'
285
Eric Wongd3a840d2007-01-26 01:32:45 -0800286test_expect_success 'able to set-tree to a subdirectory' "
287 echo cba > d &&
288 git update-index d &&
289 git commit -m 'update /bar/d' &&
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900290 git svn set-tree -i bar HEAD &&
Eric Wongd3a840d2007-01-26 01:32:45 -0800291 test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
292 "
293
Deskin Miller6e5121f2008-11-06 00:07:39 -0500294test_expect_success 'git-svn works in a bare repository' '
295 mkdir bare-repo &&
296 ( cd bare-repo &&
297 git init --bare &&
298 GIT_DIR=. git svn init "$svnrepo" &&
299 git svn fetch ) &&
300 rm -rf bare-repo
301 '
302
Eric Wong96a40b22006-02-20 10:57:29 -0800303test_done