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