Sync with 2.36.6
[git/debian.git] / t / t9100-git-svn-basic.sh
blob7c5b847f58424dc62c330674971d2d849f77ac4e
1 #!/bin/sh
3 # Copyright (c) 2006 Eric Wong
6 test_description='git svn basic tests'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_FAILS_SANITIZE_LEAK=true
12 . ./lib-git-svn.sh
14 prepare_utf8_locale
16 test_expect_success 'git svn --version works anywhere' '
17 nongit git svn --version
20 test_expect_success 'git svn help works anywhere' '
21 nongit git svn help
24 test_expect_success \
25 'initialize git svn' '
26 mkdir import &&
28 cd import &&
29 echo foo >foo &&
30 ln -s foo foo.link &&
31 mkdir -p dir/a/b/c/d/e &&
32 echo "deep dir" >dir/a/b/c/d/e/file &&
33 mkdir bar &&
34 echo "zzz" >bar/zzz &&
35 echo "#!/bin/sh" >exec.sh &&
36 chmod +x exec.sh &&
37 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
38 ) &&
39 rm -rf import &&
40 git svn init "$svnrepo"'
42 test_expect_success \
43 'import an SVN revision into git' \
44 'git svn fetch'
46 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
48 name='try a deep --rmdir with a commit'
49 test_expect_success "$name" '
50 git checkout -f -b mybranch remotes/git-svn &&
51 mv dir/a/b/c/d/e/file dir/file &&
52 cp dir/file file &&
53 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
54 git commit -m "$name" &&
55 git svn set-tree --find-copies-harder --rmdir \
56 remotes/git-svn..mybranch &&
57 svn_cmd up "$SVN_TREE" &&
58 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
61 name='detect node change from file to directory #1'
62 test_expect_success "$name" '
63 mkdir dir/new_file &&
64 mv dir/file dir/new_file/file &&
65 mv dir/new_file dir/file &&
66 git update-index --remove dir/file &&
67 git update-index --add dir/file/file &&
68 git commit -m "$name" &&
69 test_must_fail git svn set-tree --find-copies-harder --rmdir \
70 remotes/git-svn..mybranch
74 name='detect node change from directory to file #1'
75 test_expect_success "$name" '
76 rm -rf dir "$GIT_DIR"/index &&
77 git checkout -f -b mybranch2 remotes/git-svn &&
78 mv bar/zzz zzz &&
79 rm -rf bar &&
80 mv zzz bar &&
81 git update-index --remove -- bar/zzz &&
82 git update-index --add -- bar &&
83 git commit -m "$name" &&
84 test_must_fail git svn set-tree --find-copies-harder --rmdir \
85 remotes/git-svn..mybranch2
89 name='detect node change from file to directory #2'
90 test_expect_success "$name" '
91 rm -f "$GIT_DIR"/index &&
92 git checkout -f -b mybranch3 remotes/git-svn &&
93 rm bar/zzz &&
94 git update-index --remove bar/zzz &&
95 mkdir bar/zzz &&
96 echo yyy > bar/zzz/yyy &&
97 git update-index --add bar/zzz/yyy &&
98 git commit -m "$name" &&
99 git svn set-tree --find-copies-harder --rmdir \
100 remotes/git-svn..mybranch3 &&
101 svn_cmd up "$SVN_TREE" &&
102 test -d "$SVN_TREE"/bar/zzz &&
103 test -e "$SVN_TREE"/bar/zzz/yyy
106 name='detect node change from directory to file #2'
107 test_expect_success "$name" '
108 rm -f "$GIT_DIR"/index &&
109 git checkout -f -b mybranch4 remotes/git-svn &&
110 rm -rf dir &&
111 git update-index --remove -- dir/file &&
112 touch dir &&
113 echo asdf > dir &&
114 git update-index --add -- dir &&
115 git commit -m "$name" &&
116 test_must_fail git svn set-tree --find-copies-harder --rmdir \
117 remotes/git-svn..mybranch4
121 name='remove executable bit from a file'
122 test_expect_success POSIXPERM "$name" '
123 rm -f "$GIT_DIR"/index &&
124 git checkout -f -b mybranch5 remotes/git-svn &&
125 chmod -x exec.sh &&
126 git update-index exec.sh &&
127 git commit -m "$name" &&
128 git svn set-tree --find-copies-harder --rmdir \
129 remotes/git-svn..mybranch5 &&
130 svn_cmd up "$SVN_TREE" &&
131 test ! -x "$SVN_TREE"/exec.sh'
134 name='add executable bit back file'
135 test_expect_success POSIXPERM "$name" '
136 chmod +x exec.sh &&
137 git update-index exec.sh &&
138 git commit -m "$name" &&
139 git svn set-tree --find-copies-harder --rmdir \
140 remotes/git-svn..mybranch5 &&
141 svn_cmd up "$SVN_TREE" &&
142 test -x "$SVN_TREE"/exec.sh'
145 name='executable file becomes a symlink to file'
146 test_expect_success SYMLINKS "$name" '
147 rm exec.sh &&
148 ln -s file exec.sh &&
149 git update-index exec.sh &&
150 git commit -m "$name" &&
151 git svn set-tree --find-copies-harder --rmdir \
152 remotes/git-svn..mybranch5 &&
153 svn_cmd up "$SVN_TREE" &&
154 test -h "$SVN_TREE"/exec.sh'
156 name='new symlink is added to a file that was also just made executable'
158 test_expect_success POSIXPERM,SYMLINKS "$name" '
159 chmod +x file &&
160 ln -s file exec-2.sh &&
161 git update-index --add file exec-2.sh &&
162 git commit -m "$name" &&
163 git svn set-tree --find-copies-harder --rmdir \
164 remotes/git-svn..mybranch5 &&
165 svn_cmd up "$SVN_TREE" &&
166 test -x "$SVN_TREE"/file &&
167 test -h "$SVN_TREE"/exec-2.sh'
169 name='modify a symlink to become a file'
170 test_expect_success POSIXPERM,SYMLINKS "$name" '
171 echo git help >help &&
172 rm exec-2.sh &&
173 cp help exec-2.sh &&
174 git update-index exec-2.sh &&
175 git commit -m "$name" &&
176 git svn set-tree --find-copies-harder --rmdir \
177 remotes/git-svn..mybranch5 &&
178 svn_cmd up "$SVN_TREE" &&
179 test -f "$SVN_TREE"/exec-2.sh &&
180 test ! -h "$SVN_TREE"/exec-2.sh &&
181 test_cmp help "$SVN_TREE"/exec-2.sh'
183 name="commit with UTF-8 message: locale: $GIT_TEST_UTF8_LOCALE"
184 LC_ALL="$GIT_TEST_UTF8_LOCALE"
185 export LC_ALL
186 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
187 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
188 echo '# hello' >> exec-2.sh &&
189 git update-index exec-2.sh &&
190 git commit -m 'éï∏' &&
191 git svn set-tree HEAD"
192 unset LC_ALL
194 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
195 GIT_SVN_ID=alt
196 export GIT_SVN_ID
197 test_expect_success "$name" \
198 'git svn init "$svnrepo" && git svn fetch &&
199 git log --format="tree %T %s" remotes/git-svn |
200 awk "!seen[\$0]++ { print \$1, \$2 }" >a &&
201 git log --format="tree %T" alt >b &&
202 test_cmp a b'
204 name='check imported tree checksums expected tree checksums'
205 rm -f expected
206 if test_have_prereq UTF8
207 then
208 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected.sha1
209 echo tree b95b55b29d771f5eb73aa9b9d52d02fe11a2538c2feb0829f754ce20a91d98eb > expected.sha256
211 cat >> expected.sha1 <<\EOF
212 tree c3322890dcf74901f32d216f05c5044f670ce632
213 tree d3ccd5035feafd17b030c5732e7808cc49122853
214 tree d03e1630363d4881e68929d532746b20b0986b83
215 tree 149d63cd5878155c846e8c55d7d8487de283f89e
216 tree 312b76e4f64ce14893aeac8591eb3960b065e247
217 tree 149d63cd5878155c846e8c55d7d8487de283f89e
218 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
219 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
221 cat >> expected.sha256 <<\EOF
222 tree 8d12756699d0b5b110514240a0ff141f6cbf8891fd69ab05e5594196fb437c9f
223 tree 8187168d33f7d4ccb8c1cc6e99532810aaccb47658f35d19b3803072d1128d7a
224 tree 74e535d85da8ee25eb23d7b506790c5ab3ccdb1ba0826bd57625ed44ef361650
225 tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95
226 tree 1fd6cec6aa95102d69266e20419bb62ec2a06372d614b9850ef23ff204103bb4
227 tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95
228 tree deb2b7ac79cd8ce6f52af6a5a0a08691e94ba74a2ed55966bb27dbec551730eb
229 tree 59e2e936761188476a7752034e8aa0a822b34050c8504b0dfd946407f4bc9215
232 test_expect_success POSIXPERM,SYMLINKS "$name" '
233 test_cmp expected.$(test_oid algo) a
236 test_expect_success 'exit if remote refs are ambigious' '
237 git config --add svn-remote.svn.fetch \
238 bar:refs/remotes/git-svn &&
239 test_must_fail git svn migrate
242 test_expect_success 'exit if init-ing a would clobber a URL' '
243 svnadmin create "${PWD}/svnrepo2" &&
244 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
245 git config --unset svn-remote.svn.fetch \
246 "^bar:refs/remotes/git-svn$" &&
247 test_must_fail git svn init "${svnrepo}2/bar"
250 test_expect_success \
251 'init allows us to connect to another directory in the same repo' '
252 git svn init --minimize-url -i bar "$svnrepo/bar" &&
253 git config --get svn-remote.svn.fetch \
254 "^bar:refs/remotes/bar$" &&
255 git config --get svn-remote.svn.fetch \
256 "^:refs/remotes/git-svn$"
259 test_expect_success 'dcommit $rev does not clobber current branch' '
260 git svn fetch -i bar &&
261 git checkout -b my-bar refs/remotes/bar &&
262 echo 1 > foo &&
263 git add foo &&
264 git commit -m "change 1" &&
265 echo 2 > foo &&
266 git add foo &&
267 git commit -m "change 2" &&
268 old_head=$(git rev-parse HEAD) &&
269 git svn dcommit -i bar HEAD^ &&
270 test $old_head = $(git rev-parse HEAD) &&
271 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
272 git log refs/remotes/bar | grep "change 1" &&
273 ! git log refs/remotes/bar | grep "change 2" &&
274 git checkout main &&
275 git branch -D my-bar
278 test_expect_success 'able to dcommit to a subdirectory' '
279 git svn fetch -i bar &&
280 git checkout -b my-bar refs/remotes/bar &&
281 echo abc > d &&
282 git update-index --add d &&
283 git commit -m "/bar/d should be in the log" &&
284 git svn dcommit -i bar &&
285 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
286 mkdir newdir &&
287 echo new > newdir/dir &&
288 git update-index --add newdir/dir &&
289 git commit -m "add a new directory" &&
290 git svn dcommit -i bar &&
291 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
292 echo foo >> newdir/dir &&
293 git update-index newdir/dir &&
294 git commit -m "modify a file in new directory" &&
295 git svn dcommit -i bar &&
296 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
299 test_expect_success 'dcommit should not fail with a touched file' '
300 test_commit "commit-new-file-foo2" foo2 &&
301 test-tool chmtime =-60 foo &&
302 git svn dcommit
305 test_expect_success 'rebase should not fail with a touched file' '
306 test-tool chmtime =-60 foo &&
307 git svn rebase
310 test_expect_success 'able to set-tree to a subdirectory' '
311 echo cba > d &&
312 git update-index d &&
313 git commit -m "update /bar/d" &&
314 git svn set-tree -i bar HEAD &&
315 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
318 test_expect_success 'git-svn works in a bare repository' '
319 mkdir bare-repo &&
320 ( cd bare-repo &&
321 git init --bare &&
322 GIT_DIR=. git svn init "$svnrepo" &&
323 git svn fetch ) &&
324 rm -rf bare-repo
326 test_expect_success 'git-svn works in a repository with a gitdir: link' '
327 mkdir worktree gitdir &&
328 ( cd worktree &&
329 git svn init "$svnrepo" &&
330 git init --separate-git-dir ../gitdir &&
331 git svn fetch ) &&
332 rm -rf worktree gitdir
335 test_done