]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # Copyright (c) 2006 Eric Wong | |
4 | # | |
5 | ||
6 | test_description='git svn basic tests' | |
7 | ||
8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
10 | ||
11 | . ./lib-git-svn.sh | |
12 | ||
13 | prepare_utf8_locale | |
14 | ||
15 | test_expect_success 'git svn --version works anywhere' ' | |
16 | nongit git svn --version | |
17 | ' | |
18 | ||
19 | test_expect_success 'git svn help works anywhere' ' | |
20 | nongit git svn help | |
21 | ' | |
22 | ||
23 | test_expect_success \ | |
24 | 'initialize git svn' ' | |
25 | mkdir import && | |
26 | ( | |
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"' | |
40 | ||
41 | test_expect_success 'import an SVN revision into git' ' | |
42 | git svn fetch | |
43 | ' | |
44 | ||
45 | test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"' | |
46 | ||
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' | |
58 | ||
59 | ||
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 | |
70 | ' | |
71 | ||
72 | ||
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 | |
85 | ' | |
86 | ||
87 | ||
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 | |
103 | ' | |
104 | ||
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 | |
117 | ' | |
118 | ||
119 | ||
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' | |
131 | ||
132 | ||
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' | |
142 | ||
143 | ||
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' | |
154 | ||
155 | name='new symlink is added to a file that was also just made executable' | |
156 | ||
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' | |
167 | ||
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' | |
181 | ||
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 | |
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" \ | |
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' | |
202 | ||
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 | |
209 | fi | |
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 | |
219 | EOF | |
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 | |
230 | ||
231 | test_expect_success POSIXPERM,SYMLINKS "$name" ' | |
232 | test_cmp expected.$(test_oid algo) a | |
233 | ' | |
234 | ||
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 | |
239 | ' | |
240 | ||
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" | |
247 | ' | |
248 | ||
249 | test_expect_success 'init allows us to connect to another directory in the same repo' ' | |
250 | git svn init --minimize-url -i bar "$svnrepo/bar" && | |
251 | git config --get svn-remote.svn.fetch \ | |
252 | "^bar:refs/remotes/bar$" && | |
253 | git config --get svn-remote.svn.fetch \ | |
254 | "^:refs/remotes/git-svn$" | |
255 | ' | |
256 | ||
257 | test_expect_success 'dcommit $rev does not clobber current branch' ' | |
258 | git svn fetch -i bar && | |
259 | git checkout -b my-bar refs/remotes/bar && | |
260 | echo 1 > foo && | |
261 | git add foo && | |
262 | git commit -m "change 1" && | |
263 | echo 2 > foo && | |
264 | git add foo && | |
265 | git commit -m "change 2" && | |
266 | old_head=$(git rev-parse HEAD) && | |
267 | git svn dcommit -i bar HEAD^ && | |
268 | test $old_head = $(git rev-parse HEAD) && | |
269 | test refs/heads/my-bar = $(git symbolic-ref HEAD) && | |
270 | git log refs/remotes/bar | grep "change 1" && | |
271 | ! git log refs/remotes/bar | grep "change 2" && | |
272 | git checkout main && | |
273 | git branch -D my-bar | |
274 | ' | |
275 | ||
276 | test_expect_success 'able to dcommit to a subdirectory' ' | |
277 | git svn fetch -i bar && | |
278 | git checkout -b my-bar refs/remotes/bar && | |
279 | echo abc > d && | |
280 | git update-index --add d && | |
281 | git commit -m "/bar/d should be in the log" && | |
282 | git svn dcommit -i bar && | |
283 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" && | |
284 | mkdir newdir && | |
285 | echo new > newdir/dir && | |
286 | git update-index --add newdir/dir && | |
287 | git commit -m "add a new directory" && | |
288 | git svn dcommit -i bar && | |
289 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" && | |
290 | echo foo >> newdir/dir && | |
291 | git update-index newdir/dir && | |
292 | git commit -m "modify a file in new directory" && | |
293 | git svn dcommit -i bar && | |
294 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" | |
295 | ' | |
296 | ||
297 | test_expect_success 'dcommit should not fail with a touched file' ' | |
298 | test_commit "commit-new-file-foo2" foo2 && | |
299 | test-tool chmtime =-60 foo && | |
300 | git svn dcommit | |
301 | ' | |
302 | ||
303 | test_expect_success 'rebase should not fail with a touched file' ' | |
304 | test-tool chmtime =-60 foo && | |
305 | git svn rebase | |
306 | ' | |
307 | ||
308 | test_expect_success 'able to set-tree to a subdirectory' ' | |
309 | echo cba > d && | |
310 | git update-index d && | |
311 | git commit -m "update /bar/d" && | |
312 | git svn set-tree -i bar HEAD && | |
313 | test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" | |
314 | ' | |
315 | ||
316 | test_expect_success 'git-svn works in a bare repository' ' | |
317 | mkdir bare-repo && | |
318 | ( cd bare-repo && | |
319 | git init --bare && | |
320 | GIT_DIR=. git svn init "$svnrepo" && | |
321 | git svn fetch ) && | |
322 | rm -rf bare-repo | |
323 | ' | |
324 | test_expect_success 'git-svn works in a repository with a gitdir: link' ' | |
325 | mkdir worktree gitdir && | |
326 | ( cd worktree && | |
327 | git svn init "$svnrepo" && | |
328 | git init --separate-git-dir ../gitdir && | |
329 | git svn fetch ) && | |
330 | rm -rf worktree gitdir | |
331 | ' | |
332 | ||
333 | test_done |