comparison mercurial/commands.py @ 38280:2ec44160165d

graft: add a new `--stop` flag to stop interrupted graft This patch adds a new flag `--stop` to `hg graft` command which stops the interrupted graft. The `--stop` flag takes back you to the last successful step i.e. it will keep your grafted commits, it will just clear the mergestate and interrupted graft state. The `--stop` is different from `--abort` flag as the latter also undoes all the work done till now which is sometimes not what the user wants. Suppose you grafted a lot of changesets, you encountered conflicts, you resolved them, did `hg graft --continue`, again encountered conflicts, continue, again encountered conflicts. Now you are tired of solving merge conflicts and want to resume this sometimes later. If you use the `--abort` functionality, it will strip your already grafted changesets, making you loose the work you have done resolving merge conflicts. A general goal related to this flag is to add this flag to `rebase` and `histedit` too. The evolve command already has this --stop flag. Tests are added for the new flag. .. feature:: `hg graft` now has a `--stop` flag to stop interrupted graft. Differential Revision: https://phab.mercurial-scm.org/D3668
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 28 May 2018 21:13:32 +0530
parents a8e7ea176437
children 1a05e205832a
comparison
equal deleted inserted replaced
38279:a8e7ea176437 38280:2ec44160165d
2124 2124
2125 @command( 2125 @command(
2126 'graft', 2126 'graft',
2127 [('r', 'rev', [], _('revisions to graft'), _('REV')), 2127 [('r', 'rev', [], _('revisions to graft'), _('REV')),
2128 ('c', 'continue', False, _('resume interrupted graft')), 2128 ('c', 'continue', False, _('resume interrupted graft')),
2129 ('', 'stop', False, _('stop interrupted graft')),
2129 ('e', 'edit', False, _('invoke editor on commit messages')), 2130 ('e', 'edit', False, _('invoke editor on commit messages')),
2130 ('', 'log', None, _('append graft info to log message')), 2131 ('', 'log', None, _('append graft info to log message')),
2131 ('f', 'force', False, _('force graft')), 2132 ('f', 'force', False, _('force graft')),
2132 ('D', 'currentdate', False, 2133 ('D', 'currentdate', False,
2133 _('record the current date as commit date')), 2134 _('record the current date as commit date')),
2214 editor = cmdutil.getcommiteditor(editform='graft', 2215 editor = cmdutil.getcommiteditor(editform='graft',
2215 **pycompat.strkwargs(opts)) 2216 **pycompat.strkwargs(opts))
2216 2217
2217 cont = False 2218 cont = False
2218 graftstate = statemod.cmdstate(repo, 'graftstate') 2219 graftstate = statemod.cmdstate(repo, 'graftstate')
2220 if opts.get('stop'):
2221 if opts.get('continue'):
2222 raise error.Abort(_("cannot use '--continue' and "
2223 "'--stop' together"))
2224 if any((opts.get('edit'), opts.get('log'), opts.get('user'),
2225 opts.get('date'), opts.get('currentdate'),
2226 opts.get('currentuser'), opts.get('rev'))):
2227 raise error.Abort(_("cannot specify any other flag with '--stop'"))
2228 return _stopgraft(ui, repo, graftstate)
2219 if opts.get('continue'): 2229 if opts.get('continue'):
2220 cont = True 2230 cont = True
2221 if revs: 2231 if revs:
2222 raise error.Abort(_("can't specify --continue and revisions")) 2232 raise error.Abort(_("can't specify --continue and revisions"))
2223 # read in unfinished revisions 2233 # read in unfinished revisions
2389 try: 2399 try:
2390 return graftstate.read() 2400 return graftstate.read()
2391 except error.CorruptedState: 2401 except error.CorruptedState:
2392 nodes = repo.vfs.read('graftstate').splitlines() 2402 nodes = repo.vfs.read('graftstate').splitlines()
2393 return {'nodes': nodes} 2403 return {'nodes': nodes}
2404
2405 def _stopgraft(ui, repo, graftstate):
2406 """stop the interrupted graft"""
2407 if not graftstate.exists():
2408 raise error.Abort(_("no interrupted graft found"))
2409 pctx = repo['.']
2410 hg.updaterepo(repo, pctx.node(), True)
2411 graftstate.delete()
2412 ui.status(_("stopped the interrupted graft\n"))
2413 ui.status(_("working directory is now at %s\n") % pctx.hex()[:12])
2414 return 0
2394 2415
2395 @command('grep', 2416 @command('grep',
2396 [('0', 'print0', None, _('end fields with NUL')), 2417 [('0', 'print0', None, _('end fields with NUL')),
2397 ('', 'all', None, _('print all revisions that match')), 2418 ('', 'all', None, _('print all revisions that match')),
2398 ('a', 'text', None, _('treat all files as text')), 2419 ('a', 'text', None, _('treat all files as text')),