comparison mercurial/cmdutil.py @ 28120:ed4d06f180b8

cmdutil: provide a way to report how to continue checkafterresolved allows Mercurial to suggest what command to use next. If users try to continue the wrong command, there wasn't a good way for the command to suggest what to do next. Split checkmdutil into howtocontinue and checkafterresolved. Introduce wrongtooltocontinue which handles raising an Abort with the hint from howtocontinue.
author timeless <timeless@mozdev.org>
date Sun, 14 Feb 2016 16:16:17 +0000
parents 14033c5dd261
children 7623ba92af72
comparison
equal deleted inserted replaced
28119:91a827e760df 28120:ed4d06f180b8
3345 afterresolvedstates = [ 3345 afterresolvedstates = [
3346 ('graftstate', 3346 ('graftstate',
3347 _('hg graft --continue')), 3347 _('hg graft --continue')),
3348 ] 3348 ]
3349 3349
3350 def checkafterresolved(repo): 3350 def howtocontinue(repo):
3351 contmsg = _("continue: %s\n") 3351 '''Check for an unfinished operation and return the command to finish
3352 it.
3353
3354 afterresolvedstates tupples define a .hg/{file} and the corresponding
3355 command needed to finish it.
3356
3357 Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is
3358 a boolean.
3359 '''
3360 contmsg = _("continue: %s")
3352 for f, msg in afterresolvedstates: 3361 for f, msg in afterresolvedstates:
3353 if repo.vfs.exists(f): 3362 if repo.vfs.exists(f):
3354 repo.ui.warn(contmsg % msg) 3363 return contmsg % msg, True
3355 return 3364 workingctx = repo[None]
3356 repo.ui.note(contmsg % _("hg commit")) 3365 dirty = any(repo.status()) or any(workingctx.sub(s).dirty()
3366 for s in workingctx.substate)
3367 if dirty:
3368 return contmsg % _("hg commit"), False
3369 return None, None
3370
3371 def checkafterresolved(repo):
3372 '''Inform the user about the next action after completing hg resolve
3373
3374 If there's a matching afterresolvedstates, howtocontinue will yield
3375 repo.ui.warn as the reporter.
3376
3377 Otherwise, it will yield repo.ui.note.
3378 '''
3379 msg, warning = howtocontinue(repo)
3380 if msg is not None:
3381 if warning:
3382 repo.ui.warn("%s\n" % msg)
3383 else:
3384 repo.ui.note("%s\n" % msg)
3385
3386 def wrongtooltocontinue(repo, task):
3387 '''Raise an abort suggesting how to properly continue if there is an
3388 active task.
3389
3390 Uses howtocontinue() to find the active task.
3391
3392 If there's no task (repo.ui.note for 'hg commit'), it does not offer
3393 a hint.
3394 '''
3395 after = howtocontinue(repo)
3396 hint = None
3397 if after[1]:
3398 hint = after[0]
3399 raise error.Abort(_('no %s in progress') % task, hint=hint)
3357 3400
3358 class dirstateguard(object): 3401 class dirstateguard(object):
3359 '''Restore dirstate at unexpected failure. 3402 '''Restore dirstate at unexpected failure.
3360 3403
3361 At the construction, this class does: 3404 At the construction, this class does: