]>
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 | ||
c0071ae5 EW |
22 | deepdir=nothing-above |
23 | ceiling=$PWD | |
24 | ||
25 | test_expect_success 'git svn --version works anywhere' ' | |
26 | mkdir -p "$deepdir" && ( | |
2a96d398 JH |
27 | GIT_CEILING_DIRECTORIES="$ceiling" && |
28 | export GIT_CEILING_DIRECTORIES && | |
c0071ae5 EW |
29 | cd "$deepdir" && |
30 | git svn --version | |
31 | ) | |
32 | ' | |
33 | ||
34 | test_expect_success 'git svn help works anywhere' ' | |
35 | mkdir -p "$deepdir" && ( | |
2a96d398 JH |
36 | GIT_CEILING_DIRECTORIES="$ceiling" && |
37 | export GIT_CEILING_DIRECTORIES && | |
c0071ae5 EW |
38 | cd "$deepdir" && |
39 | git svn help | |
40 | ) | |
41 | ' | |
42 | ||
96a40b27 | 43 | test_expect_success \ |
f964732c | 44 | 'initialize git svn' ' |
39ed7c18 | 45 | mkdir import && |
18a82692 JN |
46 | ( |
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 && | |
2605e959 MG |
54 | echo "#!/bin/sh" >exec.sh && |
55 | chmod +x exec.sh && | |
18a82692 | 56 | svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null |
fd4ec4f2 | 57 | ) && |
39ed7c18 | 58 | rm -rf import && |
1364ff27 | 59 | git svn init "$svnrepo"' |
96a40b27 EW |
60 | |
61 | test_expect_success \ | |
62 | 'import an SVN revision into git' \ | |
1364ff27 | 63 | 'git svn fetch' |
96a40b27 | 64 | |
f69e836f | 65 | test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"' |
96a40b27 EW |
66 | |
67 | name='try a deep --rmdir with a commit' | |
f69e836f | 68 | test_expect_success "$name" ' |
e1c0c158 | 69 | git checkout -f -b mybranch remotes/git-svn && |
39ed7c18 EW |
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 && | |
f69e836f | 73 | git commit -m "$name" && |
1364ff27 | 74 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 75 | remotes/git-svn..mybranch && |
da083d68 | 76 | svn_cmd up "$SVN_TREE" && |
f69e836f | 77 | test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a' |
96a40b27 EW |
78 | |
79 | ||
80 | name='detect node change from file to directory #1' | |
41ac414e | 81 | test_expect_success "$name" " |
39ed7c18 EW |
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 && | |
41ac414e | 87 | git commit -m '$name' && |
1364ff27 | 88 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 89 | remotes/git-svn..mybranch |
2ab5ca80 | 90 | " |
96a40b27 EW |
91 | |
92 | ||
93 | name='detect node change from directory to file #1' | |
f69e836f BD |
94 | test_expect_success "$name" ' |
95 | rm -rf dir "$GIT_DIR"/index && | |
e1c0c158 | 96 | git checkout -f -b mybranch2 remotes/git-svn && |
39ed7c18 EW |
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 && | |
f69e836f | 102 | git commit -m "$name" && |
1364ff27 | 103 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 104 | remotes/git-svn..mybranch2 |
2ab5ca80 | 105 | ' |
96a40b27 EW |
106 | |
107 | ||
108 | name='detect node change from file to directory #2' | |
f69e836f BD |
109 | test_expect_success "$name" ' |
110 | rm -f "$GIT_DIR"/index && | |
e1c0c158 | 111 | git checkout -f -b mybranch3 remotes/git-svn && |
39ed7c18 | 112 | rm bar/zzz && |
5be60078 | 113 | git update-index --remove bar/zzz && |
39ed7c18 EW |
114 | mkdir bar/zzz && |
115 | echo yyy > bar/zzz/yyy && | |
5be60078 | 116 | git update-index --add bar/zzz/yyy && |
f69e836f | 117 | git commit -m "$name" && |
379862ec | 118 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 119 | remotes/git-svn..mybranch3 && |
379862ec SW |
120 | svn_cmd up "$SVN_TREE" && |
121 | test -d "$SVN_TREE"/bar/zzz && | |
2ab5ca80 JH |
122 | test -e "$SVN_TREE"/bar/zzz/yyy |
123 | ' | |
96a40b27 EW |
124 | |
125 | name='detect node change from directory to file #2' | |
f69e836f BD |
126 | test_expect_success "$name" ' |
127 | rm -f "$GIT_DIR"/index && | |
e1c0c158 | 128 | git checkout -f -b mybranch4 remotes/git-svn && |
39ed7c18 EW |
129 | rm -rf dir && |
130 | git update-index --remove -- dir/file && | |
131 | touch dir && | |
132 | echo asdf > dir && | |
133 | git update-index --add -- dir && | |
f69e836f | 134 | git commit -m "$name" && |
1364ff27 | 135 | test_must_fail git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 136 | remotes/git-svn..mybranch4 |
2ab5ca80 | 137 | ' |
96a40b27 EW |
138 | |
139 | ||
140 | name='remove executable bit from a file' | |
bcb11f19 | 141 | test_expect_success POSIXPERM "$name" ' |
f69e836f | 142 | rm -f "$GIT_DIR"/index && |
e1c0c158 | 143 | git checkout -f -b mybranch5 remotes/git-svn && |
39ed7c18 EW |
144 | chmod -x exec.sh && |
145 | git update-index exec.sh && | |
f69e836f | 146 | git commit -m "$name" && |
1364ff27 | 147 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 148 | remotes/git-svn..mybranch5 && |
da083d68 | 149 | svn_cmd up "$SVN_TREE" && |
f69e836f | 150 | test ! -x "$SVN_TREE"/exec.sh' |
96a40b27 EW |
151 | |
152 | ||
153 | name='add executable bit back file' | |
bcb11f19 | 154 | test_expect_success POSIXPERM "$name" ' |
39ed7c18 EW |
155 | chmod +x exec.sh && |
156 | git update-index exec.sh && | |
f69e836f | 157 | git commit -m "$name" && |
1364ff27 | 158 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 159 | remotes/git-svn..mybranch5 && |
da083d68 | 160 | svn_cmd up "$SVN_TREE" && |
f69e836f | 161 | test -x "$SVN_TREE"/exec.sh' |
96a40b27 EW |
162 | |
163 | ||
379862ec | 164 | name='executable file becomes a symlink to file' |
bcb11f19 | 165 | test_expect_success SYMLINKS "$name" ' |
5bd3870c | 166 | rm exec.sh && |
379862ec | 167 | ln -s file exec.sh && |
5bd3870c | 168 | git update-index exec.sh && |
f69e836f | 169 | git commit -m "$name" && |
1364ff27 | 170 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 171 | remotes/git-svn..mybranch5 && |
da083d68 | 172 | svn_cmd up "$SVN_TREE" && |
afa08760 | 173 | test -h "$SVN_TREE"/exec.sh' |
0e8a002c | 174 | |
5bd3870c | 175 | name='new symlink is added to a file that was also just made executable' |
0e8a002c | 176 | |
bcb11f19 | 177 | test_expect_success POSIXPERM,SYMLINKS "$name" ' |
379862ec SW |
178 | chmod +x file && |
179 | ln -s file exec-2.sh && | |
180 | git update-index --add file exec-2.sh && | |
f69e836f | 181 | git commit -m "$name" && |
1364ff27 | 182 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 183 | remotes/git-svn..mybranch5 && |
da083d68 | 184 | svn_cmd up "$SVN_TREE" && |
379862ec | 185 | test -x "$SVN_TREE"/file && |
afa08760 | 186 | test -h "$SVN_TREE"/exec-2.sh' |
96a40b27 | 187 | |
5bd3870c | 188 | name='modify a symlink to become a file' |
bcb11f19 | 189 | test_expect_success POSIXPERM,SYMLINKS "$name" ' |
2ab5ca80 | 190 | echo git help >help && |
5bd3870c EW |
191 | rm exec-2.sh && |
192 | cp help exec-2.sh && | |
193 | git update-index exec-2.sh && | |
f69e836f | 194 | git commit -m "$name" && |
1364ff27 | 195 | git svn set-tree --find-copies-harder --rmdir \ |
e1c0c158 | 196 | remotes/git-svn..mybranch5 && |
da083d68 | 197 | svn_cmd up "$SVN_TREE" && |
f69e836f | 198 | test -f "$SVN_TREE"/exec-2.sh && |
afa08760 | 199 | test ! -h "$SVN_TREE"/exec-2.sh && |
3af82863 | 200 | test_cmp help "$SVN_TREE"/exec-2.sh' |
96a40b27 | 201 | |
7b7247b0 JS |
202 | name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL" |
203 | LC_ALL="$GIT_SVN_LC_ALL" | |
204 | export LC_ALL | |
bcb11f19 JS |
205 | # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS |
206 | test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" " | |
7b7247b0 JS |
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 | |
96a40b27 EW |
212 | |
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" \ | |
1364ff27 | 217 | 'git svn init "$svnrepo" && git svn fetch && |
e1c0c158 | 218 | git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a && |
5be60078 | 219 | git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b && |
3af82863 | 220 | test_cmp a b' |
96a40b27 | 221 | |
42d32870 | 222 | name='check imported tree checksums expected tree checksums' |
86f36379 | 223 | rm -f expected |
7b7247b0 | 224 | if test_have_prereq UTF8 |
86f36379 | 225 | then |
379862ec | 226 | echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected |
86f36379 EW |
227 | fi |
228 | cat >> expected <<\EOF | |
379862ec SW |
229 | tree c3322890dcf74901f32d216f05c5044f670ce632 |
230 | tree d3ccd5035feafd17b030c5732e7808cc49122853 | |
231 | tree d03e1630363d4881e68929d532746b20b0986b83 | |
232 | tree 149d63cd5878155c846e8c55d7d8487de283f89e | |
233 | tree 312b76e4f64ce14893aeac8591eb3960b065e247 | |
234 | tree 149d63cd5878155c846e8c55d7d8487de283f89e | |
42d32870 EW |
235 | tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e |
236 | tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 | |
237 | EOF | |
e1516119 | 238 | |
bcb11f19 | 239 | test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected" |
42d32870 | 240 | |
577dfd03 | 241 | test_expect_success 'exit if remote refs are ambigious' ' |
5be60078 | 242 | git config --add svn-remote.svn.fetch \ |
e1c0c158 | 243 | bar:refs/remotes/git-svn && |
1364ff27 | 244 | test_must_fail git svn migrate |
577dfd03 | 245 | ' |
e6434f87 | 246 | |
f69e836f BD |
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" && | |
5be60078 | 250 | git config --unset svn-remote.svn.fetch \ |
e1c0c158 | 251 | "^bar:refs/remotes/git-svn$" && |
1364ff27 | 252 | test_must_fail git svn init "${svnrepo}2/bar" |
f69e836f | 253 | ' |
e6434f87 EW |
254 | |
255 | test_expect_success \ | |
f69e836f | 256 | 'init allows us to connect to another directory in the same repo' ' |
1364ff27 | 257 | git svn init --minimize-url -i bar "$svnrepo/bar" && |
ccb6b6f5 | 258 | git config --get svn-remote.svn.fetch \ |
f69e836f | 259 | "^bar:refs/remotes/bar$" && |
ccb6b6f5 | 260 | git config --get svn-remote.svn.fetch \ |
e1c0c158 | 261 | "^:refs/remotes/git-svn$" |
f69e836f | 262 | ' |
b805b44a | 263 | |
5eec27e3 TR |
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 | |
281 | ' | |
282 | ||
577dfd03 | 283 | test_expect_success 'able to dcommit to a subdirectory' ' |
1364ff27 | 284 | git svn fetch -i bar && |
d3a840dc EW |
285 | git checkout -b my-bar refs/remotes/bar && |
286 | echo abc > d && | |
287 | git update-index --add d && | |
577dfd03 | 288 | git commit -m "/bar/d should be in the log" && |
1364ff27 | 289 | git svn dcommit -i bar && |
577dfd03 | 290 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" && |
d3a840dc EW |
291 | mkdir newdir && |
292 | echo new > newdir/dir && | |
293 | git update-index --add newdir/dir && | |
577dfd03 | 294 | git commit -m "add a new directory" && |
1364ff27 | 295 | git svn dcommit -i bar && |
577dfd03 | 296 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" && |
d3a840dc EW |
297 | echo foo >> newdir/dir && |
298 | git update-index newdir/dir && | |
577dfd03 | 299 | git commit -m "modify a file in new directory" && |
1364ff27 | 300 | git svn dcommit -i bar && |
577dfd03 JK |
301 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" |
302 | ' | |
d3a840dc | 303 | |
181264ad DK |
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 | |
308 | ' | |
309 | ||
310 | test_expect_success 'rebase should not fail with a touched file' ' | |
311 | test-chmtime =-60 foo && | |
312 | git svn rebase | |
313 | ' | |
314 | ||
577dfd03 | 315 | test_expect_success 'able to set-tree to a subdirectory' ' |
d3a840dc EW |
316 | echo cba > d && |
317 | git update-index d && | |
577dfd03 | 318 | git commit -m "update /bar/d" && |
1364ff27 | 319 | git svn set-tree -i bar HEAD && |
577dfd03 JK |
320 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" |
321 | ' | |
d3a840dc | 322 | |
6e5121f2 DM |
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 | |
330 | ' | |
bc93ceb7 BW |
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 | |
338 | ' | |
6e5121f2 | 339 | |
96a40b27 | 340 | test_done |