summaryrefslogtreecommitdiff
path: root/subversion/tests/cmdline/info_tests.py
blob: 39b8ce21e3948081f28080490b964f03223c15d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
#!/usr/bin/env python
#
#  info_tests.py:  testing the svn info command
#
#  Subversion is a tool for revision control.
#  See http://subversion.apache.org for more information.
#
# ====================================================================
#    Licensed to the Apache Software Foundation (ASF) under one
#    or more contributor license agreements.  See the NOTICE file
#    distributed with this work for additional information
#    regarding copyright ownership.  The ASF licenses this file
#    to you under the Apache License, Version 2.0 (the
#    "License"); you may not use this file except in compliance
#    with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing,
#    software distributed under the License is distributed on an
#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#    KIND, either express or implied.  See the License for the
#    specific language governing permissions and limitations
#    under the License.
######################################################################

# See basic-tests.py for more svn info tests.

# General modules
import shutil, stat, re, os, logging

logger = logging.getLogger()

# Our testing module
import svntest

from prop_tests import binary_mime_type_on_text_file_warning

# (abbreviation)
Skip = svntest.testcase.Skip_deco
SkipUnless = svntest.testcase.SkipUnless_deco
XFail = svntest.testcase.XFail_deco
Issues = svntest.testcase.Issues_deco
Issue = svntest.testcase.Issue_deco
Wimp = svntest.testcase.Wimp_deco
Item = svntest.wc.StateItem

######################################################################
# Tests
#
#   Each test must return on success or raise on failure.

#----------------------------------------------------------------------

# Helpers for XML output
def verify_xml_elements(lines, exprs):
  """Verify that each of the given expressions matches exactly one XML
     element in the list of lines. Each expression is a tuple containing
     a name (a string), a set of attribute name-value pairs (a dict of
     string->string), and element content (a string).  The attribute dict
     and the content string are by default empty.

     Expression format: [ ('name', {'att': 'val', ...}, 'text') , ...]

     Limitations:
     We don't verify that the input is a valid XML document.
     We can't verify text mixed with child elements.
     We don't handle XML comments.
     All of these are taken care of by the Relax NG schemas.
  """
  xml_version_re = re.compile(r"<\?xml\s+[^?]+\?>")

  str = ""
  for line in lines:
    str += line
  m = xml_version_re.match(str)
  if m:
    str = str[m.end():] # skip xml version tag
  (unmatched_str, unmatched_exprs) = match_xml_element(str, exprs)
  if unmatched_exprs:
    logger.warn("Failed to find the following expressions:")
    for expr in unmatched_exprs:
      logger.warn(expr)
    raise svntest.tree.SVNTreeUnequal

def match_xml_element(str, exprs):
  """Read from STR until the start of an element. If no element is found,
     return the arguments.  Get the element name, attributes and text content.
     If not empty, call recursively on the text content.  Compare the current
     element to all expressions in EXPRS.  If no elements were found in the
     current element's text, include the text in the comparison (i.e., we
     don't support mixed content).  Return the unmatched part of the string
     and any unmatched expressions.
  """
  start_tag_re = re.compile(r"[^<]*<(?P<name>[\w-]+)", re.M)
  atttribute_re = re.compile(
                 r"\s+(?P<key>[\w-]+)\s*=\s*(['\"])(?P<val>[^'\"]*)\2", re.M)
  self_closing_re = re.compile(r"\s*/>", re.M)
  content_re_str = "\\s*>(?P<content>.*?)</%s\s*>"

  m = start_tag_re.match(str)
  if not m:
    return (str, exprs)
  name = m.group('name')
  str = str[m.end():]
  atts = {}
  while True:
    m = atttribute_re.match(str)
    if not m:
      break
    else:
      atts[m.group('key')] = m.group('val')
      str = str[m.end():]
  m = self_closing_re.match(str)
  if m:
    content = ''
    str = str[m.end():]
  else:
    content_re = re.compile(content_re_str % name, re.DOTALL)
    m = content_re.match(str)
    if not m:
      logger.warn("No XML end-tag for '%s' found in '%s...'" % (name, str[:100]))
      raise(svntest.tree.SVNTreeUnequal)
    content = m.group('content')
    str = str[m.end():]
  if content != '':
    while True:
      (new_content, exprs) = match_xml_element(content, exprs)
      if new_content == content:
        # there are no (more) child elements
        break
      else:
        content = new_content
  if exprs:
    for expr in exprs:
      # compare element names
      e_name = expr[0]
      if (e_name != name):
        continue
      # compare element attributes
      e_atts = {}
      if len(expr) > 1:
        e_atts = expr[1]
      if e_atts != atts:
        continue
      # compare element content (text only)
      e_content = ''
      if len(expr) > 2:
        e_content = expr[2]
      if (not re.search(e_content, content)):
        continue
      # success!
      exprs.remove(expr)
  return (str, exprs)

def info_with_tree_conflicts(sbox):
  "info with tree conflicts"

  # Info messages reflecting tree conflict status.
  # These tests correspond to use cases 1-3 in
  # notes/tree-conflicts/use-cases.txt.

  svntest.actions.build_greek_tree_conflicts(sbox)
  wc_dir = sbox.wc_dir
  G = os.path.join(wc_dir, 'A', 'D', 'G')

  scenarios = [
    # (filename, action, reason)
    ('pi',  'edit',   'delete'),
    ('rho', 'delete', 'edit'),
    ('tau', 'delete', 'delete'),
    ]

  for fname, action, reason in scenarios:
    path = os.path.join(G, fname)

    # check plain info
    expected_str1 = ".*local file %s, incoming file %s.*" % (reason, action)
    expected_info = { 'Tree conflict' : expected_str1 }
    svntest.actions.run_and_verify_info([expected_info], path)

    # check XML info
    exit_code, output, error = svntest.actions.run_and_verify_svn(None,
                                                                  [], 'info',
                                                                  path,
                                                                  '--xml')

    # In the XML, action and reason are past tense: 'edited' not 'edit'.
    verify_xml_elements(output,
                        [('tree-conflict', {'victim'   : fname,
                                            'kind'     : 'file',
                                            'operation': 'update',
                                            'action'   : action,
                                            'reason'   : reason,
                                            },
                          )])

  # Check recursive info.
  expected_infos = [{ 'Path' : re.escape(G) }]
  for fname, action, reason in scenarios:
    path = os.path.join(G, fname)
    tree_conflict_re = ".*local file %s, incoming file %s.*" % (reason, action)
    expected_infos.append({ 'Path' : re.escape(path),
                            'Tree conflict' : tree_conflict_re })
  expected_infos.sort(key=lambda info: info['Path'])
  svntest.actions.run_and_verify_info(expected_infos, G, '-R')

def info_on_added_file(sbox):
  """info on added file"""

  sbox.build()
  wc_dir = sbox.wc_dir

  # create new file
  new_file = os.path.join(wc_dir, 'new_file')
  svntest.main.file_append(new_file, '')

  svntest.main.run_svn(None, 'add', new_file)

  uuid_regex = '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}'

  # check that we have a Repository Root and Repository UUID
  expected = {'Path' : re.escape(new_file),
              'Name' : 'new_file',
              'URL' : '.*/new_file',
              'Relative URL' : '.*/new_file',
              'Repository Root' : '.*',
              'Node Kind' : 'file',
              'Schedule' : 'add',
              'Repository UUID' : uuid_regex,
             }

  svntest.actions.run_and_verify_info([expected], new_file)

  # check XML info
  exit_code, output, error = svntest.actions.run_and_verify_svn(None,
                                                                [], 'info',
                                                                new_file,
                                                                '--xml')

  verify_xml_elements(output,
                      [('entry',    {'kind'     : 'file',
                                     'path'     : new_file,
                                     'revision' : 'Resource is not under version control.'}),
                       ('url',      {}, '.*/new_file'),
                       ('relative-url', {}, '.*/new_file'),
                       ('root',     {}, '.*'),
                       ('uuid',     {}, uuid_regex),
                       ('depth',    {}, 'infinity'),
                       ('schedule', {}, 'add')])

