t/helper: merge test-sha1 into test-tool
[git] / t / t9119-git-svn-info.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 David D. Kilzer
4
5 test_description='git svn info'
6
7 . ./lib-git-svn.sh
8
9 # Tested with: svn, version 1.4.4 (r25188)
10 # Tested with: svn, version 1.6.[12345689]
11 v=$(svn_cmd --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p')
12 case $v in
13 1.[456].*)
14         ;;
15 *)
16         skip_all="skipping svn-info test (SVN version: $v not supported)"
17         test_done
18         ;;
19 esac
20
21 # On the "Text Last Updated" line, "git svn info" does not return the
22 # same value as "svn info" (i.e. the commit timestamp that touched the
23 # path most recently); do not expect that field to match.
24 test_cmp_info () {
25         sed -e '/^Text Last Updated:/d' "$1" >tmp.expect
26         sed -e '/^Text Last Updated:/d' "$2" >tmp.actual
27         test_cmp tmp.expect tmp.actual &&
28         rm -f tmp.expect tmp.actual
29 }
30
31 quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
32
33 test_expect_success 'setup repository and import' '
34         mkdir info &&
35         (
36                 cd info &&
37                 echo FIRST >A &&
38                 echo one >file &&
39                 ln -s file symlink-file &&
40                 mkdir directory &&
41                 touch directory/.placeholder &&
42                 ln -s directory symlink-directory &&
43                 svn_cmd import -m "initial" . "$svnrepo"
44         ) &&
45         svn_cmd co "$svnrepo" svnwc &&
46         (
47                 cd svnwc &&
48                 echo foo >foo &&
49                 svn_cmd add foo &&
50                 svn_cmd commit -m "change outside directory" &&
51                 svn_cmd update
52         ) &&
53         mkdir gitwc &&
54         (
55                 cd gitwc &&
56                 git svn init "$svnrepo" &&
57                 git svn fetch
58         )
59         '
60
61 test_expect_success 'info' "
62         (cd svnwc; svn info) > expected.info &&
63         (cd gitwc; git svn info) > actual.info &&
64         test_cmp_info expected.info actual.info
65         "
66
67 test_expect_success 'info --url' '
68         test "$(cd gitwc; git svn info --url)" = "$quoted_svnrepo"
69         '
70
71 test_expect_success 'info .' "
72         (cd svnwc; svn info .) > expected.info-dot &&
73         (cd gitwc; git svn info .) > actual.info-dot &&
74         test_cmp_info expected.info-dot actual.info-dot
75         "
76
77 test_expect_success 'info $(pwd)' '
78         (cd svnwc; svn info "$(pwd)") >expected.info-pwd &&
79         (cd gitwc; git svn info "$(pwd)") >actual.info-pwd &&
80         grep -v ^Path: <expected.info-pwd >expected.info-np &&
81         grep -v ^Path: <actual.info-pwd >actual.info-np &&
82         test_cmp_info expected.info-np actual.info-np &&
83         test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \
84              "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)"
85         '
86
87 test_expect_success 'info $(pwd)/../___wc' '
88         (cd svnwc; svn info "$(pwd)/../svnwc") >expected.info-pwd &&
89         (cd gitwc; git svn info "$(pwd)/../gitwc") >actual.info-pwd &&
90         grep -v ^Path: <expected.info-pwd >expected.info-np &&
91         grep -v ^Path: <actual.info-pwd >actual.info-np &&
92         test_cmp_info expected.info-np actual.info-np &&
93         test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \
94              "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)"
95         '
96
97 test_expect_success 'info $(pwd)/../___wc//file' '
98         (cd svnwc; svn info "$(pwd)/../svnwc//file") >expected.info-pwd &&
99         (cd gitwc; git svn info "$(pwd)/../gitwc//file") >actual.info-pwd &&
100         grep -v ^Path: <expected.info-pwd >expected.info-np &&
101         grep -v ^Path: <actual.info-pwd >actual.info-np &&
102         test_cmp_info expected.info-np actual.info-np &&
103         test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \
104              "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)"
105         '
106
107 test_expect_success 'info --url .' '
108         test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo"
109         '
110
111 test_expect_success 'info file' "
112         (cd svnwc; svn info file) > expected.info-file &&
113         (cd gitwc; git svn info file) > actual.info-file &&
114         test_cmp_info expected.info-file actual.info-file
115         "
116
117 test_expect_success 'info --url file' '
118         test "$(cd gitwc; git svn info --url file)" = "$quoted_svnrepo/file"
119         '
120
121 test_expect_success 'info directory' "
122         (cd svnwc; svn info directory) > expected.info-directory &&
123         (cd gitwc; git svn info directory) > actual.info-directory &&
124         test_cmp_info expected.info-directory actual.info-directory
125         "
126
127 test_expect_success 'info inside directory' "
128         (cd svnwc/directory; svn info) > expected.info-inside-directory &&
129         (cd gitwc/directory; git svn info) > actual.info-inside-directory &&
130         test_cmp_info expected.info-inside-directory actual.info-inside-directory
131         "
132
133 test_expect_success 'info --url directory' '
134         test "$(cd gitwc; git svn info --url directory)" = "$quoted_svnrepo/directory"
135         '
136
137 test_expect_success 'info symlink-file' "
138         (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
139         (cd gitwc; git svn info symlink-file) > actual.info-symlink-file &&
140         test_cmp_info expected.info-symlink-file actual.info-symlink-file
141         "
142
143 test_expect_success 'info --url symlink-file' '
144         test "$(cd gitwc; git svn info --url symlink-file)" \
145              = "$quoted_svnrepo/symlink-file"
146         '
147
148 test_expect_success 'info symlink-directory' "
149         (cd svnwc; svn info symlink-directory) \
150                 > expected.info-symlink-directory &&
151         (cd gitwc; git svn info symlink-directory) \
152                 > actual.info-symlink-directory &&
153         test_cmp_info expected.info-symlink-directory actual.info-symlink-directory
154         "
155
156 test_expect_success 'info --url symlink-directory' '
157         test "$(cd gitwc; git svn info --url symlink-directory)" \
158              = "$quoted_svnrepo/symlink-directory"
159         '
160
161 test_expect_success 'info added-file' "
162         echo two > gitwc/added-file &&
163         (
164                 cd gitwc &&
165                 git add added-file
166         ) &&
167         cp gitwc/added-file svnwc/added-file &&
168         (
169                 cd svnwc &&
170                 svn_cmd add added-file > /dev/null
171         ) &&
172         (cd svnwc; svn info added-file) > expected.info-added-file &&
173         (cd gitwc; git svn info added-file) > actual.info-added-file &&
174         test_cmp_info expected.info-added-file actual.info-added-file
175         "
176
177 test_expect_success 'info --url added-file' '
178         test "$(cd gitwc; git svn info --url added-file)" \
179              = "$quoted_svnrepo/added-file"
180         '
181
182 test_expect_success 'info added-directory' "
183         mkdir gitwc/added-directory svnwc/added-directory &&
184         touch gitwc/added-directory/.placeholder &&
185         (
186                 cd svnwc &&
187                 svn_cmd add added-directory > /dev/null
188         ) &&
189         (
190                 cd gitwc &&
191                 git add added-directory
192         ) &&
193         (cd svnwc; svn info added-directory) \
194                 > expected.info-added-directory &&
195         (cd gitwc; git svn info added-directory) \
196                 > actual.info-added-directory &&
197         test_cmp_info expected.info-added-directory actual.info-added-directory
198         "
199
200 test_expect_success 'info --url added-directory' '
201         test "$(cd gitwc; git svn info --url added-directory)" \
202              = "$quoted_svnrepo/added-directory"
203         '
204
205 test_expect_success 'info added-symlink-file' "
206         (
207                 cd gitwc &&
208                 ln -s added-file added-symlink-file &&
209                 git add added-symlink-file
210         ) &&
211         (
212                 cd svnwc &&
213                 ln -s added-file added-symlink-file &&
214                 svn_cmd add added-symlink-file > /dev/null
215         ) &&
216         (cd svnwc; svn info added-symlink-file) \
217                 > expected.info-added-symlink-file &&
218         (cd gitwc; git svn info added-symlink-file) \
219                 > actual.info-added-symlink-file &&
220         test_cmp_info expected.info-added-symlink-file \
221                 actual.info-added-symlink-file
222         "
223
224 test_expect_success 'info --url added-symlink-file' '
225         test "$(cd gitwc; git svn info --url added-symlink-file)" \
226              = "$quoted_svnrepo/added-symlink-file"
227         '
228
229 test_expect_success 'info added-symlink-directory' "
230         (
231                 cd gitwc &&
232                 ln -s added-directory added-symlink-directory &&
233                 git add added-symlink-directory
234         ) &&
235         (
236                 cd svnwc &&
237                 ln -s added-directory added-symlink-directory &&
238                 svn_cmd add added-symlink-directory > /dev/null
239         ) &&
240         (cd svnwc; svn info added-symlink-directory) \
241                 > expected.info-added-symlink-directory &&
242         (cd gitwc; git svn info added-symlink-directory) \
243                 > actual.info-added-symlink-directory &&
244         test_cmp_info expected.info-added-symlink-directory \
245                 actual.info-added-symlink-directory
246         "
247
248 test_expect_success 'info --url added-symlink-directory' '
249         test "$(cd gitwc; git svn info --url added-symlink-directory)" \
250              = "$quoted_svnrepo/added-symlink-directory"
251         '
252
253 test_expect_success 'info deleted-file' "
254         (
255                 cd gitwc &&
256                 git rm -f file > /dev/null
257         ) &&
258         (
259                 cd svnwc &&
260                 svn_cmd rm --force file > /dev/null
261         ) &&
262         (cd svnwc; svn info file) >expected.info-deleted-file &&
263         (cd gitwc; git svn info file) >actual.info-deleted-file &&
264         test_cmp_info expected.info-deleted-file actual.info-deleted-file
265         "
266
267 test_expect_success 'info --url file (deleted)' '
268         test "$(cd gitwc; git svn info --url file)" \
269              = "$quoted_svnrepo/file"
270         '
271
272 test_expect_success 'info deleted-directory' "
273         (
274                 cd gitwc &&
275                 git rm -r -f directory > /dev/null
276         ) &&
277         (
278                 cd svnwc &&
279                 svn_cmd rm --force directory > /dev/null
280         ) &&
281         (cd svnwc; svn info directory) >expected.info-deleted-directory &&
282         (cd gitwc; git svn info directory) >actual.info-deleted-directory &&
283         test_cmp_info expected.info-deleted-directory actual.info-deleted-directory
284         "
285
286 test_expect_success 'info --url directory (deleted)' '
287         test "$(cd gitwc; git svn info --url directory)" \
288              = "$quoted_svnrepo/directory"
289         '
290
291 test_expect_success 'info deleted-symlink-file' "
292         (
293                 cd gitwc &&
294                 git rm -f symlink-file > /dev/null
295         ) &&
296         (
297                 cd svnwc &&
298                 svn_cmd rm --force symlink-file > /dev/null
299         ) &&
300         (cd svnwc; svn info symlink-file) >expected.info-deleted-symlink-file &&
301         (cd gitwc; git svn info symlink-file) >actual.info-deleted-symlink-file &&
302         test_cmp_info expected.info-deleted-symlink-file actual.info-deleted-symlink-file
303         "
304
305 test_expect_success 'info --url symlink-file (deleted)' '
306         test "$(cd gitwc; git svn info --url symlink-file)" \
307              = "$quoted_svnrepo/symlink-file"
308         '
309
310 test_expect_success 'info deleted-symlink-directory' "
311         (
312                 cd gitwc &&
313                 git rm -f symlink-directory > /dev/null
314         ) &&
315         (
316                 cd svnwc &&
317                 svn_cmd rm --force symlink-directory > /dev/null
318         ) &&
319         (cd svnwc; svn info symlink-directory) >expected.info-deleted-symlink-directory &&
320         (cd gitwc; git svn info symlink-directory) >actual.info-deleted-symlink-directory &&
321         test_cmp_info expected.info-deleted-symlink-directory actual.info-deleted-symlink-directory
322         "
323
324 test_expect_success 'info --url symlink-directory (deleted)' '
325         test "$(cd gitwc; git svn info --url symlink-directory)" \
326              = "$quoted_svnrepo/symlink-directory"
327         '
328
329 # NOTE: git does not have the concept of replaced objects,
330 # so we can't test for files in that state.
331
332 test_expect_success 'info unknown-file' "
333         echo two > gitwc/unknown-file &&
334         (cd gitwc; test_must_fail git svn info unknown-file) \
335                  2> actual.info-unknown-file &&
336         grep unknown-file actual.info-unknown-file
337         "
338
339 test_expect_success 'info --url unknown-file' '
340         echo two > gitwc/unknown-file &&
341         (cd gitwc; test_must_fail git svn info --url unknown-file) \
342                  2> actual.info-url-unknown-file &&
343         grep unknown-file actual.info-url-unknown-file
344         '
345
346 test_expect_success 'info unknown-directory' "
347         mkdir gitwc/unknown-directory svnwc/unknown-directory &&
348         (cd gitwc; test_must_fail git svn info unknown-directory) \
349                  2> actual.info-unknown-directory &&
350         grep unknown-directory actual.info-unknown-directory
351         "
352
353 test_expect_success 'info --url unknown-directory' '
354         (cd gitwc; test_must_fail git svn info --url unknown-directory) \
355                  2> actual.info-url-unknown-directory &&
356         grep unknown-directory actual.info-url-unknown-directory
357         '
358
359 test_expect_success 'info unknown-symlink-file' "
360         (
361                 cd gitwc &&
362                 ln -s unknown-file unknown-symlink-file
363         ) &&
364         (cd gitwc; test_must_fail git svn info unknown-symlink-file) \
365                  2> actual.info-unknown-symlink-file &&
366         grep unknown-symlink-file actual.info-unknown-symlink-file
367         "
368
369 test_expect_success 'info --url unknown-symlink-file' '
370         (cd gitwc; test_must_fail git svn info --url unknown-symlink-file) \
371                  2> actual.info-url-unknown-symlink-file &&
372         grep unknown-symlink-file actual.info-url-unknown-symlink-file
373         '
374
375 test_expect_success 'info unknown-symlink-directory' "
376         (
377                 cd gitwc &&
378                 ln -s unknown-directory unknown-symlink-directory
379         ) &&
380         (cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
381                  2> actual.info-unknown-symlink-directory &&
382         grep unknown-symlink-directory actual.info-unknown-symlink-directory
383         "
384
385 test_expect_success 'info --url unknown-symlink-directory' '
386         (cd gitwc; test_must_fail git svn info --url unknown-symlink-directory) \
387                  2> actual.info-url-unknown-symlink-directory &&
388         grep unknown-symlink-directory actual.info-url-unknown-symlink-directory
389         '
390
391 test_done