git-svn: allow 'init' to act as multi-init
[git/jnareb-git/bp-gitweb.git] / t / t9107-git-svn-migrate.sh
bloba20038b6705a380e93983a23d4a6671b2d5944bf
1 #!/bin/sh
2 # Copyright (c) 2006 Eric Wong
3 test_description='git-svn metadata migrations from previous versions'
4 . ./lib-git-svn.sh
6 test_expect_success 'setup old-looking metadata' "
7 cp $GIT_DIR/config $GIT_DIR/config-old-git-svn &&
8 mkdir import &&
9 cd import &&
10 for i in trunk branches/a branches/b \
11 tags/0.1 tags/0.2 tags/0.3; do
12 mkdir -p \$i && \
13 echo hello >> \$i/README || exit 1
14 done && \
15 svn import -m test . $svnrepo
16 cd .. &&
17 git-svn init $svnrepo &&
18 git-svn fetch &&
19 mv $GIT_DIR/svn/* $GIT_DIR/ &&
20 rmdir $GIT_DIR/svn &&
21 git-update-ref refs/heads/git-svn-HEAD refs/remotes/git-svn &&
22 git-update-ref refs/heads/svn-HEAD refs/remotes/git-svn &&
23 git-update-ref -d refs/remotes/git-svn refs/remotes/git-svn
26 head=`git rev-parse --verify refs/heads/git-svn-HEAD^0`
27 test_expect_success 'git-svn-HEAD is a real HEAD' "test -n '$head'"
29 test_expect_success 'initialize old-style (v0) git-svn layout' "
30 mkdir -p $GIT_DIR/git-svn/info $GIT_DIR/svn/info &&
31 echo $svnrepo > $GIT_DIR/git-svn/info/url &&
32 echo $svnrepo > $GIT_DIR/svn/info/url &&
33 git-svn migrate &&
34 ! test -d $GIT_DIR/git-svn &&
35 git-rev-parse --verify refs/remotes/git-svn^0 &&
36 git-rev-parse --verify refs/remotes/svn^0 &&
37 test \`git config --get svn-remote.svn.url\` = '$svnrepo' &&
38 test \`git config --get svn-remote.svn.fetch\` = \
39 ':refs/remotes/git-svn'
42 test_expect_success 'initialize a multi-repository repo' "
43 git-svn init $svnrepo -T trunk -t tags -b branches &&
44 git-config --get-all svn-remote.svn.fetch > fetch.out &&
45 grep '^trunk:refs/remotes/trunk$' fetch.out &&
46 test -n \"\`git-config --get svn-remote.svn.branches \
47 '^branches/\*:refs/remotes/\*$'\`\" &&
48 test -n \"\`git-config --get svn-remote.svn.tags \
49 '^tags/\*:refs/remotes/tags/\*$'\`\" &&
50 git config --unset svn-remote.svn.branches \
51 '^branches/\*:refs/remotes/\*$' &&
52 git config --unset svn-remote.svn.tags \
53 '^tags/\*:refs/remotes/tags/\*$' &&
54 git-config --add svn-remote.svn.fetch 'branches/a:refs/remotes/a' &&
55 git-config --add svn-remote.svn.fetch 'branches/b:refs/remotes/b' &&
56 for i in tags/0.1 tags/0.2 tags/0.3; do
57 git-config --add svn-remote.svn.fetch \
58 \$i:refs/remotes/\$i || exit 1; done
61 # refs should all be different, but the trees should all be the same:
62 test_expect_success 'multi-fetch works on partial urls + paths' "
63 git-svn multi-fetch &&
64 for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do
65 git rev-parse --verify refs/remotes/\$i^0 >> refs.out || exit 1;
66 done &&
67 test -z \"\`sort < refs.out | uniq -d\`\" &&
68 for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do
69 for j in trunk a b tags/0.1 tags/0.2 tags/0.3; do
70 if test \$j != \$i; then continue; fi
71 test -z \"\`git diff refs/remotes/\$i \
72 refs/remotes/\$j\`\" ||exit 1; done; done
75 test_expect_success 'migrate --minimize on old inited layout' "
76 git config --unset-all svn-remote.svn.fetch &&
77 git config --unset-all svn-remote.svn.url &&
78 rm -rf $GIT_DIR/svn &&
79 for i in \`cat fetch.out\`; do
80 path=\`expr \$i : '\\([^:]*\\):.*$'\`
81 ref=\`expr \$i : '[^:]*:refs/remotes/\\(.*\\)$'\`
82 if test -z \"\$ref\"; then continue; fi
83 if test -n \"\$path\"; then path=\"/\$path\"; fi
84 ( mkdir -p $GIT_DIR/svn/\$ref/info/ &&
85 echo $svnrepo\$path > $GIT_DIR/svn/\$ref/info/url ) || exit 1;
86 done &&
87 git-svn migrate --minimize &&
88 test -z \"\`git-config -l |grep -v '^svn-remote\.git-svn\.'\`\" &&
89 git-config --get-all svn-remote.svn.fetch > fetch.out &&
90 grep '^trunk:refs/remotes/trunk$' fetch.out &&
91 grep '^branches/a:refs/remotes/a$' fetch.out &&
92 grep '^branches/b:refs/remotes/b$' fetch.out &&
93 grep '^tags/0\.1:refs/remotes/tags/0\.1$' fetch.out &&
94 grep '^tags/0\.2:refs/remotes/tags/0\.2$' fetch.out &&
95 grep '^tags/0\.3:refs/remotes/tags/0\.3$' fetch.out
96 grep '^:refs/remotes/git-svn' fetch.out
99 test_expect_success ".rev_db auto-converted to .rev_db.UUID" "
100 git-svn fetch -i trunk &&
101 expect=$GIT_DIR/svn/trunk/.rev_db.* &&
102 test -n \"\$expect\" &&
103 mv \$expect $GIT_DIR/svn/trunk/.rev_db &&
104 git-svn fetch -i trunk &&
105 test -L $GIT_DIR/svn/trunk/.rev_db &&
106 test -f \$expect &&
107 cmp \$expect $GIT_DIR/svn/trunk/.rev_db
110 test_done