def info_on_mkdir(sbox):
  """info on new dir with mkdir"""
  sbox.build()
  wc_dir = sbox.wc_dir

  # create a new directory using svn mkdir
  new_dir = os.path.join(wc_dir, 'new_dir')
  svntest.main.run_svn(None, 'mkdir', new_dir)

  uuid_regex = '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}'

  # check that we have a Repository Root and Repository UUID
  expected = {'Path' : re.escape(new_dir),
              'URL' : '.*/new_dir',
              'Relative URL' : '.*/new_dir',
              'Repository Root' : '.*',
              'Node Kind' : 'directory',
              'Schedule' : 'add',
              'Repository UUID' : uuid_regex,
             }

  svntest.actions.run_and_verify_info([expected], new_dir)

  # check XML info
  exit_code, output, error = svntest.actions.run_and_verify_svn(None,
                                                                [], 'info',
                                                                new_dir,
                                                                '--xml')
  verify_xml_elements(output,
                      [('entry',    {'kind'     : 'dir',
                                     'path'     : new_dir,
                                     'revision' : 'Resource is not under version control.'}),
                       ('url',      {}, '.*/new_dir'),
                       ('relative-url', {}, '.*/new_dir'),
                       ('root',     {}, '.*'),
                       ('uuid',     {}, uuid_regex),
                       ('depth',    {}, 'infinity'),
                       ('schedule', {}, 'add')])

def info_wcroot_abspaths(sbox):
  """wc root paths in 'svn info' output"""

  def check_wcroot_paths(lines, wcroot_abspath):
    "check that paths found on input lines beginning 'Path: ' are as expected"
    path = None
    target = None
    for line in lines:
      if line.startswith('Path: '):
        target = line[6:].rstrip()
      if line.startswith('Working Copy Root Path: '):
        path = line[24:].rstrip()
      if target is not None and path is not None:
        break

    if target is None:
      target = "(UNKNOWN)"

    if path is None:
      logger.warn("No WC root path for '%s'", target)
      raise svntest.Failure

    if path != wcroot_abspath:
      logger.warn("For target '%s'...", target)
      logger.warn("   Reported WC root path: %s", path)
      logger.warn("   Expected WC root path: %s", wcroot_abspath)
      raise svntest.Failure

  sbox.build(read_only=True)
  exit_code, output, errput = svntest.main.run_svn(None, 'info', '-R', sbox.wc_dir)
  check_wcroot_paths(output, os.path.abspath(sbox.wc_dir))

def info_url_special_characters(sbox):
  """special characters in svn info URL"""
  sbox.build(create_wc = False)
  wc_dir = sbox.wc_dir

  special_urls = [sbox.repo_url + '/A' + '/%2E',
                  sbox.repo_url + '%2F' + 'A']

  expected = {'Path' : 'A',
              'Repository Root' : re.escape(sbox.repo_url),
              'Revision' : '1',
              'Node Kind' : 'dir',
             }

  for url in special_urls:
    svntest.actions.run_and_verify_info([expected], url)

def info_multiple_targets(sbox):
  "info multiple targets"

  sbox.build(read_only = True)
  wc_dir = sbox.wc_dir

  def multiple_wc_targets():
    "multiple wc targets"

    alpha = sbox.ospath('A/B/E/alpha')
    beta = sbox.ospath('A/B/E/beta')
    non_existent_path = os.path.join(wc_dir, 'non-existent')

    # All targets are existing
    svntest.actions.run_and_verify_svn2(None, [],
                                        0, 'info', alpha, beta)

    # One non-existing target
    expected_err = ".*W155010.*\n\n.*E200009.*"
    expected_err_re = re.compile(expected_err, re.DOTALL)

    exit_code, output, error = svntest.main.run_svn(1, 'info', alpha,
                                                    non_existent_path, beta)

    # Verify error
    if not expected_err_re.match("".join(error)):
      raise svntest.Failure('info failed: expected error "%s", but received '
                            '"%s"' % (expected_err, "".join(error)))

  def multiple_url_targets():
    "multiple url targets"

    alpha = sbox.repo_url +  '/A/B/E/alpha'
    beta = sbox.repo_url +  '/A/B/E/beta'
    non_existent_url = sbox.repo_url +  '/non-existent'

    # All targets are existing
    svntest.actions.run_and_verify_svn2(None, [],
                                        0, 'info', alpha, beta)

    # One non-existing target
    expected_err = ".*W170000.*\n\n.*E200009.*"
    expected_err_re = re.compile(expected_err, re.DOTALL)

    exit_code, output, error = svntest.main.run_svn(1, 'info', alpha,
                                                    non_existent_url, beta)

    # Verify error
    if not expected_err_re.match("".join(error)):
      raise svntest.Failure('info failed: expected error "%s", but received '
                            '"%s"' % (expected_err, "".join(error)))
  # Test one by one
  multiple_wc_targets()
  multiple_url_targets()

def info_repos_root_url(sbox):
  """verify values for repository root"""
  sbox.build(create_wc = False)
  wc_dir = sbox.wc_dir

  expected_info = [
    {
        'Path'              : re.escape(os.path.basename(sbox.repo_dir)),
        'Repository Root'   : re.escape(sbox.repo_url),
        'URL'               : re.escape(sbox.repo_url),
        'Relative URL'      : '\^/', # escape ^ -- this isn't a regexp
        'Revision'          : '1',
        'Node Kind'         : 'directory',
        'Last Changed Rev'  : '1',
    },
    {
        'Path'              : 'iota',
        'Name'              : 'iota',
        'Repository Root'   : re.escape(sbox.repo_url),
        'URL'               : re.escape(sbox.repo_url + '/iota'),
        'Relative URL'      : '\^/iota', # escape ^ -- this isn't a regexp
        'Revision'          : '1',
        'Node Kind'         : 'file',
        'Last Changed Rev'  : '1',
    }
  ]

  svntest.actions.run_and_verify_info(expected_info, sbox.repo_url,
                                      '--depth', 'files')

@Issue(3787)
def info_show_exclude(sbox):
  "tests 'info --depth' variants on excluded node"

  sbox.build()
  wc_dir = sbox.wc_dir

  A_path = os.path.join(wc_dir, 'A')
  iota = os.path.join(wc_dir, 'iota')
  svntest.main.run_svn(None, 'up', '--set-depth', 'exclude', A_path)
  wc_uuid = svntest.actions.get_wc_uuid(wc_dir)

  expected_info = [{
      'Path' : re.escape(wc_dir),
      'Repository Root' : sbox.repo_url,
      'Repository UUID' : wc_uuid,
  }]

  svntest.actions.run_and_verify_info(expected_info, '--depth', 'empty',
                                      wc_dir)

  expected_info = [{
      'Path' : '.*%sA' % re.escape(os.sep),
      'Repository Root' : sbox.repo_url,
      'Repository UUID' : wc_uuid,
      'Depth' : 'exclude',
  }]

  svntest.actions.run_and_verify_info(expected_info, '--depth',
                                      'empty', A_path)
  svntest.actions.run_and_verify_info(expected_info, '--depth',
                                      'infinity', A_path)
  svntest.actions.run_and_verify_info(expected_info, '--depth',
                                      'immediates', A_path)

  expected_info = [{
      'Path' : '.*%siota' % re.escape(os.sep),
      'Repository Root' : sbox.repo_url,
      'Repository UUID' : wc_uuid,
  }]
  svntest.main.run_svn(None, 'up', '--set-depth', 'exclude', iota)
  svntest.actions.run_and_verify_info(expected_info, iota)

  # And now get iota back, to allow testing other states
  expected_output = svntest.wc.State(wc_dir, {
    'iota' : Item(status='A '),
    })

  expected_status = svntest.wc.State(iota, {
    '' : Item(status='  ', wc_rev='1')
  })

  svntest.actions.run_and_verify_update(iota,
                                        expected_output, None, expected_status)

  sbox.simple_rm('iota')
  sbox.simple_commit()

  expected_error = 'svn: E200009: Could not display info for all targets.*'

  # Expect error on iota (status = not-present)
  svntest.actions.run_and_verify_svn([], expected_error, 'info', iota)

  sbox.simple_update()

  # Expect error on iota (unversioned)
  svntest.actions.run_and_verify_svn([], expected_error, 'info', iota)

