This instance will be upgraded to Heptapod 0.23.2 on 2021-08-05 at 11:00 UTC+2 (a few minutes of down time)

Commit 019e54d0 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

amend: abort if amending s0 with a different topic

This patch fixes issue of silently changing topic when amending on s0
(base of a topic stack) by aborting in that case. So now if you amend
s0 with a topic which is different from wdir parent it won't let you
amend until you update to the topic of wdir parent.

Changes in test file reflect the added behavior.
parent 098aa7a02356
Pipeline #16972 passed with stage
in 4 minutes and 47 seconds
......@@ -125,10 +125,12 @@ def amend(ui, repo, *pats, **opts):
if opts.get('patch') and opts.get('extract'):
raise error.Abort(_(b'cannot use both --patch and --extract'))
if opts.get('patch'):
precheck_s0_amendment(repo)
return amendpatch(ui, repo, *pats, **opts)
if opts.get('extract'):
return uncommit(ui, repo, *pats, **opts)
else:
precheck_s0_amendment(repo)
if opts.pop('all', False):
# add an include for all
include = list(opts.get('include'))
......@@ -144,6 +146,20 @@ def amend(ui, repo, *pats, **opts):
rewriteutil.precheck(repo, [repo[b'.'].rev()], action=b'amend')
return commitcmd[0](ui, repo, *pats, **opts)
def precheck_s0_amendment(repo):
wdp = repo[b'.']
if not util.safehasattr(wdp, 'topic'):
return
activetopic = getattr(repo, 'currenttopic', b'')
if not activetopic:
return
childtopics = [ctx.topic() for ctx in wdp.children() if ctx.topic()]
if activetopic in childtopics and activetopic != wdp.topic():
# amending on s0
hint = _(b"run 'hg update .' to checkout topic of working copy parent, if any")
raise error.Abort(_(b'cannot amend on stack base with current active topic'),
hint=hint)
def amendpatch(ui, repo, *pats, **opts):
"""logic for --patch flag of `hg amend` command."""
with repo.wlock(), repo.lock(), repo.transaction(b'amend') as tr:
......
......@@ -1059,10 +1059,20 @@ case amending on s0
[0] c_a
$ echo aa > a
$ hg amend
abort: cannot amend on stack base with current active topic
(run 'hg update .' to checkout topic of working copy parent, if any)
[255]
$ hg log --graph
o 1 default {feature} draft c_b
|
@ 0 default {} draft c_a
$ hg up .
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg amend
1 new orphan changesets
$ hg log --graph
@ 2 default {feature} draft c_a
@ 2 default {} draft c_a
* 1 default {feature} draft c_b
|
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment