1#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
6test_description='git-svn tests'
7GIT_SVN_LC_ALL=$LC_ALL
8. ./lib-git-svn.sh
9
10mkdir import
11cd import
12
13echo foo > foo
14ln -s foo foo.link
15mkdir -p dir/a/b/c/d/e
16echo 'deep dir' > dir/a/b/c/d/e/file
17mkdir -p bar
18echo 'zzz' > bar/zzz
19echo '#!/bin/sh' > exec.sh
20chmod +x exec.sh
21svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
22
23cd ..
24rm -rf import
25
26test_expect_success \
27 'initialize git-svn' \
28 "git-svn init $svnrepo"
29
30test_expect_success \
31 'import an SVN revision into git' \
32 'git-svn fetch'
33
34
35name='try a deep --rmdir with a commit'
36git checkout -f -b mybranch remotes/git-svn
37mv dir/a/b/c/d/e/file dir/file
38cp dir/file file
39git update-index --add --remove dir/a/b/c/d/e/file dir/file file
40git commit -m "$name"
41
42test_expect_success "$name" \
43 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch &&
44 test -d $SVN_TREE/dir && test ! -d $SVN_TREE/dir/a"
45
46
47name='detect node change from file to directory #1'
48mkdir dir/new_file
49mv dir/file dir/new_file/file
50mv dir/new_file dir/file
51git update-index --remove dir/file
52git update-index --add dir/file/file
53git commit -m "$name"
54
55test_expect_code 1 "$name" \
56 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch' \
57 || true
58
59
60name='detect node change from directory to file #1'
61rm -rf dir $GIT_DIR/index
62git checkout -f -b mybranch2 remotes/git-svn
63mv bar/zzz zzz
64rm -rf bar
65mv zzz bar
66git update-index --remove -- bar/zzz
67git update-index --add -- bar
68git commit -m "$name"
69
70test_expect_code 1 "$name" \
71 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch2' \
72 || true
73
74
75name='detect node change from file to directory #2'
76rm -f $GIT_DIR/index
77git checkout -f -b mybranch3 remotes/git-svn
78rm bar/zzz
79git-update-index --remove bar/zzz
80mkdir bar/zzz
81echo yyy > bar/zzz/yyy
82git-update-index --add bar/zzz/yyy
83git commit -m "$name"
84
85test_expect_code 1 "$name" \
86 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch3' \
87 || true
88
89
90name='detect node change from directory to file #2'
91rm -f $GIT_DIR/index
92git checkout -f -b mybranch4 remotes/git-svn
93rm -rf dir
94git update-index --remove -- dir/file
95touch dir
96echo asdf > dir
97git update-index --add -- dir
98git commit -m "$name"
99
100test_expect_code 1 "$name" \
101 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch4' \
102 || true
103
104
105name='remove executable bit from a file'
106rm -f $GIT_DIR/index
107git checkout -f -b mybranch5 remotes/git-svn
108chmod -x exec.sh
109git update-index exec.sh
110git commit -m "$name"
111
112test_expect_success "$name" \
113 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
114 test ! -x $SVN_TREE/exec.sh"
115
116
117name='add executable bit back file'
118chmod +x exec.sh
119git update-index exec.sh
120git commit -m "$name"
121
122test_expect_success "$name" \
123 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
124 test -x $SVN_TREE/exec.sh"
125
126
127
128name='executable file becomes a symlink to bar/zzz (file)'
129rm exec.sh
130ln -s bar/zzz exec.sh
131git update-index exec.sh
132git commit -m "$name"
133
134test_expect_success "$name" \
135 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
136 test -L $SVN_TREE/exec.sh"
137
138
139
140name='new symlink is added to a file that was also just made executable'
141chmod +x bar/zzz
142ln -s bar/zzz exec-2.sh
143git update-index --add bar/zzz exec-2.sh
144git commit -m "$name"
145
146test_expect_success "$name" \
147 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
148 test -x $SVN_TREE/bar/zzz &&
149 test -L $SVN_TREE/exec-2.sh"
150
151
152
153name='modify a symlink to become a file'
154git help > help || true
155rm exec-2.sh
156cp help exec-2.sh
157git update-index exec-2.sh
158git commit -m "$name"
159
160test_expect_success "$name" \
161 "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
162 test -f $SVN_TREE/exec-2.sh &&
163 test ! -L $SVN_TREE/exec-2.sh &&
164 diff -u help $SVN_TREE/exec-2.sh"
165
166
167if test -n "$GIT_SVN_LC_ALL" && echo $GIT_SVN_LC_ALL | grep -q '\.UTF-8$'
168then
169 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
170 echo '# hello' >> exec-2.sh
171 git update-index exec-2.sh
172 git commit -m 'éï∏'
173 export LC_ALL="$GIT_SVN_LC_ALL"
174 test_expect_success "$name" "git-svn commit HEAD"
175 unset LC_ALL
176else
177 echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
178fi
179
180name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
181GIT_SVN_ID=alt
182export GIT_SVN_ID
183test_expect_success "$name" \
184 "git-svn init $svnrepo && git-svn fetch &&
185 git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
186 git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
187 diff -u a b"
188
189test_done
190