]>
Commit | Line | Data |
---|---|---|
96a40b27 EW |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Eric Wong | |
4 | # | |
5 | ||
1364ff27 | 6 | test_description='git svn basic tests' |
952182b5 | 7 | GIT_SVN_LC_ALL=${LC_ALL:-$LANG} |
dc62e25c | 8 | |
7b7247b0 JS |
9 | . ./lib-git-svn.sh |
10 | ||
11 | say 'define NO_SVN_TESTS to skip git svn tests' | |
12 | ||
952182b5 | 13 | case "$GIT_SVN_LC_ALL" in |
dc62e25c | 14 | *.UTF-8) |
7b7247b0 | 15 | test_set_prereq UTF8 |
dc62e25c EW |
16 | ;; |
17 | *) | |
fadb5156 | 18 | say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)" |
dc62e25c EW |
19 | ;; |
20 | esac | |
21 | ||
96a40b27 | 22 | test_expect_success \ |
f964732c | 23 | 'initialize git svn' ' |
39ed7c18 EW |
24 | mkdir import && |
25 | cd import && | |
26 | echo foo > foo && | |
5bd3870c | 27 | ln -s foo foo.link |
39ed7c18 | 28 | mkdir -p dir/a/b/c/d/e && |
f69e836f | 29 | echo "deep dir" > dir/a/b/c/d/e/file && |
39ed7c18 | 30 | mkdir bar && |
f69e836f BD |
31 | echo "zzz" > bar/zzz && |
32 | echo "#!/bin/sh" > exec.sh && | |
39ed7c18 | 33 | chmod +x exec.sh && |
da083d68 | 34 | svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null && |
39ed7c18 EW |
35 | cd .. && |
36 | rm -rf import && | |
1364ff27 | 37 | git svn init "$svnrepo"' |
96a40b27 EW |
38 | |
39 | test_expect_success \ | |
40 | 'import an SVN revision into git' \ | |
1364ff27 | 41 | 'git svn fetch' |
96a40b27 | 42 | |
f69e836f | 43 | test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"' |
96a40b27 EW |
44 | |
45 | name='try a deep --rmdir with a commit' | |
f69e836f | 46 | test_expect_success "$name" ' |
16805d3e | 47 | git checkout -f -b mybranch ${remotes_git_svn} && |
39ed7c18 EW |
48 | mv dir/a/b/c/d/e/file dir/file && |
49 | cp dir/file file && | |
50 | git update-index --add --remove dir/a/b/c/d/e/file dir/file file && | |
f69e836f | 51 | git commit -m "$name" && |
1364ff27 | 52 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 53 | ${remotes_git_svn}..mybranch && |
da083d68 | 54 | svn_cmd up "$SVN_TREE" && |
f69e836f | 55 | test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a' |
96a40b27 EW |
56 | |
57 | ||
58 | name='detect node change from file to directory #1' | |
41ac414e | 59 | test_expect_success "$name" " |
39ed7c18 EW |
60 | mkdir dir/new_file && |
61 | mv dir/file dir/new_file/file && | |
62 | mv dir/new_file dir/file && | |
63 | git update-index --remove dir/file && | |
64 | git update-index --add dir/file/file && | |
41ac414e | 65 | git commit -m '$name' && |
1364ff27 | 66 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 67 | ${remotes_git_svn}..mybranch" || true |
96a40b27 EW |
68 | |
69 | ||
70 | name='detect node change from directory to file #1' | |
f69e836f BD |
71 | test_expect_success "$name" ' |
72 | rm -rf dir "$GIT_DIR"/index && | |
16805d3e | 73 | git checkout -f -b mybranch2 ${remotes_git_svn} && |
39ed7c18 EW |
74 | mv bar/zzz zzz && |
75 | rm -rf bar && | |
76 | mv zzz bar && | |
77 | git update-index --remove -- bar/zzz && | |
78 | git update-index --add -- bar && | |
f69e836f | 79 | git commit -m "$name" && |
1364ff27 | 80 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 81 | ${remotes_git_svn}..mybranch2' || true |
96a40b27 EW |
82 | |
83 | ||
84 | name='detect node change from file to directory #2' | |
f69e836f BD |
85 | test_expect_success "$name" ' |
86 | rm -f "$GIT_DIR"/index && | |
16805d3e | 87 | git checkout -f -b mybranch3 ${remotes_git_svn} && |
39ed7c18 | 88 | rm bar/zzz && |
5be60078 | 89 | git update-index --remove bar/zzz && |
39ed7c18 EW |
90 | mkdir bar/zzz && |
91 | echo yyy > bar/zzz/yyy && | |
5be60078 | 92 | git update-index --add bar/zzz/yyy && |
f69e836f | 93 | git commit -m "$name" && |
1364ff27 | 94 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 95 | ${remotes_git_svn}..mybranch3' || true |
96a40b27 EW |
96 | |
97 | ||
98 | name='detect node change from directory to file #2' | |
f69e836f BD |
99 | test_expect_success "$name" ' |
100 | rm -f "$GIT_DIR"/index && | |
16805d3e | 101 | git checkout -f -b mybranch4 ${remotes_git_svn} && |
39ed7c18 EW |
102 | rm -rf dir && |
103 | git update-index --remove -- dir/file && | |
104 | touch dir && | |
105 | echo asdf > dir && | |
106 | git update-index --add -- dir && | |
f69e836f | 107 | git commit -m "$name" && |
1364ff27 | 108 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 109 | ${remotes_git_svn}..mybranch4' || true |
96a40b27 EW |
110 | |
111 | ||
112 | name='remove executable bit from a file' | |
f69e836f BD |
113 | test_expect_success "$name" ' |
114 | rm -f "$GIT_DIR"/index && | |
16805d3e | 115 | git checkout -f -b mybranch5 ${remotes_git_svn} && |
39ed7c18 EW |
116 | chmod -x exec.sh && |
117 | git update-index exec.sh && | |
f69e836f | 118 | git commit -m "$name" && |
1364ff27 | 119 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 120 | ${remotes_git_svn}..mybranch5 && |
da083d68 | 121 | svn_cmd up "$SVN_TREE" && |
f69e836f | 122 | test ! -x "$SVN_TREE"/exec.sh' |
96a40b27 EW |
123 | |
124 | ||
125 | name='add executable bit back file' | |
f69e836f | 126 | test_expect_success "$name" ' |
39ed7c18 EW |
127 | chmod +x exec.sh && |
128 | git update-index exec.sh && | |
f69e836f | 129 | git commit -m "$name" && |
1364ff27 | 130 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 131 | ${remotes_git_svn}..mybranch5 && |
da083d68 | 132 | svn_cmd up "$SVN_TREE" && |
f69e836f | 133 | test -x "$SVN_TREE"/exec.sh' |
96a40b27 EW |
134 | |
135 | ||
5bd3870c | 136 | name='executable file becomes a symlink to bar/zzz (file)' |
f69e836f | 137 | test_expect_success "$name" ' |
5bd3870c EW |
138 | rm exec.sh && |
139 | ln -s bar/zzz exec.sh && | |
140 | git update-index exec.sh && | |
f69e836f | 141 | git commit -m "$name" && |
1364ff27 | 142 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 143 | ${remotes_git_svn}..mybranch5 && |
da083d68 | 144 | svn_cmd up "$SVN_TREE" && |
f69e836f | 145 | test -L "$SVN_TREE"/exec.sh' |
0e8a002c | 146 | |
5bd3870c | 147 | name='new symlink is added to a file that was also just made executable' |
0e8a002c | 148 | |
f69e836f | 149 | test_expect_success "$name" ' |
5bd3870c EW |
150 | chmod +x bar/zzz && |
151 | ln -s bar/zzz exec-2.sh && | |
152 | git update-index --add bar/zzz exec-2.sh && | |
f69e836f | 153 | git commit -m "$name" && |
1364ff27 | 154 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 155 | ${remotes_git_svn}..mybranch5 && |
da083d68 | 156 | svn_cmd up "$SVN_TREE" && |
f69e836f BD |
157 | test -x "$SVN_TREE"/bar/zzz && |
158 | test -L "$SVN_TREE"/exec-2.sh' | |
96a40b27 | 159 | |
5bd3870c | 160 | name='modify a symlink to become a file' |
f69e836f | 161 | test_expect_success "$name" ' |
5bd3870c EW |
162 | echo git help > help || true && |
163 | rm exec-2.sh && | |
164 | cp help exec-2.sh && | |
165 | git update-index exec-2.sh && | |
f69e836f | 166 | git commit -m "$name" && |
1364ff27 | 167 | git svn set-tree --find-copies-harder --rmdir \ |
16805d3e | 168 | ${remotes_git_svn}..mybranch5 && |
da083d68 | 169 | svn_cmd up "$SVN_TREE" && |
f69e836f BD |
170 | test -f "$SVN_TREE"/exec-2.sh && |
171 | test ! -L "$SVN_TREE"/exec-2.sh && | |
3af82863 | 172 | test_cmp help "$SVN_TREE"/exec-2.sh' |
96a40b27 | 173 | |
7b7247b0 JS |
174 | name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL" |
175 | LC_ALL="$GIT_SVN_LC_ALL" | |
176 | export LC_ALL | |
177 | test_expect_success UTF8 "$name" " | |
178 | echo '# hello' >> exec-2.sh && | |
179 | git update-index exec-2.sh && | |
180 | git commit -m 'éï∏' && | |
181 | git svn set-tree HEAD" | |
182 | unset LC_ALL | |
96a40b27 EW |
183 | |
184 | name='test fetch functionality (svn => git) with alternate GIT_SVN_ID' | |
185 | GIT_SVN_ID=alt | |
186 | export GIT_SVN_ID | |
187 | test_expect_success "$name" \ | |
1364ff27 | 188 | 'git svn init "$svnrepo" && git svn fetch && |
16805d3e | 189 | git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a && |
5be60078 | 190 | git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b && |
3af82863 | 191 | test_cmp a b' |
96a40b27 | 192 | |
42d32870 | 193 | name='check imported tree checksums expected tree checksums' |
86f36379 | 194 | rm -f expected |
7b7247b0 | 195 | if test_have_prereq UTF8 |
86f36379 | 196 | then |
822a7d50 | 197 | echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected |
86f36379 EW |
198 | fi |
199 | cat >> expected <<\EOF | |
822a7d50 | 200 | tree 83654bb36f019ae4fe77a0171f81075972087624 |
42d32870 EW |
201 | tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1 |
202 | tree 0b094cbff17168f24c302e297f55bfac65eb8bd3 | |
203 | tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e | |
204 | tree 56a30b966619b863674f5978696f4a3594f2fca9 | |
205 | tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e | |
206 | tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 | |
207 | EOF | |
e1516119 | 208 | |
3af82863 | 209 | test_expect_success "$name" "test_cmp a expected" |
42d32870 | 210 | |
41ac414e | 211 | test_expect_success 'exit if remote refs are ambigious' " |
5be60078 | 212 | git config --add svn-remote.svn.fetch \ |
16805d3e | 213 | bar:refs/${remotes_git_svn} && |
1364ff27 | 214 | test_must_fail git svn migrate |
41ac414e | 215 | " |
e6434f87 | 216 | |
f69e836f BD |
217 | test_expect_success 'exit if init-ing a would clobber a URL' ' |
218 | svnadmin create "${PWD}/svnrepo2" && | |
219 | svn mkdir -m "mkdir bar" "${svnrepo}2/bar" && | |
5be60078 | 220 | git config --unset svn-remote.svn.fetch \ |
16805d3e | 221 | "^bar:refs/${remotes_git_svn}$" && |
1364ff27 | 222 | test_must_fail git svn init "${svnrepo}2/bar" |
f69e836f | 223 | ' |
e6434f87 EW |
224 | |
225 | test_expect_success \ | |
f69e836f | 226 | 'init allows us to connect to another directory in the same repo' ' |
1364ff27 | 227 | git svn init --minimize-url -i bar "$svnrepo/bar" && |
ccb6b6f5 | 228 | git config --get svn-remote.svn.fetch \ |
f69e836f | 229 | "^bar:refs/remotes/bar$" && |
ccb6b6f5 | 230 | git config --get svn-remote.svn.fetch \ |
16805d3e | 231 | "^:refs/${remotes_git_svn}$" |
f69e836f | 232 | ' |
b805b44a | 233 | |
5eec27e3 TR |
234 | test_expect_success 'dcommit $rev does not clobber current branch' ' |
235 | git svn fetch -i bar && | |
236 | git checkout -b my-bar refs/remotes/bar && | |
237 | echo 1 > foo && | |
238 | git add foo && | |
239 | git commit -m "change 1" && | |
240 | echo 2 > foo && | |
241 | git add foo && | |
242 | git commit -m "change 2" && | |
243 | old_head=$(git rev-parse HEAD) && | |
244 | git svn dcommit -i bar HEAD^ && | |
245 | test $old_head = $(git rev-parse HEAD) && | |
246 | test refs/heads/my-bar = $(git symbolic-ref HEAD) && | |
247 | git log refs/remotes/bar | grep "change 1" && | |
248 | ! git log refs/remotes/bar | grep "change 2" && | |
249 | git checkout master && | |
250 | git branch -D my-bar | |
251 | ' | |
252 | ||
d3a840dc | 253 | test_expect_success 'able to dcommit to a subdirectory' " |
1364ff27 | 254 | git svn fetch -i bar && |
d3a840dc EW |
255 | git checkout -b my-bar refs/remotes/bar && |
256 | echo abc > d && | |
257 | git update-index --add d && | |
258 | git commit -m '/bar/d should be in the log' && | |
1364ff27 | 259 | git svn dcommit -i bar && |
d3a840dc EW |
260 | test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" && |
261 | mkdir newdir && | |
262 | echo new > newdir/dir && | |
263 | git update-index --add newdir/dir && | |
264 | git commit -m 'add a new directory' && | |
1364ff27 | 265 | git svn dcommit -i bar && |
d3a840dc EW |
266 | test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" && |
267 | echo foo >> newdir/dir && | |
268 | git update-index newdir/dir && | |
269 | git commit -m 'modify a file in new directory' && | |
1364ff27 | 270 | git svn dcommit -i bar && |
d3a840dc EW |
271 | test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" |
272 | " | |
273 | ||
274 | test_expect_success 'able to set-tree to a subdirectory' " | |
275 | echo cba > d && | |
276 | git update-index d && | |
277 | git commit -m 'update /bar/d' && | |
1364ff27 | 278 | git svn set-tree -i bar HEAD && |
d3a840dc EW |
279 | test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" |
280 | " | |
281 | ||
6e5121f2 DM |
282 | test_expect_success 'git-svn works in a bare repository' ' |
283 | mkdir bare-repo && | |
284 | ( cd bare-repo && | |
285 | git init --bare && | |
286 | GIT_DIR=. git svn init "$svnrepo" && | |
287 | git svn fetch ) && | |
288 | rm -rf bare-repo | |
289 | ' | |
290 | ||
96a40b27 | 291 | test_done |