Code

Merge branch 'kf/post-receive-sample-hook' into maint
[git.git] / t / t9119-git-svn-info.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 David D. Kilzer
5 test_description='git svn info'
7 . ./lib-git-svn.sh
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
21 ptouch() {
22         perl -w -e '
23                 use strict;
24                 use POSIX qw(mktime);
25                 die "ptouch requires exactly 2 arguments" if @ARGV != 2;
26                 my $text_last_updated = shift @ARGV;
27                 my $git_file = shift @ARGV;
28                 die "\"$git_file\" does not exist" if ! -e $git_file;
29                 if ($text_last_updated
30                     =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/) {
31                         my $mtime = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900);
32                         my $atime = $mtime;
33                         utime $atime, $mtime, $git_file;
34                 }
35         ' "`svn_cmd info $2 | grep '^Text Last Updated:'`" "$1"
36 }
38 quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
40 test_expect_success 'setup repository and import' '
41         mkdir info &&
42         (
43                 cd info &&
44                 echo FIRST >A &&
45                 echo one >file &&
46                 ln -s file symlink-file &&
47                 mkdir directory &&
48                 touch directory/.placeholder &&
49                 ln -s directory symlink-directory &&
50                 svn_cmd import -m "initial" . "$svnrepo"
51         ) &&
52         svn_cmd co "$svnrepo" svnwc &&
53         (
54                 cd svnwc &&
55                 echo foo >foo &&
56                 svn_cmd add foo &&
57                 svn_cmd commit -m "change outside directory" &&
58                 svn_cmd update
59         ) &&
60         mkdir gitwc &&
61         (
62                 cd gitwc &&
63                 git svn init "$svnrepo" &&
64                 git svn fetch
65         ) &&
66         ptouch gitwc/file svnwc/file &&
67         ptouch gitwc/directory svnwc/directory &&
68         ptouch gitwc/symlink-file svnwc/symlink-file &&
69         ptouch gitwc/symlink-directory svnwc/symlink-directory
70         '
72 test_expect_success 'info' "
73         (cd svnwc; svn info) > expected.info &&
74         (cd gitwc; git svn info) > actual.info &&
75         test_cmp expected.info actual.info
76         "
78 test_expect_success 'info --url' '
79         test "$(cd gitwc; git svn info --url)" = "$quoted_svnrepo"
80         '
82 test_expect_success 'info .' "
83         (cd svnwc; svn info .) > expected.info-dot &&
84         (cd gitwc; git svn info .) > actual.info-dot &&
85         test_cmp expected.info-dot actual.info-dot
86         "
88 test_expect_success 'info --url .' '
89         test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo"
90         '
92 test_expect_success 'info file' "
93         (cd svnwc; svn info file) > expected.info-file &&
94         (cd gitwc; git svn info file) > actual.info-file &&
95         test_cmp expected.info-file actual.info-file
96         "
98 test_expect_success 'info --url file' '
99         test "$(cd gitwc; git svn info --url file)" = "$quoted_svnrepo/file"
100         '
102 test_expect_success 'info directory' "
103         (cd svnwc; svn info directory) > expected.info-directory &&
104         (cd gitwc; git svn info directory) > actual.info-directory &&
105         test_cmp expected.info-directory actual.info-directory
106         "
108 test_expect_success 'info inside directory' "
109         (cd svnwc/directory; svn info) > expected.info-inside-directory &&
110         (cd gitwc/directory; git svn info) > actual.info-inside-directory &&
111         test_cmp expected.info-inside-directory actual.info-inside-directory
112         "
114 test_expect_success 'info --url directory' '
115         test "$(cd gitwc; git svn info --url directory)" = "$quoted_svnrepo/directory"
116         '
118 test_expect_success 'info symlink-file' "
119         (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
120         (cd gitwc; git svn info symlink-file) > actual.info-symlink-file &&
121         test_cmp expected.info-symlink-file actual.info-symlink-file
122         "
124 test_expect_success 'info --url symlink-file' '
125         test "$(cd gitwc; git svn info --url symlink-file)" \
126              = "$quoted_svnrepo/symlink-file"
127         '
129 test_expect_success 'info symlink-directory' "
130         (cd svnwc; svn info symlink-directory) \
131                 > expected.info-symlink-directory &&
132         (cd gitwc; git svn info symlink-directory) \
133                 > actual.info-symlink-directory &&
134         test_cmp expected.info-symlink-directory actual.info-symlink-directory
135         "
137 test_expect_success 'info --url symlink-directory' '
138         test "$(cd gitwc; git svn info --url symlink-directory)" \
139              = "$quoted_svnrepo/symlink-directory"
140         '
142 test_expect_success 'info added-file' "
143         echo two > gitwc/added-file &&
144         (
145                 cd gitwc &&
146                 git add added-file
147         ) &&
148         cp gitwc/added-file svnwc/added-file &&
149         ptouch gitwc/added-file svnwc/added-file &&
150         (
151                 cd svnwc &&
152                 svn_cmd add added-file > /dev/null
153         ) &&
154         (cd svnwc; svn info added-file) > expected.info-added-file &&
155         (cd gitwc; git svn info added-file) > actual.info-added-file &&
156         test_cmp expected.info-added-file actual.info-added-file
157         "
159 test_expect_success 'info --url added-file' '
160         test "$(cd gitwc; git svn info --url added-file)" \
161              = "$quoted_svnrepo/added-file"
162         '
164 test_expect_success 'info added-directory' "
165         mkdir gitwc/added-directory svnwc/added-directory &&
166         ptouch gitwc/added-directory svnwc/added-directory &&
167         touch gitwc/added-directory/.placeholder &&
168         (
169                 cd svnwc &&
170                 svn_cmd add added-directory > /dev/null
171         ) &&
172         (
173                 cd gitwc &&
174                 git add added-directory
175         ) &&
176         (cd svnwc; svn info added-directory) \
177                 > expected.info-added-directory &&
178         (cd gitwc; git svn info added-directory) \
179                 > actual.info-added-directory &&
180         test_cmp expected.info-added-directory actual.info-added-directory
181         "
183 test_expect_success 'info --url added-directory' '
184         test "$(cd gitwc; git svn info --url added-directory)" \
185              = "$quoted_svnrepo/added-directory"
186         '
188 test_expect_success 'info added-symlink-file' "
189         (
190                 cd gitwc &&
191                 ln -s added-file added-symlink-file &&
192                 git add added-symlink-file
193         ) &&
194         (
195                 cd svnwc &&
196                 ln -s added-file added-symlink-file &&
197                 svn_cmd add added-symlink-file > /dev/null
198         ) &&
199         ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
200         (cd svnwc; svn info added-symlink-file) \
201                 > expected.info-added-symlink-file &&
202         (cd gitwc; git svn info added-symlink-file) \
203                 > actual.info-added-symlink-file &&
204         test_cmp expected.info-added-symlink-file \
205                  actual.info-added-symlink-file
206         "
208 test_expect_success 'info --url added-symlink-file' '
209         test "$(cd gitwc; git svn info --url added-symlink-file)" \
210              = "$quoted_svnrepo/added-symlink-file"
211         '
213 test_expect_success 'info added-symlink-directory' "
214         (
215                 cd gitwc &&
216                 ln -s added-directory added-symlink-directory &&
217                 git add added-symlink-directory
218         ) &&
219         (
220                 cd svnwc &&
221                 ln -s added-directory added-symlink-directory &&
222                 svn_cmd add added-symlink-directory > /dev/null
223         ) &&
224         ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
225         (cd svnwc; svn info added-symlink-directory) \
226                 > expected.info-added-symlink-directory &&
227         (cd gitwc; git svn info added-symlink-directory) \
228                 > actual.info-added-symlink-directory &&
229         test_cmp expected.info-added-symlink-directory \
230                  actual.info-added-symlink-directory
231         "
233 test_expect_success 'info --url added-symlink-directory' '
234         test "$(cd gitwc; git svn info --url added-symlink-directory)" \
235              = "$quoted_svnrepo/added-symlink-directory"
236         '
238 # The next few tests replace the "Text Last Updated" value with a
239 # placeholder since git doesn't have a way to know the date that a
240 # now-deleted file was last checked out locally.  Internally it
241 # simply reuses the Last Changed Date.
243 test_expect_success 'info deleted-file' "
244         (
245                 cd gitwc &&
246                 git rm -f file > /dev/null
247         ) &&
248         (
249                 cd svnwc &&
250                 svn_cmd rm --force file > /dev/null
251         ) &&
252         (cd svnwc; svn info file) |
253         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
254                 > expected.info-deleted-file &&
255         (cd gitwc; git svn info file) |
256         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
257                 > actual.info-deleted-file &&
258         test_cmp expected.info-deleted-file actual.info-deleted-file
259         "
261 test_expect_success 'info --url file (deleted)' '
262         test "$(cd gitwc; git svn info --url file)" \
263              = "$quoted_svnrepo/file"
264         '
266 test_expect_success 'info deleted-directory' "
267         (
268                 cd gitwc &&
269                 git rm -r -f directory > /dev/null
270         ) &&
271         (
272                 cd svnwc &&
273                 svn_cmd rm --force directory > /dev/null
274         ) &&
275         (cd svnwc; svn info directory) |
276         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
277                 > expected.info-deleted-directory &&
278         (cd gitwc; git svn info directory) |
279         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
280                 > actual.info-deleted-directory &&
281         test_cmp expected.info-deleted-directory actual.info-deleted-directory
282         "
284 test_expect_success 'info --url directory (deleted)' '
285         test "$(cd gitwc; git svn info --url directory)" \
286              = "$quoted_svnrepo/directory"
287         '
289 test_expect_success 'info deleted-symlink-file' "
290         (
291                 cd gitwc &&
292                 git rm -f symlink-file > /dev/null
293         ) &&
294         (
295                 cd svnwc &&
296                 svn_cmd rm --force symlink-file > /dev/null
297         ) &&
298         (cd svnwc; svn info symlink-file) |
299         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
300                 > expected.info-deleted-symlink-file &&
301         (cd gitwc; git svn info symlink-file) |
302         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
303                 > actual.info-deleted-symlink-file &&
304         test_cmp expected.info-deleted-symlink-file \
305                  actual.info-deleted-symlink-file
306         "
308 test_expect_success 'info --url symlink-file (deleted)' '
309         test "$(cd gitwc; git svn info --url symlink-file)" \
310              = "$quoted_svnrepo/symlink-file"
311         '
313 test_expect_success 'info deleted-symlink-directory' "
314         (
315                 cd gitwc &&
316                 git rm -f symlink-directory > /dev/null
317         ) &&
318         (
319                 cd svnwc &&
320                 svn_cmd rm --force symlink-directory > /dev/null
321         ) &&
322         (cd svnwc; svn info symlink-directory) |
323         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
324                  > expected.info-deleted-symlink-directory &&
325         (cd gitwc; git svn info symlink-directory) |
326         sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
327                  > actual.info-deleted-symlink-directory &&
328         test_cmp expected.info-deleted-symlink-directory \
329                  actual.info-deleted-symlink-directory
330         "
332 test_expect_success 'info --url symlink-directory (deleted)' '
333         test "$(cd gitwc; git svn info --url symlink-directory)" \
334              = "$quoted_svnrepo/symlink-directory"
335         '
337 # NOTE: git does not have the concept of replaced objects,
338 # so we can't test for files in that state.
340 test_expect_success 'info unknown-file' "
341         echo two > gitwc/unknown-file &&
342         (cd gitwc; test_must_fail git svn info unknown-file) \
343                  2> actual.info-unknown-file &&
344         grep unknown-file actual.info-unknown-file
345         "
347 test_expect_success 'info --url unknown-file' '
348         echo two > gitwc/unknown-file &&
349         (cd gitwc; test_must_fail git svn info --url unknown-file) \
350                  2> actual.info-url-unknown-file &&
351         grep unknown-file actual.info-url-unknown-file
352         '
354 test_expect_success 'info unknown-directory' "
355         mkdir gitwc/unknown-directory svnwc/unknown-directory &&
356         (cd gitwc; test_must_fail git svn info unknown-directory) \
357                  2> actual.info-unknown-directory &&
358         grep unknown-directory actual.info-unknown-directory
359         "
361 test_expect_success 'info --url unknown-directory' '
362         (cd gitwc; test_must_fail git svn info --url unknown-directory) \
363                  2> actual.info-url-unknown-directory &&
364         grep unknown-directory actual.info-url-unknown-directory
365         '
367 test_expect_success 'info unknown-symlink-file' "
368         (
369                 cd gitwc &&
370                 ln -s unknown-file unknown-symlink-file
371         ) &&
372         (cd gitwc; test_must_fail git svn info unknown-symlink-file) \
373                  2> actual.info-unknown-symlink-file &&
374         grep unknown-symlink-file actual.info-unknown-symlink-file
375         "
377 test_expect_success 'info --url unknown-symlink-file' '
378         (cd gitwc; test_must_fail git svn info --url unknown-symlink-file) \
379                  2> actual.info-url-unknown-symlink-file &&
380         grep unknown-symlink-file actual.info-url-unknown-symlink-file
381         '
383 test_expect_success 'info unknown-symlink-directory' "
384         (
385                 cd gitwc &&
386                 ln -s unknown-directory unknown-symlink-directory
387         ) &&
388         (cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
389                  2> actual.info-unknown-symlink-directory &&
390         grep unknown-symlink-directory actual.info-unknown-symlink-directory
391         "
393 test_expect_success 'info --url unknown-symlink-directory' '
394         (cd gitwc; test_must_fail git svn info --url unknown-symlink-directory) \
395                  2> actual.info-url-unknown-symlink-directory &&
396         grep unknown-symlink-directory actual.info-url-unknown-symlink-directory
397         '
399 test_done