use QSORT, part 2
[git/git-svn.git] / t / t9100-git-svn-basic.sh
blob92a3aa8063f810bd2b8df68f3f0f30c2faf3bdc6
1 #!/bin/sh
3 # Copyright (c) 2006 Eric Wong
6 test_description='git svn basic tests'
7 GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
9 . ./lib-git-svn.sh
11 case "$GIT_SVN_LC_ALL" in
12 *.UTF-8)
13 test_set_prereq UTF8
16 say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
18 esac
20 deepdir=nothing-above
21 ceiling=$PWD
23 test_expect_success 'git svn --version works anywhere' '
24 mkdir -p "$deepdir" && (
25 GIT_CEILING_DIRECTORIES="$ceiling" &&
26 export GIT_CEILING_DIRECTORIES &&
27 cd "$deepdir" &&
28 git svn --version
32 test_expect_success 'git svn help works anywhere' '
33 mkdir -p "$deepdir" && (
34 GIT_CEILING_DIRECTORIES="$ceiling" &&
35 export GIT_CEILING_DIRECTORIES &&
36 cd "$deepdir" &&
37 git svn help
41 test_expect_success \
42 'initialize git svn' '
43 mkdir import &&
45 cd import &&
46 echo foo >foo &&
47 ln -s foo foo.link
48 mkdir -p dir/a/b/c/d/e &&
49 echo "deep dir" >dir/a/b/c/d/e/file &&
50 mkdir bar &&
51 echo "zzz" >bar/zzz &&
52 echo "#!/bin/sh" >exec.sh &&
53 chmod +x exec.sh &&
54 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
55 ) &&
56 rm -rf import &&
57 git svn init "$svnrepo"'
59 test_expect_success \
60 'import an SVN revision into git' \
61 'git svn fetch'
63 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
65 name='try a deep --rmdir with a commit'
66 test_expect_success "$name" '
67 git checkout -f -b mybranch remotes/git-svn &&
68 mv dir/a/b/c/d/e/file dir/file &&
69 cp dir/file file &&
70 git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
71 git commit -m "$name" &&
72 git svn set-tree --find-copies-harder --rmdir \
73 remotes/git-svn..mybranch &&
74 svn_cmd up "$SVN_TREE" &&
75 test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
78 name='detect node change from file to directory #1'
79 test_expect_success "$name" "
80 mkdir dir/new_file &&
81 mv dir/file dir/new_file/file &&
82 mv dir/new_file dir/file &&
83 git update-index --remove dir/file &&
84 git update-index --add dir/file/file &&
85 git commit -m '$name' &&
86 test_must_fail git svn set-tree --find-copies-harder --rmdir \
87 remotes/git-svn..mybranch
91 name='detect node change from directory to file #1'
92 test_expect_success "$name" '
93 rm -rf dir "$GIT_DIR"/index &&
94 git checkout -f -b mybranch2 remotes/git-svn &&
95 mv bar/zzz zzz &&
96 rm -rf bar &&
97 mv zzz bar &&
98 git update-index --remove -- bar/zzz &&
99 git update-index --add -- bar &&
100 git commit -m "$name" &&
101 test_must_fail git svn set-tree --find-copies-harder --rmdir \
102 remotes/git-svn..mybranch2
106 name='detect node change from file to directory #2'
107 test_expect_success "$name" '
108 rm -f "$GIT_DIR"/index &&
109 git checkout -f -b mybranch3 remotes/git-svn &&
110 rm bar/zzz &&
111 git update-index --remove bar/zzz &&
112 mkdir bar/zzz &&
113 echo yyy > bar/zzz/yyy &&
114 git update-index --add bar/zzz/yyy &&
115 git commit -m "$name" &&
116 git svn set-tree --find-copies-harder --rmdir \
117 remotes/git-svn..mybranch3 &&
118 svn_cmd up "$SVN_TREE" &&
119 test -d "$SVN_TREE"/bar/zzz &&
120 test -e "$SVN_TREE"/bar/zzz/yyy
123 name='detect node change from directory to file #2'
124 test_expect_success "$name" '
125 rm -f "$GIT_DIR"/index &&
126 git checkout -f -b mybranch4 remotes/git-svn &&
127 rm -rf dir &&
128 git update-index --remove -- dir/file &&
129 touch dir &&
130 echo asdf > dir &&
131 git update-index --add -- dir &&
132 git commit -m "$name" &&
133 test_must_fail git svn set-tree --find-copies-harder --rmdir \
134 remotes/git-svn..mybranch4
138 name='remove executable bit from a file'
139 test_expect_success POSIXPERM "$name" '
140 rm -f "$GIT_DIR"/index &&
141 git checkout -f -b mybranch5 remotes/git-svn &&
142 chmod -x exec.sh &&
143 git update-index exec.sh &&
144 git commit -m "$name" &&
145 git svn set-tree --find-copies-harder --rmdir \
146 remotes/git-svn..mybranch5 &&
147 svn_cmd up "$SVN_TREE" &&
148 test ! -x "$SVN_TREE"/exec.sh'
151 name='add executable bit back file'
152 test_expect_success POSIXPERM "$name" '
153 chmod +x exec.sh &&
154 git update-index exec.sh &&
155 git commit -m "$name" &&
156 git svn set-tree --find-copies-harder --rmdir \
157 remotes/git-svn..mybranch5 &&
158 svn_cmd up "$SVN_TREE" &&
159 test -x "$SVN_TREE"/exec.sh'
162 name='executable file becomes a symlink to file'
163 test_expect_success SYMLINKS "$name" '
164 rm exec.sh &&
165 ln -s file exec.sh &&
166 git update-index exec.sh &&
167 git commit -m "$name" &&
168 git svn set-tree --find-copies-harder --rmdir \
169 remotes/git-svn..mybranch5 &&
170 svn_cmd up "$SVN_TREE" &&
171 test -h "$SVN_TREE"/exec.sh'
173 name='new symlink is added to a file that was also just made executable'
175 test_expect_success POSIXPERM,SYMLINKS "$name" '
176 chmod +x file &&
177 ln -s file exec-2.sh &&
178 git update-index --add file exec-2.sh &&
179 git commit -m "$name" &&
180 git svn set-tree --find-copies-harder --rmdir \
181 remotes/git-svn..mybranch5 &&
182 svn_cmd up "$SVN_TREE" &&
183 test -x "$SVN_TREE"/file &&
184 test -h "$SVN_TREE"/exec-2.sh'
186 name='modify a symlink to become a file'
187 test_expect_success POSIXPERM,SYMLINKS "$name" '
188 echo git help >help &&
189 rm exec-2.sh &&
190 cp help exec-2.sh &&
191 git update-index exec-2.sh &&
192 git commit -m "$name" &&
193 git svn set-tree --find-copies-harder --rmdir \
194 remotes/git-svn..mybranch5 &&
195 svn_cmd up "$SVN_TREE" &&
196 test -f "$SVN_TREE"/exec-2.sh &&
197 test ! -h "$SVN_TREE"/exec-2.sh &&
198 test_cmp help "$SVN_TREE"/exec-2.sh'
200 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
201 LC_ALL="$GIT_SVN_LC_ALL"
202 export LC_ALL
203 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
204 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
205 echo '# hello' >> exec-2.sh &&
206 git update-index exec-2.sh &&
207 git commit -m 'éï∏' &&
208 git svn set-tree HEAD"
209 unset LC_ALL
211 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
212 GIT_SVN_ID=alt
213 export GIT_SVN_ID
214 test_expect_success "$name" \
215 'git svn init "$svnrepo" && git svn fetch &&
216 git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
217 git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
218 test_cmp a b'
220 name='check imported tree checksums expected tree checksums'
221 rm -f expected
222 if test_have_prereq UTF8
223 then
224 echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
226 cat >> expected <<\EOF
227 tree c3322890dcf74901f32d216f05c5044f670ce632
228 tree d3ccd5035feafd17b030c5732e7808cc49122853
229 tree d03e1630363d4881e68929d532746b20b0986b83
230 tree 149d63cd5878155c846e8c55d7d8487de283f89e
231 tree 312b76e4f64ce14893aeac8591eb3960b065e247
232 tree 149d63cd5878155c846e8c55d7d8487de283f89e
233 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
234 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
237 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected"
239 test_expect_success 'exit if remote refs are ambigious' '
240 git config --add svn-remote.svn.fetch \
241 bar:refs/remotes/git-svn &&
242 test_must_fail git svn migrate
245 test_expect_success 'exit if init-ing a would clobber a URL' '
246 svnadmin create "${PWD}/svnrepo2" &&
247 svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
248 git config --unset svn-remote.svn.fetch \
249 "^bar:refs/remotes/git-svn$" &&
250 test_must_fail git svn init "${svnrepo}2/bar"
253 test_expect_success \
254 'init allows us to connect to another directory in the same repo' '
255 git svn init --minimize-url -i bar "$svnrepo/bar" &&
256 git config --get svn-remote.svn.fetch \
257 "^bar:refs/remotes/bar$" &&
258 git config --get svn-remote.svn.fetch \
259 "^:refs/remotes/git-svn$"
262 test_expect_success 'dcommit $rev does not clobber current branch' '
263 git svn fetch -i bar &&
264 git checkout -b my-bar refs/remotes/bar &&
265 echo 1 > foo &&
266 git add foo &&
267 git commit -m "change 1" &&
268 echo 2 > foo &&
269 git add foo &&
270 git commit -m "change 2" &&
271 old_head=$(git rev-parse HEAD) &&
272 git svn dcommit -i bar HEAD^ &&
273 test $old_head = $(git rev-parse HEAD) &&
274 test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
275 git log refs/remotes/bar | grep "change 1" &&
276 ! git log refs/remotes/bar | grep "change 2" &&
277 git checkout master &&
278 git branch -D my-bar
281 test_expect_success 'able to dcommit to a subdirectory' '
282 git svn fetch -i bar &&
283 git checkout -b my-bar refs/remotes/bar &&
284 echo abc > d &&
285 git update-index --add d &&
286 git commit -m "/bar/d should be in the log" &&
287 git svn dcommit -i bar &&
288 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
289 mkdir newdir &&
290 echo new > newdir/dir &&
291 git update-index --add newdir/dir &&
292 git commit -m "add a new directory" &&
293 git svn dcommit -i bar &&
294 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
295 echo foo >> newdir/dir &&
296 git update-index newdir/dir &&
297 git commit -m "modify a file in new directory" &&
298 git svn dcommit -i bar &&
299 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
302 test_expect_success 'dcommit should not fail with a touched file' '
303 test_commit "commit-new-file-foo2" foo2 &&
304 test-chmtime =-60 foo &&
305 git svn dcommit
308 test_expect_success 'rebase should not fail with a touched file' '
309 test-chmtime =-60 foo &&
310 git svn rebase
313 test_expect_success 'able to set-tree to a subdirectory' '
314 echo cba > d &&
315 git update-index d &&
316 git commit -m "update /bar/d" &&
317 git svn set-tree -i bar HEAD &&
318 test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
321 test_expect_success 'git-svn works in a bare repository' '
322 mkdir bare-repo &&
323 ( cd bare-repo &&
324 git init --bare &&
325 GIT_DIR=. git svn init "$svnrepo" &&
326 git svn fetch ) &&
327 rm -rf bare-repo
329 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
330 mkdir worktree gitdir &&
331 ( cd worktree &&
332 git svn init "$svnrepo" &&
333 git init --separate-git-dir ../gitdir &&
334 git svn fetch ) &&
335 rm -rf worktree gitdir
338 test_done