tests/test-state-extension.t
author Simon Sapin <simon.sapin@octobus.net>
Wed, 22 Sep 2021 11:33:29 +0200
changeset 48044 d5528ac9b4f2
parent 45826 21733e8c924f
permissions -rw-r--r--
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled … instead of the C implementation, with C/Rust conversions at the FFI boundary Differential Revision: https://phab.mercurial-scm.org/D11486
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45171
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     1
Test extension of unfinished states support.
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     2
  $ mkdir chainify
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     3
  $ cd chainify
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     4
  $ cat >> chainify.py <<EOF
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     5
  > from mercurial import cmdutil, error, extensions, exthelper, node, scmutil, state
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     6
  > from hgext import rebase
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     7
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     8
  > eh = exthelper.exthelper()
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
     9
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    10
  > extsetup = eh.finalextsetup
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    11
  > cmdtable = eh.cmdtable
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    12
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    13
  > # Rebase calls addunfinished in uisetup, so we have to call it in extsetup.
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    14
  > # Ideally there'd by an 'extensions.afteruisetup()' just like
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    15
  > # 'extensions.afterloaded()' to allow nesting multiple commands.
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    16
  > @eh.extsetup
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    17
  > def _extsetup(ui):
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    18
  >     state.addunfinished(
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    19
  >         b'chainify',
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    20
  >         b'chainify.state',
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    21
  >         continueflag=True,
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    22
  >         childopnames=[b'rebase'])
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    23
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    24
  > def _node(repo, arg):
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    25
  >     return node.hex(scmutil.revsingle(repo, arg).node())
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    26
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    27
  > @eh.command(
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    28
  >     b'chainify',
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    29
  >     [(b'r', b'revs', [], b'revs to chain', b'REV'),
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    30
  >      (b'', b'continue', False, b'continue op')],
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    31
  >     b'chainify [-r REV] +',
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    32
  >     inferrepo=True)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    33
  > def chainify(ui, repo, **opts):
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    34
  >     """Rebases r1, r2, r3, etc. into a chain."""
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    35
  >     with repo.wlock(), repo.lock():
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    36
  >         cmdstate = state.cmdstate(repo, b'chainify.state')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    37
  >         if opts['continue']:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    38
  >             if not cmdstate.exists():
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    39
  >                 raise error.Abort(b'no chainify in progress')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    40
  >         else:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    41
  >             cmdutil.checkunfinished(repo)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    42
  >             data = {
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    43
  >                 b'tip': _node(repo, opts['revs'][0]),
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    44
  >                 b'revs': b','.join(_node(repo, r) for r in opts['revs'][1:]),
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    45
  >             }
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    46
  >             cmdstate.save(1, data)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    47
  > 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    48
  >         data = cmdstate.read()
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    49
  >         while data[b'revs']:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    50
  >             tip = data[b'tip']
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    51
  >             revs = data[b'revs'].split(b',')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    52
  >             with state.delegating(repo, b'chainify', b'rebase'):
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    53
  >                 ui.status(b'rebasing %s onto %s\n' % (revs[0][:12], tip[:12]))
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    54
  >                 if state.ischildunfinished(repo, b'chainify', b'rebase'):
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    55
  >                     rc = state.continuechild(ui, repo, b'chainify', b'rebase')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    56
  >                 else:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    57
  >                     rc = rebase.rebase(ui, repo, rev=[revs[0]], dest=tip)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    58
  >                 if rc and rc != 0:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    59
  >                     raise error.Abort(b'rebase failed (rc: %d)' % rc)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    60
  >             data[b'tip'] = _node(repo, b'tip')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    61
  >             data[b'revs'] = b','.join(revs[1:])
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    62
  >             cmdstate.save(1, data)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    63
  >         cmdstate.delete()
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    64
  >         ui.status(b'done chainifying\n')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    65
  > EOF
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    66
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    67
  $ chainifypath=`pwd`/chainify.py
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    68
  $ echo '[extensions]' >> $HGRCPATH
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    69
  $ echo "chainify = $chainifypath" >> $HGRCPATH
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    70
  $ echo "rebase =" >> $HGRCPATH
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    71
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    72
  $ cd $TESTTMP
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    73
  $ hg init a
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    74
  $ cd a
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    75
  $ echo base > base.txt
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    76
  $ hg commit -Aqm 'base commit'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    77
  $ echo foo > file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    78
  $ hg commit -Aqm 'add file'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    79
  $ hg co -q ".^"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    80
  $ echo bar > file2
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    81
  $ hg commit -Aqm 'add other file'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    82
  $ hg co -q ".^"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    83
  $ echo foo2 > file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    84
  $ hg commit -Aqm 'add conflicting file'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    85
  $ hg co -q ".^"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    86
  $ hg log --graph --template '{rev} {files}'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    87
  o  3 file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    88
  |
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    89
  | o  2 file2
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    90
  |/
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    91
  | o  1 file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    92
  |/
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    93
  @  0 base.txt
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    94
  
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    95
  $ hg chainify -r 8430cfdf77c2 -r f8596309dff8 -r a858b338b3e9
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    96
  rebasing f8596309dff8 onto 8430cfdf77c2
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    97
  rebasing 2:f8596309dff8 "add other file"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    98
  saved backup bundle to $TESTTMP/* (glob)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
    99
  rebasing a858b338b3e9 onto 83c722183a8e
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   100
  rebasing 2:a858b338b3e9 "add conflicting file"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   101
  merging file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   102
  warning: conflicts while merging file1! (edit, then use 'hg resolve --mark')
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   103
  unresolved conflicts (see 'hg resolve', then 'hg chainify --continue')
45826
21733e8c924f errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents: 45171
diff changeset
   104
  [240]
45171
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   105
  $ hg status --config commands.status.verbose=True
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   106
  M file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   107
  ? file1.orig
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   108
  # The repository is in an unfinished *chainify* state.
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   109
  
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   110
  # Unresolved merge conflicts:
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   111
  # 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   112
  #     file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   113
  # 
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   114
  # To mark files as resolved:  hg resolve --mark FILE
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   115
  
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   116
  # To continue:    hg chainify --continue
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   117
  # To abort:       hg chainify --abort
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   118
  
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   119
  $ echo foo3 > file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   120
  $ hg resolve --mark file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   121
  (no more unresolved files)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   122
  continue: hg chainify --continue
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   123
  $ hg chainify --continue
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   124
  rebasing a858b338b3e9 onto 83c722183a8e
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   125
  rebasing 2:a858b338b3e9 "add conflicting file"
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   126
  saved backup bundle to $TESTTMP/* (glob)
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   127
  done chainifying
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   128
  $ hg log --graph --template '{rev} {files}'
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   129
  o  3 file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   130
  |
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   131
  o  2 file2
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   132
  |
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   133
  o  1 file1
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   134
  |
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   135
  @  0 base.txt
5322e738be0f state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
diff changeset
   136