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