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