1#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
6test_description='git-svn basic tests'
7GIT_SVN_LC_ALL=$LC_ALL
8
9case "$LC_ALL" in
10*.UTF-8)
11 have_utf8=t
12 ;;
13*)
14 have_utf8=
15 ;;
16esac
17
18. ./lib-git-svn.sh
19
20echo 'define NO_SVN_TESTS to skip git-svn tests'
21
22test_expect_success \
23 'initialize git-svn' "
24 mkdir import &&
25 cd import &&
26 echo foo > foo &&
27 if test -z '$NO_SYMLINK'
28 then
29 ln -s foo foo.link
30 fi
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 import -m 'import for git-svn' . $svnrepo >/dev/null &&
38 cd .. &&
39 rm -rf import &&
40 git-svn init $svnrepo"
41
42test_expect_success \
43 'import an SVN revision into git' \
44 'git-svn fetch'
45
46test_expect_success "checkout from svn" "svn co $svnrepo '$SVN_TREE'"
47
48name='try a deep --rmdir with a commit'
49test_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 up '$SVN_TREE' &&
58 test -d '$SVN_TREE'/dir && test ! -d '$SVN_TREE'/dir/a"
59
60
61name='detect node change from file to directory #1'
62test_expect_failure "$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 git-svn set-tree --find-copies-harder --rmdir \
70 remotes/git-svn..mybranch" || true
71
72
73name='detect node change from directory to file #1'
74test_expect_failure "$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 git-svn set-tree --find-copies-harder --rmdir \
84 remotes/git-svn..mybranch2" || true
85
86
87name='detect node change from file to directory #2'
88test_expect_failure "$name" "
89 rm -f '$GIT_DIR'/index &&
90 git checkout -f -b mybranch3 remotes/git-svn &&
91 rm bar/zzz &&
92 git-update-index --remove bar/zzz &&
93 mkdir bar/zzz &&
94 echo yyy > bar/zzz/yyy &&
95 git-update-index --add bar/zzz/yyy &&
96 git commit -m '$name' &&
97 git-svn set-tree --find-copies-harder --rmdir \
98 remotes/git-svn..mybranch3" || true
99
100
101name='detect node change from directory to file #2'
102test_expect_failure "$name" "
103 rm -f '$GIT_DIR'/index &&
104 git checkout -f -b mybranch4 remotes/git-svn &&
105 rm -rf dir &&
106 git update-index --remove -- dir/file &&
107 touch dir &&
108 echo asdf > dir &&
109 git update-index --add -- dir &&
110 git commit -m '$name' &&
111 git-svn set-tree --find-copies-harder --rmdir \
112 remotes/git-svn..mybranch4" || true
113
114
115name='remove executable bit from a file'
116test_expect_success "$name" "
117 rm -f '$GIT_DIR'/index &&
118 git checkout -f -b mybranch5 remotes/git-svn &&
119 chmod -x exec.sh &&
120 git update-index exec.sh &&
121 git commit -m '$name' &&
122 git-svn set-tree --find-copies-harder --rmdir \
123 remotes/git-svn..mybranch5 &&
124 svn up '$SVN_TREE' &&
125 test ! -x '$SVN_TREE'/exec.sh"
126
127
128name='add executable bit back file'
129test_expect_success "$name" "
130 chmod +x exec.sh &&
131 git update-index exec.sh &&
132 git commit -m '$name' &&
133 git-svn set-tree --find-copies-harder --rmdir \
134 remotes/git-svn..mybranch5 &&
135 svn up '$SVN_TREE' &&
136 test -x '$SVN_TREE'/exec.sh"
137
138
139if test -z "$NO_SYMLINK"
140then
141 name='executable file becomes a symlink to bar/zzz (file)'
142
143 test_expect_success "$name" "
144 rm exec.sh &&
145 ln -s bar/zzz exec.sh &&
146 git update-index exec.sh &&
147 git commit -m '$name' &&
148 git-svn set-tree --find-copies-harder --rmdir \
149 remotes/git-svn..mybranch5 &&
150 svn up '$SVN_TREE' &&
151 test -L '$SVN_TREE'/exec.sh"
152
153 name='new symlink is added to a file that was also just made executable'
154
155 test_expect_success "$name" "
156 chmod +x bar/zzz &&
157 ln -s bar/zzz exec-2.sh &&
158 git update-index --add bar/zzz exec-2.sh &&
159 git commit -m '$name' &&
160 git-svn set-tree --find-copies-harder --rmdir \
161 remotes/git-svn..mybranch5 &&
162 svn up '$SVN_TREE' &&
163 test -x '$SVN_TREE'/bar/zzz &&
164 test -L '$SVN_TREE'/exec-2.sh"
165
166 name='modify a symlink to become a file'
167 test_expect_success "$name" "
168 echo git help > help || true &&
169 rm exec-2.sh &&
170 cp help exec-2.sh &&
171 git update-index exec-2.sh &&
172 git commit -m '$name' &&
173 git-svn set-tree --find-copies-harder --rmdir \
174 remotes/git-svn..mybranch5 &&
175 svn up '$SVN_TREE' &&
176 test -f '$SVN_TREE'/exec-2.sh &&
177 test ! -L '$SVN_TREE'/exec-2.sh &&
178 diff -u help $SVN_TREE/exec-2.sh"
179fi
180
181
182if test "$have_utf8" = t
183then
184 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
185 LC_ALL="$GIT_SVN_LC_ALL"
186 export LC_ALL
187 test_expect_success "$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
193else
194 echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
195fi
196
197name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
198GIT_SVN_ID=alt
199export GIT_SVN_ID
200test_expect_success "$name" \
201 "git-svn init $svnrepo && git-svn fetch &&
202 git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
203 git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
204 diff -u a b"
205
206if test -n "$NO_SYMLINK"
207then
208 test_done
209 exit 0
210fi
211
212name='check imported tree checksums expected tree checksums'
213rm -f expected
214if test "$have_utf8" = t
215then
216 echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected
217fi
218cat >> expected <<\EOF
219tree 83654bb36f019ae4fe77a0171f81075972087624
220tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
221tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
222tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
223tree 56a30b966619b863674f5978696f4a3594f2fca9
224tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
225tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
226EOF
227
228echo tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 >> expected
229
230test_expect_success "$name" "diff -u a expected"
231
232test_done