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