@Issue(3998)
def binary_tree_conflict(sbox):
  "svn info shouldn't crash on conflict"
  sbox.build()
  wc_dir = sbox.wc_dir

  svntest.main.run_svn(binary_mime_type_on_text_file_warning,
                       'propset', 'svn:mime-type', 'binary/octet-stream',
                       sbox.ospath('iota'))
  sbox.simple_commit()

  iota = sbox.ospath('iota')

  svntest.main.file_write(iota, 'something-else')
  sbox.simple_commit()

  svntest.main.file_write(iota, 'third')

  expected_output = svntest.wc.State(wc_dir, {
    'iota' : Item(status='C '),
    })
  expected_status = svntest.wc.State(iota, {
    '' : Item(status='C ', wc_rev='2')
  })
  svntest.actions.run_and_verify_update(iota,
                                        expected_output, None, expected_status,
                                        [], False,
                                        iota, '-r', '2')

  expected_info = [{
      'Path' : '%s' % re.escape(iota),
      'Conflict Previous Base File' : re.escape(iota + '.r3'),
      'Conflict Current Base File' : re.escape(iota + '.r2'),
  }]
  svntest.actions.run_and_verify_info(expected_info, iota)

  expected_info = [{
      'Path' : '%s' % re.escape(wc_dir),
  }]
  svntest.actions.run_and_verify_info(expected_info, wc_dir)

def relpath_escaping(sbox):
  "relpath escaping should be usable as-is"

  sbox.build()
  wc_dir = sbox.wc_dir

  name = 'path with space, +, % and #'
  name2 = 'path with %20'
  sbox.simple_copy('iota', name)
  sbox.simple_copy('iota', name2)
  sbox.simple_commit()

  testpath = sbox.ospath(name)

  expected = {'Path' : re.escape(testpath),
              'URL' : '.*/path.*with.*space.*',
              'Relative URL' : '.*/path.*with.*space.*',
             }

  svntest.actions.run_and_verify_info([expected], sbox.ospath(name))

  info = svntest.actions.run_and_parse_info(sbox.ospath(name), sbox.ospath(name2))

  # And now verify that the returned URL and relative url are usable

  # Also test the local path (to help resolving the relative path) and an
  # unescaped path which the client should automatically encode
  svntest.actions.run_and_verify_svn(None, [], 'info',
                                     info[0]['Relative URL'],
                                     info[0]['URL'],
                                     testpath,
                                     '^/' + name,

                                     info[1]['Relative URL'],
                                     info[1]['URL'])

  # And now do the same thing with a the file external handling
  sbox.simple_propset('svn:externals',
                        info[0]['Relative URL'] + " f1\n" +
                        info[0]['URL'] + " f2\n" +
                        '"^/' + name + "\" f3\n" +

                        info[1]['Relative URL'] + " g1\n" +
                        info[1]['URL'] + " g2\n",
                      ''
                     )

  # And now we expect to see 3 file externals
  expected_output = svntest.wc.State(wc_dir, {
    'f1'                : Item(status='A '),
    'f2'                : Item(status='A '),
    'f3'                : Item(status='A '),

    'g1'                : Item(status='A '),
    'g2'                : Item(status='A '),
  })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

def node_hidden_info(sbox):
  "fetch svn info on 'hidden' nodes"

  sbox.build()

  sbox.simple_rm('A/B/E/alpha')
  sbox.simple_commit()
  svntest.actions.run_and_verify_svn(None, [],
                                     'up', '--set-depth', 'exclude',
                                     sbox.ospath('A/B/E/beta'))

  sbox.simple_copy('A/B/E', 'E')

  # Running info on BASE not-present fails
  expected_err = '.*(E|W)155010: The node \'.*alpha\' was not found.*'
  svntest.actions.run_and_verify_svn(None, expected_err,
                                     'info', sbox.ospath('A/B/E/alpha'))

  expected_info = [
    {
        'Path': re.escape(sbox.ospath('A/B/E/beta')),
        'Schedule': 'normal',
        'Depth': 'exclude',
        'Node Kind': 'file',
    },
    {
        'Path': re.escape(sbox.ospath('E/alpha')),
        'Schedule': 'delete',
        'Depth': 'exclude',
        'Node Kind': 'unknown',
    },
    {
        'Path': re.escape(sbox.ospath('E/beta')),
        'Schedule': 'normal',
        'Depth': 'exclude',
        'Node Kind': 'file',
    }
  ]

  svntest.actions.run_and_verify_info(expected_info,
                                      sbox.ospath('A/B/E/beta'),
                                      sbox.ospath('E/alpha'),
                                      sbox.ospath('E/beta'))


def info_item_simple(sbox):
  "show one info item"

  sbox.build(read_only=True)
  svntest.actions.run_and_verify_svn(
    ['1'], [],
    'info', '--show-item=revision', '--no-newline',
    sbox.ospath(''))


def info_item_simple_multiple(sbox):
  "show one info item with multiple targets"

  sbox.build(read_only=True)

  svntest.actions.run_and_verify_svn(
    r'^jrandom\s+\S+(/|\\)info_tests-\d+((/|\\)[^/\\]+)?$', [],
    'info', '--show-item=last-changed-author',
    '--depth=immediates', sbox.ospath(''))

  svntest.actions.run_and_verify_svn(
    r'^1\s+\S+(/|\\)info_tests-\d+(/|\\)[^/\\]+$', [],
    'info', '--show-item=last-changed-revision',
    sbox.ospath('A'), sbox.ospath('iota'))


def info_item_url(sbox):
  "show one info item with URL targets"

  sbox.build(create_wc=False, read_only=True)

  svntest.actions.run_and_verify_svn(
    '1', [],
    'info', '--show-item=last-changed-revision',
    sbox.repo_url)


  svntest.actions.run_and_verify_svn(
    r'^1\s+[^/:]+://.+/repos/[^/]+$', [],
    'info', '--show-item=last-changed-revision',
    sbox.repo_url + '/A', sbox.repo_url + '/iota')


  # Empty working copy root on URL targets
  svntest.actions.run_and_verify_svn(
    '', [],
    'info', '--show-item=wc-root',
    sbox.repo_url)


def info_item_uncommmitted(sbox):
  "show one info item on uncommitted targets"

  sbox.build()

  svntest.main.file_write(sbox.ospath('newfile'), 'newfile')
  sbox.simple_add('newfile')
  sbox.simple_mkdir('newdir')

  svntest.actions.run_and_verify_svn(
    '', [],
    'info', '--show-item=last-changed-revision',
    sbox.ospath('newfile'))

  svntest.actions.run_and_verify_svn(
    '', [],
    'info', '--show-item=last-changed-author',
    sbox.ospath('newdir'))

  svntest.actions.run_and_verify_svn(
    r'\s+\S+(/|\\)new(file|dir)', [],
    'info', '--show-item=last-changed-date',
    sbox.ospath('newfile'), sbox.ospath('newdir'))

  svntest.actions.run_and_verify_svn(
    r'\^/new(file|dir)\s+\S+(/|\\)new(file|dir)', [],
    'info', '--show-item=relative-url',
    sbox.ospath('newfile'), sbox.ospath('newdir'))


def info_item_size_wc_recursive(sbox):
  "recursive '--show-item=repos-size' on local path"

  sbox.build(read_only=True)

  svntest.actions.run_and_verify_svn(
    [], [],
    'info', '--show-item=repos-size', '--recursive',
    sbox.ospath(''))


def info_item_size_repos(sbox):
  "non-recursive '--show-item=repos-size' on URL"

  sbox.build(read_only=True)

  svntest.actions.run_and_verify_svn(
    "25\n", [],
    'info', '--show-item=repos-size',
    sbox.repo_url + "/iota")

  # Same, but without the newline.
  svntest.actions.run_and_verify_svn(
    "25", [],
    'info', '--show-item=repos-size', '--no-newline',
    sbox.repo_url + "/iota")

  # Same, but with "human-readable" output.
  svntest.actions.run_and_verify_svn(
    "25 B", [],
    'info', '--show-item=repos-size', '--human-readable',
    sbox.repo_url + "/iota")

  # No output when the URL is a directory.
  svntest.actions.run_and_verify_svn(
    [], [],
    'info', '--show-item=repos-size',
    sbox.repo_url)


