git-svn: several graft-branches improvements
[git] / contrib / git-svn / t / t0000-contrib-git-svn.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 test_description='git-svn tests'
7 GIT_SVN_LC_ALL=$LC_ALL
8
9 case "$LC_ALL" in
10 *.UTF-8)
11         have_utf8=t
12         ;;
13 *)
14         have_utf8=
15         ;;
16 esac
17
18 . ./lib-git-svn.sh
19
20 mkdir import
21 cd import
22
23 echo foo > foo
24 if test -z "$NO_SYMLINK"
25 then
26         ln -s foo foo.link
27 fi
28 mkdir -p dir/a/b/c/d/e
29 echo 'deep dir' > dir/a/b/c/d/e/file
30 mkdir -p bar
31 echo 'zzz' > bar/zzz
32 echo '#!/bin/sh' > exec.sh
33 chmod +x exec.sh
34 svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
35
36 cd ..
37 rm -rf import
38
39 test_expect_success \
40     'initialize git-svn' \
41     "git-svn init $svnrepo"
42
43 test_expect_success \
44     'import an SVN revision into git' \
45     'git-svn fetch'
46
47 test_expect_success "checkout from svn" "svn co $svnrepo $SVN_TREE"
48
49 name='try a deep --rmdir with a commit'
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
56 test_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
62 name='detect node change from file to directory #1'
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
70 test_expect_failure "$name" \
71     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch' \
72     || true
73
74
75 name='detect node change from directory to file #1'
76 rm -rf dir $GIT_DIR/index
77 git checkout -f -b mybranch2 remotes/git-svn
78 mv bar/zzz zzz
79 rm -rf bar
80 mv zzz bar
81 git update-index --remove -- bar/zzz
82 git update-index --add -- bar
83 git commit -m "$name"
84
85 test_expect_failure "$name" \
86     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch2' \
87     || true
88
89
90 name='detect node change from file to directory #2'
91 rm -f $GIT_DIR/index
92 git checkout -f -b mybranch3 remotes/git-svn
93 rm bar/zzz
94 git-update-index --remove bar/zzz
95 mkdir bar/zzz
96 echo yyy > bar/zzz/yyy
97 git-update-index --add bar/zzz/yyy
98 git commit -m "$name"
99
100 test_expect_failure "$name" \
101     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch3' \
102     || true
103
104
105 name='detect node change from directory to file #2'
106 rm -f $GIT_DIR/index
107 git checkout -f -b mybranch4 remotes/git-svn
108 rm -rf dir
109 git update-index --remove -- dir/file
110 touch dir
111 echo asdf > dir
112 git update-index --add -- dir
113 git commit -m "$name"
114
115 test_expect_failure "$name" \
116     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch4' \
117     || true
118
119
120 name='remove executable bit from a file'
121 rm -f $GIT_DIR/index
122 git checkout -f -b mybranch5 remotes/git-svn
123 chmod -x exec.sh
124 git update-index exec.sh
125 git commit -m "$name"
126
127 test_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
133 name='add executable bit back file'
134 chmod +x exec.sh
135 git update-index exec.sh
136 git commit -m "$name"
137
138 test_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
145 if test -z "$NO_SYMLINK"
146 then
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"
183 fi
184
185
186 if test "$have_utf8" = t
187 then
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
195 else
196         echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
197 fi
198
199 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
200 GIT_SVN_ID=alt
201 export GIT_SVN_ID
202 test_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
208 if test -n "$NO_SYMLINK"
209 then
210         test_done
211         exit 0
212 fi
213
214 name='check imported tree checksums expected tree checksums'
215 rm -f expected
216 if test "$have_utf8" = t
217 then
218         echo tree f735671b89a7eb30cab1d8597de35bd4271ab813 > expected
219 fi
220 cat >> expected <<\EOF
221 tree 4b9af72bb861eaed053854ec502cf7df72618f0f
222 tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
223 tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
224 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
225 tree 56a30b966619b863674f5978696f4a3594f2fca9
226 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
227 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
228 EOF
229 test_expect_success "$name" "diff -u a expected"
230
231 test_done
232