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