tests/test-paths.t
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 05 Dec 2015 21:11:04 -0800
changeset 27266 4dccc37b87bd
parent 16913 f2719b387380
child 27329 944af8e2eb4c
permissions -rw-r--r--
ui: support declaring path push urls as sub-options Power users often want to apply per-path configuration options. For example, they may want to declare an alternate URL for push operations or declare a revset of revisions to push when `hg push` is used (as opposed to attempting to push all revisions by default). This patch establishes the use of sub-options (config options with ":" in the name) to declare additional behavior for paths. New sub-options are declared by using the new ``@ui.pathsuboption`` decorator. This decorator serves multiple purposes: * Declaring which sub-options are registered * Declaring how a sub-option maps to an attribute on ``path`` instances (this is needed to `hg paths` can render sub-options and values properly) * Validation and normalization of config options to attribute values * Allows extensions to declare new sub-options without monkeypatching * Allows extensions to overwrite built-in behavior for sub-option handling As convenient as the new option registration decorator is, extensions (and even core functionality) may still need an additional hook point to perform finalization of path instances. For example, they may wish to validate that multiple options/attributes aren't conflicting with each other. This hook point could be added later, if needed. To prove this new functionality works, we implement the "pushurl" path sub-option. This option declares the URL that `hg push` should use by default. We require that "pushurl" is an actual URL. This requirement might be controversial and could be dropped if there is opposition. However, objectors should read the complicated code in ui.path.__init__ and commands.push for resolving non-URL values before making a judgement. We also don't allow #fragment in the URLs. I intend to introduce a ":pushrev" (or similar) option to define a revset to control which revisions are pushed when "-r <rev>" isn't passed into `hg push`. This is much more powerful than #fragment and I don't think #fragment is useful enough to continue supporting. The [paths] section of the "config" help page has been updated significantly. `hg paths` has been taught to display path sub-options. The docs mention that "default-push" is now deprecated. However, there are several references to it that need to be cleaned up. A large part of this is converting more consumers to the new paths API. This will happen naturally as more path sub-options are added and more and more components need to access them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11785
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     1
  $ hg init a
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     2
  $ hg clone a b
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     3
  updating to branch default
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     4
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     5
  $ cd a
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     6
  $ echo '[paths]' >> .hg/hgrc
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     7
  $ echo 'dupe = ../b' >> .hg/hgrc
12662
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
     8
  $ echo 'expand = $SOMETHING/bar' >> .hg/hgrc
11785
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
     9
  $ hg in dupe
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    10
  comparing with $TESTTMP/b (glob)
11785
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
    11
  no changes found
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11785
diff changeset
    12
  [1]
11785
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
    13
  $ cd ..
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
    14
  $ hg -R a in dupe
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    15
  comparing with $TESTTMP/b (glob)
11785
7d9be960cd9a tests: unify test-paths
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 5951
diff changeset
    16
  no changes found
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11785
diff changeset
    17
  [1]
12662
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
    18
  $ cd a
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
    19
  $ hg paths
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    20
  dupe = $TESTTMP/b (glob)
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    21
  expand = $TESTTMP/a/$SOMETHING/bar (glob)
12662
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
    22
  $ SOMETHING=foo hg paths
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    23
  dupe = $TESTTMP/b (glob)
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    24
  expand = $TESTTMP/a/foo/bar (glob)
16843
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    25
#if msys
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    26
  $ SOMETHING=//foo hg paths
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    27
  dupe = $TESTTMP/b (glob)
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    28
  expand = /foo/bar
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    29
#else
12662
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
    30
  $ SOMETHING=/foo hg paths
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    31
  dupe = $TESTTMP/b (glob)
12662
7285b2824fb7 ui.paths: expand paths directly in fixconfig (issue2373)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12640
diff changeset
    32
  expand = /foo/bar
16843
61f3ca8e4d39 test-paths.t: enable for Windows using #if
Adrian Buehlmann <adrian@cadifra.com>
parents: 15567
diff changeset
    33
#endif
14331
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    34
  $ hg paths -q
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    35
  dupe
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    36
  expand
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    37
  $ hg paths dupe
15447
9910f60a37ee tests: make (glob) on windows accept \ instead of /
Mads Kiilerich <mads@kiilerich.com>
parents: 14331
diff changeset
    38
  $TESTTMP/b (glob)
14331
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    39
  $ hg paths -q dupe
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    40
  $ hg paths unknown
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    41
  not found!
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    42
  [1]
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    43
  $ hg paths -q unknown
3b9a896af09c paths: Add support for -q/--quiet
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13797
diff changeset
    44
  [1]
13797
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
    45
  $ cd ..
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
    46
27266
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    47
sub-options for an undeclared path are ignored
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    48
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    49
  $ hg init suboptions
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    50
  $ cd suboptions
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    51
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    52
  $ cat > .hg/hgrc << EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    53
  > [paths]
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    54
  > path0 = https://example.com/path0
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    55
  > path1:pushurl = https://example.com/path1
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    56
  > EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    57
  $ hg paths
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    58
  path0 = https://example.com/path0
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    59
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    60
unknown sub-options aren't displayed
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    61
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    62
  $ cat > .hg/hgrc << EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    63
  > [paths]
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    64
  > path0 = https://example.com/path0
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    65
  > path0:foo = https://example.com/path1
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    66
  > EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    67
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    68
  $ hg paths
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    69
  path0 = https://example.com/path0
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    70
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    71
:pushurl must be a URL
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    72
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    73
  $ cat > .hg/hgrc << EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    74
  > [paths]
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    75
  > default = /path/to/nothing
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    76
  > default:pushurl = /not/a/url
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    77
  > EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    78
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    79
  $ hg paths
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    80
  (paths.default:pushurl not a URL; ignoring)
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    81
  default = /path/to/nothing
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    82
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    83
#fragment is not allowed in :pushurl
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    84
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    85
  $ cat > .hg/hgrc << EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    86
  > [paths]
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    87
  > default = https://example.com/repo
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    88
  > invalid = https://example.com/repo
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    89
  > invalid:pushurl = https://example.com/repo#branch
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    90
  > EOF
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    91
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    92
  $ hg paths
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    93
  ("#fragment" in paths.invalid:pushurl not supported; ignoring)
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    94
  default = https://example.com/repo
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    95
  invalid = https://example.com/repo
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    96
  invalid:pushurl = https://example.com/repo
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    97
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    98
  $ cd ..
4dccc37b87bd ui: support declaring path push urls as sub-options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16913
diff changeset
    99
13797
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   100
'file:' disables [paths] entries for clone destination
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   101
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   102
  $ cat >> $HGRCPATH <<EOF
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   103
  > [paths]
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   104
  > gpath1 = http://hg.example.com
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   105
  > EOF
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   106
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   107
  $ hg clone a gpath1
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   108
  abort: cannot create new http repository
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   109
  [255]
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   110
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   111
  $ hg clone a file:gpath1
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   112
  updating to branch default
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   113
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   114
  $ cd gpath1
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   115
  $ hg -q id
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   116
  000000000000
16d5e80876de test-paths.t: 'file:' disables [paths] entries for clone dest
Adrian Buehlmann <adrian@cadifra.com>
parents: 12662
diff changeset
   117
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 16843
diff changeset
   118
  $ cd ..