grep: simplify -p output
[git/vmiklos.git] / t / t9119-git-svn-info.sh
blob95741cbbac6bf2e59531bbe1f9527ce4596fa904
1 #!/bin/sh
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 v=`svn_cmd --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p'`
11 case $v in
12 1.[45].*)
15 say "skipping svn-info test (SVN version: $v not supported)"
16 test_done
18 esac
20 ptouch() {
21 perl -w -e '
22 use strict;
23 use POSIX qw(mktime);
24 die "ptouch requires exactly 2 arguments" if @ARGV != 2;
25 my $text_last_updated = shift @ARGV;
26 my $git_file = shift @ARGV;
27 die "\"$git_file\" does not exist" if ! -e $git_file;
28 if ($text_last_updated
29 =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/) {
30 my $mtime = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900);
31 my $atime = $mtime;
32 utime $atime, $mtime, $git_file;
34 ' "`svn_cmd info $2 | grep '^Text Last Updated:'`" "$1"
37 quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
39 test_expect_success 'setup repository and import' '
40 mkdir info &&
41 cd info &&
42 echo FIRST > A &&
43 echo one > file &&
44 ln -s file symlink-file &&
45 mkdir directory &&
46 touch directory/.placeholder &&
47 ln -s directory symlink-directory &&
48 svn_cmd import -m "initial" . "$svnrepo" &&
49 cd .. &&
50 svn_cmd co "$svnrepo" svnwc &&
51 cd svnwc &&
52 echo foo > foo &&
53 svn_cmd add foo &&
54 svn_cmd commit -m "change outside directory" &&
55 svn_cmd update &&
56 cd .. &&
57 mkdir gitwc &&
58 cd gitwc &&
59 git svn init "$svnrepo" &&
60 git svn fetch &&
61 cd .. &&
62 ptouch gitwc/file svnwc/file &&
63 ptouch gitwc/directory svnwc/directory &&
64 ptouch gitwc/symlink-file svnwc/symlink-file &&
65 ptouch gitwc/symlink-directory svnwc/symlink-directory
68 test_expect_success 'info' "
69 (cd svnwc; svn info) > expected.info &&
70 (cd gitwc; git svn info) > actual.info &&
71 test_cmp expected.info actual.info
74 test_expect_success 'info --url' '
75 test "$(cd gitwc; git svn info --url)" = "$quoted_svnrepo"
78 test_expect_success 'info .' "
79 (cd svnwc; svn info .) > expected.info-dot &&
80 (cd gitwc; git svn info .) > actual.info-dot &&
81 test_cmp expected.info-dot actual.info-dot
84 test_expect_success 'info --url .' '
85 test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo"
88 test_expect_success 'info file' "
89 (cd svnwc; svn info file) > expected.info-file &&
90 (cd gitwc; git svn info file) > actual.info-file &&
91 test_cmp expected.info-file actual.info-file
94 test_expect_success 'info --url file' '
95 test "$(cd gitwc; git svn info --url file)" = "$quoted_svnrepo/file"
98 test_expect_success 'info directory' "
99 (cd svnwc; svn info directory) > expected.info-directory &&
100 (cd gitwc; git svn info directory) > actual.info-directory &&
101 test_cmp expected.info-directory actual.info-directory
104 test_expect_success 'info inside directory' "
105 (cd svnwc/directory; svn info) > expected.info-inside-directory &&
106 (cd gitwc/directory; git svn info) > actual.info-inside-directory &&
107 test_cmp expected.info-inside-directory actual.info-inside-directory
110 test_expect_success 'info --url directory' '
111 test "$(cd gitwc; git svn info --url directory)" = "$quoted_svnrepo/directory"
114 test_expect_success 'info symlink-file' "
115 (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
116 (cd gitwc; git svn info symlink-file) > actual.info-symlink-file &&
117 test_cmp expected.info-symlink-file actual.info-symlink-file
120 test_expect_success 'info --url symlink-file' '
121 test "$(cd gitwc; git svn info --url symlink-file)" \
122 = "$quoted_svnrepo/symlink-file"
125 test_expect_success 'info symlink-directory' "
126 (cd svnwc; svn info symlink-directory) \
127 > expected.info-symlink-directory &&
128 (cd gitwc; git svn info symlink-directory) \
129 > actual.info-symlink-directory &&
130 test_cmp expected.info-symlink-directory actual.info-symlink-directory
133 test_expect_success 'info --url symlink-directory' '
134 test "$(cd gitwc; git svn info --url symlink-directory)" \
135 = "$quoted_svnrepo/symlink-directory"
138 test_expect_success 'info added-file' "
139 echo two > gitwc/added-file &&
140 cd gitwc &&
141 git add added-file &&
142 cd .. &&
143 cp gitwc/added-file svnwc/added-file &&
144 ptouch gitwc/added-file svnwc/added-file &&
145 cd svnwc &&
146 svn_cmd add added-file > /dev/null &&
147 cd .. &&
148 (cd svnwc; svn info added-file) > expected.info-added-file &&
149 (cd gitwc; git svn info added-file) > actual.info-added-file &&
150 test_cmp expected.info-added-file actual.info-added-file
153 test_expect_success 'info --url added-file' '
154 test "$(cd gitwc; git svn info --url added-file)" \
155 = "$quoted_svnrepo/added-file"
158 test_expect_success 'info added-directory' "
159 mkdir gitwc/added-directory svnwc/added-directory &&
160 ptouch gitwc/added-directory svnwc/added-directory &&
161 touch gitwc/added-directory/.placeholder &&
162 cd svnwc &&
163 svn_cmd add added-directory > /dev/null &&
164 cd .. &&
165 cd gitwc &&
166 git add added-directory &&
167 cd .. &&
168 (cd svnwc; svn info added-directory) \
169 > expected.info-added-directory &&
170 (cd gitwc; git svn info added-directory) \
171 > actual.info-added-directory &&
172 test_cmp expected.info-added-directory actual.info-added-directory
175 test_expect_success 'info --url added-directory' '
176 test "$(cd gitwc; git svn info --url added-directory)" \
177 = "$quoted_svnrepo/added-directory"
180 test_expect_success 'info added-symlink-file' "
181 cd gitwc &&
182 ln -s added-file added-symlink-file &&
183 git add added-symlink-file &&
184 cd .. &&
185 cd svnwc &&
186 ln -s added-file added-symlink-file &&
187 svn_cmd add added-symlink-file > /dev/null &&
188 cd .. &&
189 ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
190 (cd svnwc; svn info added-symlink-file) \
191 > expected.info-added-symlink-file &&
192 (cd gitwc; git svn info added-symlink-file) \
193 > actual.info-added-symlink-file &&
194 test_cmp expected.info-added-symlink-file \
195 actual.info-added-symlink-file
198 test_expect_success 'info --url added-symlink-file' '
199 test "$(cd gitwc; git svn info --url added-symlink-file)" \
200 = "$quoted_svnrepo/added-symlink-file"
203 test_expect_success 'info added-symlink-directory' "
204 cd gitwc &&
205 ln -s added-directory added-symlink-directory &&
206 git add added-symlink-directory &&
207 cd .. &&
208 cd svnwc &&
209 ln -s added-directory added-symlink-directory &&
210 svn_cmd add added-symlink-directory > /dev/null &&
211 cd .. &&
212 ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
213 (cd svnwc; svn info added-symlink-directory) \
214 > expected.info-added-symlink-directory &&
215 (cd gitwc; git svn info added-symlink-directory) \
216 > actual.info-added-symlink-directory &&
217 test_cmp expected.info-added-symlink-directory \
218 actual.info-added-symlink-directory
221 test_expect_success 'info --url added-symlink-directory' '
222 test "$(cd gitwc; git svn info --url added-symlink-directory)" \
223 = "$quoted_svnrepo/added-symlink-directory"
226 # The next few tests replace the "Text Last Updated" value with a
227 # placeholder since git doesn't have a way to know the date that a
228 # now-deleted file was last checked out locally. Internally it
229 # simply reuses the Last Changed Date.
231 test_expect_success 'info deleted-file' "
232 cd gitwc &&
233 git rm -f file > /dev/null &&
234 cd .. &&
235 cd svnwc &&
236 svn_cmd rm --force file > /dev/null &&
237 cd .. &&
238 (cd svnwc; svn info file) |
239 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
240 > expected.info-deleted-file &&
241 (cd gitwc; git svn info file) |
242 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
243 > actual.info-deleted-file &&
244 test_cmp expected.info-deleted-file actual.info-deleted-file
247 test_expect_success 'info --url file (deleted)' '
248 test "$(cd gitwc; git svn info --url file)" \
249 = "$quoted_svnrepo/file"
252 test_expect_success 'info deleted-directory' "
253 cd gitwc &&
254 git rm -r -f directory > /dev/null &&
255 cd .. &&
256 cd svnwc &&
257 svn_cmd rm --force directory > /dev/null &&
258 cd .. &&
259 (cd svnwc; svn info directory) |
260 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
261 > expected.info-deleted-directory &&
262 (cd gitwc; git svn info directory) |
263 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
264 > actual.info-deleted-directory &&
265 test_cmp expected.info-deleted-directory actual.info-deleted-directory
268 test_expect_success 'info --url directory (deleted)' '
269 test "$(cd gitwc; git svn info --url directory)" \
270 = "$quoted_svnrepo/directory"
273 test_expect_success 'info deleted-symlink-file' "
274 cd gitwc &&
275 git rm -f symlink-file > /dev/null &&
276 cd .. &&
277 cd svnwc &&
278 svn_cmd rm --force symlink-file > /dev/null &&
279 cd .. &&
280 (cd svnwc; svn info symlink-file) |
281 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
282 > expected.info-deleted-symlink-file &&
283 (cd gitwc; git svn info symlink-file) |
284 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
285 > actual.info-deleted-symlink-file &&
286 test_cmp expected.info-deleted-symlink-file \
287 actual.info-deleted-symlink-file
290 test_expect_success 'info --url symlink-file (deleted)' '
291 test "$(cd gitwc; git svn info --url symlink-file)" \
292 = "$quoted_svnrepo/symlink-file"
295 test_expect_success 'info deleted-symlink-directory' "
296 cd gitwc &&
297 git rm -f symlink-directory > /dev/null &&
298 cd .. &&
299 cd svnwc &&
300 svn_cmd rm --force symlink-directory > /dev/null &&
301 cd .. &&
302 (cd svnwc; svn info symlink-directory) |
303 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
304 > expected.info-deleted-symlink-directory &&
305 (cd gitwc; git svn info symlink-directory) |
306 sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
307 > actual.info-deleted-symlink-directory &&
308 test_cmp expected.info-deleted-symlink-directory \
309 actual.info-deleted-symlink-directory
312 test_expect_success 'info --url symlink-directory (deleted)' '
313 test "$(cd gitwc; git svn info --url symlink-directory)" \
314 = "$quoted_svnrepo/symlink-directory"
317 # NOTE: git does not have the concept of replaced objects,
318 # so we can't test for files in that state.
320 test_expect_success 'info unknown-file' "
321 echo two > gitwc/unknown-file &&
322 (cd gitwc; test_must_fail git svn info unknown-file) \
323 2> actual.info-unknown-file &&
324 grep unknown-file actual.info-unknown-file
327 test_expect_success 'info --url unknown-file' '
328 echo two > gitwc/unknown-file &&
329 (cd gitwc; test_must_fail git svn info --url unknown-file) \
330 2> actual.info-url-unknown-file &&
331 grep unknown-file actual.info-url-unknown-file
334 test_expect_success 'info unknown-directory' "
335 mkdir gitwc/unknown-directory svnwc/unknown-directory &&
336 (cd gitwc; test_must_fail git svn info unknown-directory) \
337 2> actual.info-unknown-directory &&
338 grep unknown-directory actual.info-unknown-directory
341 test_expect_success 'info --url unknown-directory' '
342 (cd gitwc; test_must_fail git svn info --url unknown-directory) \
343 2> actual.info-url-unknown-directory &&
344 grep unknown-directory actual.info-url-unknown-directory
347 test_expect_success 'info unknown-symlink-file' "
348 cd gitwc &&
349 ln -s unknown-file unknown-symlink-file &&
350 cd .. &&
351 (cd gitwc; test_must_fail git svn info unknown-symlink-file) \
352 2> actual.info-unknown-symlink-file &&
353 grep unknown-symlink-file actual.info-unknown-symlink-file
356 test_expect_success 'info --url unknown-symlink-file' '
357 (cd gitwc; test_must_fail git svn info --url unknown-symlink-file) \
358 2> actual.info-url-unknown-symlink-file &&
359 grep unknown-symlink-file actual.info-url-unknown-symlink-file
362 test_expect_success 'info unknown-symlink-directory' "
363 cd gitwc &&
364 ln -s unknown-directory unknown-symlink-directory &&
365 cd .. &&
366 (cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
367 2> actual.info-unknown-symlink-directory &&
368 grep unknown-symlink-directory actual.info-unknown-symlink-directory
371 test_expect_success 'info --url unknown-symlink-directory' '
372 (cd gitwc; test_must_fail git svn info --url unknown-symlink-directory) \
373 2> actual.info-url-unknown-symlink-directory &&
374 grep unknown-symlink-directory actual.info-url-unknown-symlink-directory
377 test_done