Skip to content
Snippets Groups Projects
Commit 6ad456e39e10 authored by Georges Racinet's avatar Georges Racinet
Browse files

New command to assert uniqueness of successor and display it

This will be useful for rebase and fold operations from the Rails
app.

As explained in the docstring, the same result can be obtained with
two successive calls to hg log, together with parsing of results
to refuse ambiguities.

While such a upstream Mercurial or Evolve should provide
a template for this, we'll have a much better robustness with
this fully tested command. Making the call from Rails the simplest
possible has the biggest value for us.
parent dd6fc894d361
No related branches found
No related tags found
No related merge requests found
Pipeline #5418 passed
......@@ -23,6 +23,7 @@
from . import (
topic as topicmod,
git,
obsutil,
)
eh = exthelper.exthelper()
......@@ -118,6 +119,40 @@
git.HeptapodGitHandler(repo, repo.ui).export_commits()
@command(b'hpd-unique-successor',
[(b'r', b'rev', b'', _(b'specified revision'), _(b'REV')),
])
def unique_successor(ui, repo, rev=None, **opts):
"""Display the node ID of the obsolescence successor of REV if unique.
This can be useful after a simple rebase or fold, as a direct way to
find the resulting changeset.
If REV isn't obsolete, the output is REV.
If there is any divergence, the command will fail.
The same functionality can be accomplished with
``hg log -T {successorsets}`` but the latter
1. won't fail on divergence
2. will present as with ``{rev}:{node|short}``, making a second ``hg log``
call necessary to get the full hash.
In the context of the Rails app 1) could be almost acceptable by
detecting multiple results and refusing them (that's already some parsing),
but together with 2) that's too much, we'll have a
better robustness with this simple, fully tested command.
See also: https://foss.heptapod.net/mercurial/evolve/issues/13
"""
if not rev:
raise error.Abort(_(b"Please specify a revision"))
# rev would typically be an obsolete revision, we need to see them
ctx = scmutil.revsingle(repo.unfiltered(), rev)
succ_ctx = obsutil.latest_unique_successor(ctx)
ui.write(succ_ctx.hex())
def runsystem(orig, ui, cmd, environ, cwd, out):
heptapod_env = {k: v for k, v in ui.environ.items()
if k.startswith('HEPTAPOD_')}
......
# Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import absolute_import
from mercurial import (
error,
scmutil,
)
import pytest
from heptapod.testhelpers import (
LocalRepoWrapper,
)
from .utils import common_config
def test_hpd_unique_successor(tmpdir, monkeypatch):
repo_path = tmpdir.join('repo')
wrapper = LocalRepoWrapper.init(repo_path, config=common_config())
ctx = wrapper.write_commit('foo', message="default0",
return_ctx=True)
repo_path.join('foo').write('amend 1')
wrapper.command('amend', message='amend1')
repo_path.join('foo').write('amend 2')
wrapper.command('amend', message='amend2')
records = []
def write(*args, **opts):
records.append((args, opts))
wrapper.repo.ui.write = write
wrapper.command('hpd-unique-successor', rev=ctx.hex())
out = records[0][0][0]
succ_ctx = scmutil.revsingle(wrapper.repo, out)
assert succ_ctx.description() == 'amend2'
def test_hpd_unique_successor_divergence(tmpdir, monkeypatch):
repo_path = tmpdir.join('repo')
config = common_config()
config.setdefault('experimental', {})['evolution.allowdivergence'] = 'yes'
wrapper = LocalRepoWrapper.init(repo_path, config=config)
ctx = wrapper.write_commit('foo', message="default0",
return_ctx=True)
repo_path.join('foo').write('amend 1')
wrapper.command('amend', message='amend1')
# let's create the divergence
wrapper.update(ctx.hex(), hidden=True)
repo_path.join('foo').write('amend 2')
wrapper.command('amend', message='amend2')
with pytest.raises(error.Abort) as exc_info:
wrapper.command('hpd-unique-successor', rev=ctx.hex())
assert 'divergent' in exc_info.value.args[0]
def test_hpd_unique_successor_missing_rev(tmpdir, monkeypatch):
repo_path = tmpdir.join('repo')
wrapper = LocalRepoWrapper.init(repo_path, config=common_config())
with pytest.raises(error.Abort) as exc_info:
wrapper.command('hpd-unique-successor')
assert 'specify a revision' in exc_info.value.args[0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment