@@ -2819,7 +2819,10 @@ def stripwrapper(orig, ui, repo, *revs,
@command('^touch',
[('r', 'rev', [], 'revision to update'),
('D', 'duplicate', False,
- 'do not mark the new revision as successor of the old one')],
+ 'do not mark the new revision as successor of the old one'),
+ ('A', 'allowdivergence', False,
+ 'mark the new revision as successor of the old one potentially creating '
+ 'divergence')],
# allow to choose the seed ?
_('[-r] revs'))
def touch(ui, repo, *revs, **opts):
@@ -2829,6 +2832,7 @@ def touch(ui, repo, *revs, **opts):
This is used to "resurrect" changesets
"""
duplicate = opts['duplicate']
+ allowdivergence = opts['allowdivergence']
revs = list(revs)
revs.extend(opts['rev'])
if not revs:
@@ -2839,6 +2843,7 @@ def touch(ui, repo, *revs, **opts):
return 1
if not duplicate and repo.revs('public() and %ld', revs):
raise error.Abort("can't touch public revision")
+ displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
wlock = lock = tr = None
try:
wlock = repo.wlock()
@@ -2855,11 +2860,37 @@ def touch(ui, repo, *revs, **opts):
p2 = ctx.p2().node()
p1 = newmapping.get(p1, p1)
p2 = newmapping.get(p2, p2)
+
+ if not (duplicate or allowdivergence):
+ # The user hasn't yet decided what to do with the revived
+ # cset, let's ask
+ sset = obsolete.successorssets(repo, ctx.node())
+ nodivergencerisk = len(sset) == 0 or (
+ len(sset) == 1 and
+ len(sset[0]) == 1 and
+ repo[sset[0][0]].rev() == ctx.rev()
+ )
+ if nodivergencerisk:
+ duplicate = False
+ else:
+ displayer.show(ctx)
+ index = ui.promptchoice(
+ _("reviving this changeset will create divergence"
+ " unless you make a duplicate.\n(a)llow divergence or"
+ " (d)uplicate the changeset? $$ &Allowdivergence $$ "
+ "&Duplicate"), 0)
+ choice = ['allowdivergence', 'duplicate'][index]
+ if choice == 'allowdivergence':
+ duplicate = False
+ else:
+ duplicate = True
+
new, unusedvariable = rewrite(repo, ctx, [], ctx,
[p1, p2],
commitopts={'extra': extra})
# store touched version to help potential children
newmapping[ctx.node()] = new
+
if not duplicate:
obsolete.createmarkers(repo, [(ctx, (repo[new],))])
phases.retractboundary(repo, tr, ctx.phase(), [new])
@@ -41,6 +41,9 @@ Revive usage
@ 1:[0-9a-f]{12} a (re)
$ hg touch .
+ [1] a
+ reviving this changeset will create divergence unless you make a duplicate.
+ (a)llow divergence or (d)uplicate the changeset? a
2 new divergent changesets
$ hg log -G
@ 4:[0-9a-f]{12} a (re)
@@ -110,3 +113,15 @@ check move data kept after rebase on tou
A gna2
gna1
R gna1
+
+check that the --duplicate option does not create divergence
+
+ $ hg touch --duplicate 11 --hidden
+ 1 new unstable changesets
+
+check that reviving a changeset with no successor does not show the prompt
+
+ $ hg prune 14
+ 1 changesets pruned
+ $ hg touch 14 --hidden
+ 1 new unstable changesets