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