Sync with 2.38.4
[git.git] / t / t9100-git-svn-basic.sh
blobfea41b3c3606df1fc6d8111cdd74522532ca8b0b
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 . ./lib-git-svn.sh
13 prepare_utf8_locale
15 test_expect_success 'git svn --version works anywhere' '
16 nongit git svn --version
19 test_expect_success 'git svn help works anywhere' '
20 nongit git svn help
23 test_expect_success \
24 'initialize git svn' '
25 mkdir import &&
27 cd import &&
28 echo foo >foo &&
29 ln -s foo foo.link &&
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 &&
34 echo "#!/bin/sh" >exec.sh &&
35 chmod +x exec.sh &&
36 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
37 ) &&
38 rm -rf import &&
39 git svn init "$svnrepo"'
41 test_expect_success \
42 'import an SVN revision into git' \
43 'git svn fetch'
45 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
47 name='try a deep --rmdir with a commit'
48 test_expect_success "$name" '
49 git checkout -f -b mybranch remotes/git-svn &&
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 &&
53 git commit -m "$name" &&
54 git svn set-tree --find-copies-harder --rmdir \
55 remotes/git-svn..mybranch &&
56 svn_cmd up "$SVN_TREE" &&
57 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
60 name='detect node change from file to directory #1'
61 test_expect_success "$name" '
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 &&
67 git commit -m "$name" &&
68 test_must_fail git svn set-tree --find-copies-harder --rmdir \
69 remotes/git-svn..mybranch
73 name='detect node change from directory to file #1'
74 test_expect_success "$name" '
75 rm -rf dir "$GIT_DIR"/index &&
76 git checkout -f -b mybranch2 remotes/git-svn &&
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 &&
82 git commit -m "$name" &&
83 test_must_fail git svn set-tree --find-copies-harder --rmdir \
84 remotes/git-svn..mybranch2
88 name='detect node change from file to directory #2'
89 test_expect_success "$name" '
90 rm -f "$GIT_DIR"/index &&
91 git checkout -f -b mybranch3 remotes/git-svn &&
92 rm bar/zzz &&
93 git update-index --remove bar/zzz &&
94 mkdir bar/zzz &&
95 echo yyy > bar/zzz/yyy &&
96 git update-index --add bar/zzz/yyy &&
97 git commit -m "$name" &&
98 git svn set-tree --find-copies-harder --rmdir \
99 remotes/git-svn..mybranch3 &&
100 svn_cmd up "$SVN_TREE" &&
101 test -d "$SVN_TREE"/bar/zzz &&
102 test -e "$SVN_TREE"/bar/zzz/yyy
105 name='detect node change from directory to file #2'
106 test_expect_success "$name" '
107 rm -f "$GIT_DIR"/index &&
108 git checkout -f -b mybranch4 remotes/git-svn &&
109 rm -rf dir &&
110 git update-index --remove -- dir/file &&
111 touch dir &&
112 echo asdf > dir &&
113 git update-index --add -- dir &&
114 git commit -m "$name" &&
115 test_must_fail git svn set-tree --find-copies-harder --rmdir \
116 remotes/git-svn..mybranch4
120 name='remove executable bit from a file'
121 test_expect_success POSIXPERM "$name" '
122 rm -f "$GIT_DIR"/index &&
123 git checkout -f -b mybranch5 remotes/git-svn &&
124 chmod -x exec.sh &&
125 git update-index exec.sh &&
126 git commit -m "$name" &&
127 git svn set-tree --find-copies-harder --rmdir \
128 remotes/git-svn..mybranch5 &&
129 svn_cmd up "$SVN_TREE" &&
130 test ! -x "$SVN_TREE"/exec.sh'
133 name='add executable bit back file'
134 test_expect_success POSIXPERM "$name" '
135 chmod +x exec.sh &&
136 git update-index exec.sh &&
137 git commit -m "$name" &&
138 git svn set-tree --find-copies-harder --rmdir \
139 remotes/git-svn..mybranch5 &&
140 svn_cmd up "$SVN_TREE" &&
141 test -x "$SVN_TREE"/exec.sh'
144 name='executable file becomes a symlink to file'
145 test_expect_success SYMLINKS "$name" '
146 rm exec.sh &&
147 ln -s file exec.sh &&
148 git update-index exec.sh &&
149 git commit -m "$name" &&
150 git svn set-tree --find-copies-harder --rmdir \
151 remotes/git-svn..mybranch5 &&
152 svn_cmd up "$SVN_TREE" &&
153 test -h "$SVN_TREE"/exec.sh'
155 name='new symlink is added to a file that was also just made executable'
157 test_expect_success POSIXPERM,SYMLINKS "$name" '
158 chmod +x file &&
159 ln -s file exec-2.sh &&
160 git update-index --add file exec-2.sh &&
161 git commit -m "$name" &&
162 git svn set-tree --find-copies-harder --rmdir \
163 remotes/git-svn..mybranch5 &&
164 svn_cmd up "$SVN_TREE" &&
165 test -x "$SVN_TREE"/file &&
166 test -h "$SVN_TREE"/exec-2.sh'
168 name='modify a symlink to become a file'
169 test_expect_success POSIXPERM,SYMLINKS "$name" '
170 echo git help >help &&
171 rm exec-2.sh &&
172 cp help exec-2.sh &&
173 git update-index exec-2.sh &&
174 git commit -m "$name" &&
175 git svn set-tree --find-copies-harder --rmdir \
176 remotes/git-svn..mybranch5 &&
177 svn_cmd up "$SVN_TREE" &&
178 test -f "$SVN_TREE"/exec-2.sh &&
179 test ! -h "$SVN_TREE"/exec-2.sh &&
180 test_cmp help "$SVN_TREE"/exec-2.sh'
182 name="commit with UTF-8 message: locale: $GIT_TEST_UTF8_LOCALE"
183 LC_ALL="$GIT_TEST_UTF8_LOCALE"
184 export LC_ALL
185 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
186 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
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
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" \
197 'git svn init "$svnrepo" && git svn fetch &&
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 &&
201 test_cmp a b'
203 name='check imported tree checksums expected tree checksums'
204 rm -f expected
205 if test_have_prereq UTF8
206 then
207 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected.sha1
208 echo tree b95b55b29d771f5eb73aa9b9d52d02fe11a2538c2feb0829f754ce20a91d98eb > expected.sha256
210 cat >> expected.sha1 <<\EOF
211 tree c3322890dcf74901f32d216f05c5044f670ce632
212 tree d3ccd5035feafd17b030c5732e7808cc49122853
213 tree d03e1630363d4881e68929d532746b20b0986b83
214 tree 149d63cd5878155c846e8c55d7d8487de283f89e
215 tree 312b76e4f64ce14893aeac8591eb3960b065e247
216 tree 149d63cd5878155c846e8c55d7d8487de283f89e
217 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
218 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
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
231 test_expect_success POSIXPERM,SYMLINKS "$name" '
232 test_cmp expected.$(test_oid algo) a
235 test_expect_success 'exit if remote refs are ambigious' '
236 git config --add svn-remote.svn.fetch \
237 bar:refs/remotes/git-svn &&
238 test_must_fail git svn migrate
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" &&
244 git config --unset svn-remote.svn.fetch \
245 "^bar:refs/remotes/git-svn$" &&
246 test_must_fail git svn init "${svnrepo}2/bar"
249 test_expect_success \
250 'init allows us to connect to another directory in the same repo' '
251 git svn init --minimize-url -i bar "$svnrepo/bar" &&
252 git config --get svn-remote.svn.fetch \
253 "^bar:refs/remotes/bar$" &&
254 git config --get svn-remote.svn.fetch \
255 "^:refs/remotes/git-svn$"
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" &&
273 git checkout main &&
274 git branch -D my-bar
277 test_expect_success 'able to dcommit to a subdirectory' '
278 git svn fetch -i bar &&
279 git checkout -b my-bar refs/remotes/bar &&
280 echo abc > d &&
281 git update-index --add d &&
282 git commit -m "/bar/d should be in the log" &&
283 git svn dcommit -i bar &&
284 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
285 mkdir newdir &&
286 echo new > newdir/dir &&
287 git update-index --add newdir/dir &&
288 git commit -m "add a new directory" &&
289 git svn dcommit -i bar &&
290 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
291 echo foo >> newdir/dir &&
292 git update-index newdir/dir &&
293 git commit -m "modify a file in new directory" &&
294 git svn dcommit -i bar &&
295 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
298 test_expect_success 'dcommit should not fail with a touched file' '
299 test_commit "commit-new-file-foo2" foo2 &&
300 test-tool chmtime =-60 foo &&
301 git svn dcommit
304 test_expect_success 'rebase should not fail with a touched file' '
305 test-tool chmtime =-60 foo &&
306 git svn rebase
309 test_expect_success 'able to set-tree to a subdirectory' '
310 echo cba > d &&
311 git update-index d &&
312 git commit -m "update /bar/d" &&
313 git svn set-tree -i bar HEAD &&
314 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
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
325 test_expect_success 'git-svn works in a repository with a gitdir: link' '
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
334 test_done