git-svn: Make following parents atomic
[git/git.git] / t / t9104-git-svn-follow-parent.sh
CommitLineData
a00439ac
EW
1#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
0bed5eaa 6test_description='git-svn fetching'
a00439ac
EW
7. ./lib-git-svn.sh
8
f69e836f 9test_expect_success 'initialize repo' '
a00439ac
EW
10 mkdir import &&
11 cd import &&
12 mkdir -p trunk &&
13 echo hello > trunk/readme &&
f69e836f 14 svn import -m "initial" . "$svnrepo" &&
a00439ac 15 cd .. &&
f69e836f 16 svn co "$svnrepo" wc &&
a00439ac
EW
17 cd wc &&
18 echo world >> trunk/readme &&
7b3fab87 19 poke trunk/readme &&
f69e836f 20 svn commit -m "another commit" &&
e66191f4 21 svn up &&
400e58b7 22 svn mv trunk thunk &&
a00439ac 23 echo goodbye >> thunk/readme &&
7b3fab87 24 poke thunk/readme &&
f69e836f 25 svn commit -m "bye now" &&
a00439ac 26 cd ..
f69e836f 27 '
a00439ac 28
f69e836f
BD
29test_expect_success 'init and fetch a moved directory' '
30 git-svn init --minimize-url -i thunk "$svnrepo"/thunk &&
0bed5eaa 31 git-svn fetch -i thunk &&
f69e836f
BD
32 test "`git rev-parse --verify refs/remotes/thunk@2`" \
33 = "`git rev-parse --verify refs/remotes/thunk~1`" &&
34 test "`git cat-file blob refs/remotes/thunk:readme |\
35 sed -n -e "3p"`" = goodbye &&
36 test -z "`git config --get svn-remote.svn.fetch \
37 "^trunk:refs/remotes/thunk@2$"`"
38 '
a00439ac 39
f69e836f
BD
40test_expect_success 'init and fetch from one svn-remote' '
41 git config svn-remote.svn.url "$svnrepo" &&
5be60078 42 git config --add svn-remote.svn.fetch \
8b8fc068 43 trunk:refs/remotes/svn/trunk &&
5be60078 44 git config --add svn-remote.svn.fetch \
8b8fc068 45 thunk:refs/remotes/svn/thunk &&
0bed5eaa 46 git-svn fetch -i svn/thunk &&
f69e836f
BD
47 test "`git rev-parse --verify refs/remotes/svn/trunk`" \
48 = "`git rev-parse --verify refs/remotes/svn/thunk~1`" &&
49 test "`git cat-file blob refs/remotes/svn/thunk:readme |\
50 sed -n -e "3p"`" = goodbye
51 '
8b8fc068 52
f69e836f
BD
53test_expect_success 'follow deleted parent' '
54 (svn cp -m "resurrecting trunk as junk" \
55 "$svnrepo"/trunk@2 "$svnrepo"/junk ||
56 svn cp -m "resurrecting trunk as junk" \
57 -r2 "$svnrepo"/trunk "$svnrepo"/junk) &&
5be60078 58 git config --add svn-remote.svn.fetch \
a2003abc 59 junk:refs/remotes/svn/junk &&
0bed5eaa
EW
60 git-svn fetch -i svn/thunk &&
61 git-svn fetch -i svn/junk &&
f69e836f
BD
62 test -z "`git diff svn/junk svn/trunk`" &&
63 test "`git merge-base svn/junk svn/trunk`" \
64 = "`git rev-parse svn/trunk`"
65 '
a2003abc 66
f69e836f 67test_expect_success 'follow larger parent' '
7f578c55
EW
68 mkdir -p import/trunk/thunk/bump/thud &&
69 echo hi > import/trunk/thunk/bump/thud/file &&
f69e836f
BD
70 svn import -m "import a larger parent" import "$svnrepo"/larger-parent &&
71 svn cp -m "hi" "$svnrepo"/larger-parent "$svnrepo"/another-larger &&
4a1bb4c3 72 git-svn init --minimize-url -i larger \
f69e836f 73 "$svnrepo"/another-larger/trunk/thunk/bump/thud &&
0bed5eaa 74 git-svn fetch -i larger &&
5be60078
JH
75 git rev-parse --verify refs/remotes/larger &&
76 git rev-parse --verify \
7f578c55 77 refs/remotes/larger-parent/trunk/thunk/bump/thud &&
f69e836f 78 test "`git merge-base \
7f578c55 79 refs/remotes/larger-parent/trunk/thunk/bump/thud \
f69e836f
BD
80 refs/remotes/larger`" = \
81 "`git rev-parse refs/remotes/larger`"
7f578c55 82 true
f69e836f 83 '
7f578c55 84
f69e836f
BD
85test_expect_success 'follow higher-level parent' '
86 svn mkdir -m "follow higher-level parent" "$svnrepo"/blob &&
87 svn co "$svnrepo"/blob blob &&
1492b424
EW
88 cd blob &&
89 echo hi > hi &&
90 svn add hi &&
f69e836f 91 svn commit -m "hihi" &&
1492b424 92 cd ..
f69e836f
BD
93 svn mkdir -m "new glob at top level" "$svnrepo"/glob &&
94 svn mv -m "move blob down a level" "$svnrepo"/blob "$svnrepo"/glob/blob &&
95 git-svn init --minimize-url -i blob "$svnrepo"/glob/blob &&
0bed5eaa 96 git-svn fetch -i blob
f69e836f 97 '
1492b424 98
f69e836f
BD
99test_expect_success 'follow deleted directory' '
100 svn mv -m "bye!" "$svnrepo"/glob/blob/hi "$svnrepo"/glob/blob/bye &&
101 svn rm -m "remove glob" "$svnrepo"/glob &&
102 git-svn init --minimize-url -i glob "$svnrepo"/glob &&
e5a0b240 103 git-svn fetch -i glob &&
f69e836f
BD
104 test "`git cat-file blob refs/remotes/glob:blob/bye`" = hi &&
105 test "`git ls-tree refs/remotes/glob | wc -l `" -eq 1
106 '
e5a0b240 107
2b27f6c8
EW
108# ref: r9270 of the Subversion repository: (http://svn.collab.net/repos/svn)
109# in trunk/subversion/bindings/swig/perl
f69e836f 110test_expect_success 'follow-parent avoids deleting relevant info' '
2b27f6c8
EW
111 mkdir -p import/trunk/subversion/bindings/swig/perl/t &&
112 for i in a b c ; do \
f69e836f
BD
113 echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm &&
114 echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \
2b27f6c8 115 done &&
f69e836f 116 echo "bad delete test" > \
2b27f6c8 117 import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
f69e836f 118 echo "bad delete test 2" > \
2b27f6c8
EW
119 import/trunk/subversion/bindings/swig/perl/another-larger &&
120 cd import &&
f69e836f 121 svn import -m "r9270 test" . "$svnrepo"/r9270 &&
2b27f6c8 122 cd .. &&
f69e836f 123 svn co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 &&
2b27f6c8
EW
124 cd r9270 &&
125 svn mkdir native &&
126 svn mv t native/t &&
f69e836f 127 for i in a b c; do svn mv $i.pm native/$i.pm; done &&
2b27f6c8 128 echo z >> native/t/c.t &&
ccb6b6f5 129 poke native/t/c.t &&
f69e836f 130 svn commit -m "reorg test" &&
2b27f6c8 131 cd .. &&
4a1bb4c3 132 git-svn init --minimize-url -i r9270-t \
f69e836f 133 "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl/native/t &&
0bed5eaa 134 git-svn fetch -i r9270-t &&
f69e836f
BD
135 test `git rev-list r9270-t | wc -l` -eq 2 &&
136 test "`git ls-tree --name-only r9270-t~1`" = \
137 "`git ls-tree --name-only r9270-t`"
138 '
2b27f6c8 139
f69e836f
BD
140test_expect_success "track initial change if it was only made to parent" '
141 svn cp -m "wheee!" "$svnrepo"/r9270/trunk "$svnrepo"/r9270/drunk &&
4a1bb4c3 142 git-svn init --minimize-url -i r9270-d \
f69e836f 143 "$svnrepo"/r9270/drunk/subversion/bindings/swig/perl/native/t &&
0bed5eaa 144 git-svn fetch -i r9270-d &&
f69e836f
BD
145 test `git rev-list r9270-d | wc -l` -eq 3 &&
146 test "`git ls-tree --name-only r9270-t`" = \
147 "`git ls-tree --name-only r9270-d`" &&
148 test "`git rev-parse r9270-t`" = \
149 "`git rev-parse r9270-d~1`"
150 '
28937057 151
553589f7
DM
152test_expect_success "follow-parent is atomic" '
153 (
154 cd wc &&
155 svn up &&
156 svn mkdir stunk &&
157 echo "trunk stunk" > stunk/readme &&
158 svn add stunk/readme &&
159 svn ci -m "trunk stunk" &&
160 echo "stunk like junk" >> stunk/readme &&
161 svn ci -m "really stunk" &&
162 echo "stink stank stunk" >> stunk/readme &&
163 svn ci -m "even the grinch agrees"
164 ) &&
165 svn copy -m "stunk flunked" "$svnrepo"/stunk "$svnrepo"/flunk &&
166 { svn cp -m "early stunk flunked too" \
167 "$svnrepo"/stunk@17 "$svnrepo"/flunked ||
168 svn cp -m "early stunk flunked too" \
169 -r17 "$svnrepo"/stunk "$svnrepo"/flunked; } &&
170 git svn init --minimize-url -i stunk "$svnrepo"/stunk &&
171 git svn fetch -i stunk &&
172 git update-ref refs/remotes/flunk@18 refs/remotes/stunk~2 &&
173 git update-ref -d refs/remotes/stunk &&
174 git config --unset svn-remote.svn.fetch stunk &&
175 mkdir -p "$GIT_DIR"/svn/flunk@18 &&
176 rev_map=$(cd "$GIT_DIR"/svn/stunk && ls .rev_map*) &&
177 dd if="$GIT_DIR"/svn/stunk/$rev_map \
178 of="$GIT_DIR"/svn/flunk@18/$rev_map bs=24 count=1 &&
179 rm -rf "$GIT_DIR"/svn/stunk &&
180 git svn init --minimize-url -i flunk "$svnrepo"/flunk &&
181 git svn fetch -i flunk &&
182 git svn init --minimize-url -i stunk "$svnrepo"/stunk &&
183 git svn fetch -i stunk &&
184 git svn init --minimize-url -i flunked "$svnrepo"/flunked &&
185 git svn fetch -i flunked
186 test "`git rev-parse --verify refs/remotes/flunk@18`" \
187 = "`git rev-parse --verify refs/remotes/stunk`" &&
188 test "`git rev-parse --verify refs/remotes/flunk~1`" \
189 = "`git rev-parse --verify refs/remotes/stunk`" &&
190 test "`git rev-parse --verify refs/remotes/flunked~1`" \
191 = "`git rev-parse --verify refs/remotes/stunk~1`"
192 '
193
f69e836f
BD
194test_expect_success "track multi-parent paths" '
195 svn cp -m "resurrect /glob" "$svnrepo"/r9270 "$svnrepo"/glob &&
0bed5eaa 196 git-svn multi-fetch &&
f69e836f
BD
197 test `git cat-file commit refs/remotes/glob | \
198 grep "^parent " | wc -l` -eq 2
199 '
b9dffd8c 200
8a603774 201test_expect_success "multi-fetch continues to work" "
0bed5eaa 202 git-svn multi-fetch
8a603774
EW
203 "
204
f69e836f
BD
205test_expect_success "multi-fetch works off a 'clean' repository" '
206 rm -r "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" "$GIT_DIR/logs" &&
207 mkdir "$GIT_DIR/svn" &&
0bed5eaa 208 git-svn multi-fetch
f69e836f 209 '
8a603774 210
a00439ac
EW
211test_debug 'gitk --all &'
212
213test_done