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