0c6ff2066b7faa098ecc23a415a95870199a0641
[git.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 . ./lib-git-svn.sh
9
10 mkdir import
11 cd import
12
13 echo foo > foo
14 ln -s foo foo.link
15 mkdir -p dir/a/b/c/d/e
16 echo 'deep dir' > dir/a/b/c/d/e/file
17 mkdir -p bar
18 echo 'zzz' > bar/zzz
19 echo '#!/bin/sh' > exec.sh
20 chmod +x exec.sh
21 svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
22
23 cd ..
24 rm -rf import
25
26 test_expect_success \
27     'initialize git-svn' \
28     "git-svn init $svnrepo"
29
30 test_expect_success \
31     'import an SVN revision into git' \
32     'git-svn fetch'
33
34
35 name='try a deep --rmdir with a commit'
36 git checkout -f -b mybranch remotes/git-svn
37 mv dir/a/b/c/d/e/file dir/file
38 cp dir/file file
39 git update-index --add --remove dir/a/b/c/d/e/file dir/file file
40 git commit -m "$name"
41
42 test_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
47 name='detect node change from file to directory #1'
48 mkdir dir/new_file
49 mv dir/file dir/new_file/file
50 mv dir/new_file dir/file
51 git update-index --remove dir/file
52 git update-index --add dir/file/file
53 git commit -m "$name"
54
55 test_expect_code 1 "$name" \
56     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch' \
57     || true
58
59
60 name='detect node change from directory to file #1'
61 rm -rf dir $GIT_DIR/index
62 git checkout -f -b mybranch2 remotes/git-svn
63 mv bar/zzz zzz
64 rm -rf bar
65 mv zzz bar
66 git update-index --remove -- bar/zzz
67 git update-index --add -- bar
68 git commit -m "$name"
69
70 test_expect_code 1 "$name" \
71     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch2' \
72     || true
73
74
75 name='detect node change from file to directory #2'
76 rm -f $GIT_DIR/index
77 git checkout -f -b mybranch3 remotes/git-svn
78 rm bar/zzz
79 git-update-index --remove bar/zzz
80 mkdir bar/zzz
81 echo yyy > bar/zzz/yyy
82 git-update-index --add bar/zzz/yyy
83 git commit -m "$name"
84
85 test_expect_code 1 "$name" \
86     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch3' \
87     || true
88
89
90 name='detect node change from directory to file #2'
91 rm -f $GIT_DIR/index
92 git checkout -f -b mybranch4 remotes/git-svn
93 rm -rf dir
94 git update-index --remove -- dir/file
95 touch dir
96 echo asdf > dir
97 git update-index --add -- dir
98 git commit -m "$name"
99
100 test_expect_code 1 "$name" \
101     'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch4' \
102     || true
103
104
105 name='remove executable bit from a file'
106 rm -f $GIT_DIR/index
107 git checkout -f -b mybranch5 remotes/git-svn
108 chmod -x exec.sh
109 git update-index exec.sh
110 git commit -m "$name"
111
112 test_expect_success "$name" \
113     "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 &&
114      test ! -x $SVN_TREE/exec.sh"
115
116
117 name='add executable bit back file'
118 chmod +x exec.sh
119 git update-index exec.sh
120 git commit -m "$name"
121
122 test_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
128 name='executable file becomes a symlink to bar/zzz (file)'
129 rm exec.sh
130 ln -s bar/zzz exec.sh
131 git update-index exec.sh
132 git commit -m "$name"
133
134 test_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
140 name='new symlink is added to a file that was also just made executable'
141 chmod +x bar/zzz
142 ln -s bar/zzz exec-2.sh
143 git update-index --add bar/zzz exec-2.sh
144 git commit -m "$name"
145
146 test_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
153 name='modify a symlink to become a file'
154 git help > help || true
155 rm exec-2.sh
156 cp help exec-2.sh
157 git update-index exec-2.sh
158 git commit -m "$name"
159
160 test_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
167 if test -n "$GIT_SVN_LC_ALL" && echo $GIT_SVN_LC_ALL | grep -q '\.UTF-8$'
168 then
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
176 else
177         echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
178 fi
179
180 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
181 GIT_SVN_ID=alt
182 export GIT_SVN_ID
183 test_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
189 test_done
190