def info_item_size_repos_recursive(sbox):
  "recursive '--show-item=repos-size' on dir URL"

  sbox.build(read_only=True)

  expected_output = svntest.verify.UnorderedOutput([
    "25         " + sbox.repo_url + "/iota\n",
    "27         " + sbox.repo_url + "/A/B/lambda\n",
    "25         " + sbox.repo_url + "/A/B/E/beta\n",
    "26         " + sbox.repo_url + "/A/B/E/alpha\n",
    "23         " + sbox.repo_url + "/A/mu\n",
    "26         " + sbox.repo_url + "/A/D/gamma\n",
    "23         " + sbox.repo_url + "/A/D/G/pi\n",
    "24         " + sbox.repo_url + "/A/D/G/rho\n",
    "24         " + sbox.repo_url + "/A/D/G/tau\n",
    "26         " + sbox.repo_url + "/A/D/H/omega\n",
    "24         " + sbox.repo_url + "/A/D/H/psi\n",
    "24         " + sbox.repo_url + "/A/D/H/chi\n",
  ])

  svntest.actions.run_and_verify_svn(
    expected_output, [],
    'info', '--show-item=repos-size', '--recursive',
    sbox.repo_url)


def info_item_failures(sbox):
  "failure modes of 'svn info --show-item'"

  sbox.build(read_only=True)

  svntest.actions.run_and_verify_svn(
    None, r'.*E200009:.*',
    'info', '--show-item=revision',
    sbox.ospath('not-there'))

  svntest.actions.run_and_verify_svn(
    None, r".*E205000: .*; did you mean 'wc-root'\?",
    'info', '--show-item=root',
    sbox.ospath(''))

  svntest.actions.run_and_verify_svn(
    None, (r".*E205000: --show-item is not valid in --xml mode"),
    'info', '--show-item=revision', '--xml',
    sbox.ospath(''))

  svntest.actions.run_and_verify_svn(
    None, (r".*E205000: --incremental is only valid in --xml mode"),
    'info', '--show-item=revision', '--incremental',
    sbox.ospath(''))

  svntest.actions.run_and_verify_svn(
    None, (r".*E205000: --no-newline is only available.*"),
    'info', '--show-item=revision', '--no-newline',
    sbox.ospath('A'), sbox.ospath('iota'))

  svntest.actions.run_and_verify_svn(
    None, (r".*E200007: can't show in-repository size.*"),
    'info', '--show-item=repos-size',
    sbox.ospath('iota'))


@Issue(4837)
def info_file_in_file_replaced_dir(sbox):
  "info, file in file-replaced dir"

  sbox.build(empty=True)
  sbox.simple_mkdir('dir')
  sbox.simple_add_text('text\n', 'dir/file')
  sbox.simple_commit(message='Add file')

  sbox.simple_copy('dir/file', 'file-moved')
  sbox.simple_rm('dir')
  sbox.simple_add_text('replaced\n', 'dir')
  sbox.simple_commit(message='Replace dir with file')

  sbox.simple_update()

  expected = {'Relative URL' : r'\^/dir/file',
              'Node Kind' : 'file',
              'Revision': '1',
              'Last Changed Rev': '1',
             }

  svntest.actions.run_and_verify_info([expected],
                                      sbox.repo_url + '/dir/file@1')


########################################################################
# Run the tests

# list all tests here, starting with None:
test_list = [ None,
              info_with_tree_conflicts,
              info_on_added_file,
              info_on_mkdir,
              info_wcroot_abspaths,
              info_url_special_characters,
              info_multiple_targets,
              info_repos_root_url,
              info_show_exclude,
              binary_tree_conflict,
              relpath_escaping,
              node_hidden_info,
              info_item_simple,
              info_item_simple_multiple,
              info_item_url,
              info_item_uncommmitted,
              info_item_size_wc_recursive,
              info_item_size_repos,
              info_item_size_repos_recursive,
              info_item_failures,
              info_file_in_file_replaced_dir,
             ]

if __name__ == '__main__':
  svntest.main.run_tests(test_list)
  # NOTREACHED


### End of file.