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