Commit e63534a9 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

HgGitRepository: low level hg_tag method

This is for now mostly intended as a helper for tests.
We're using one of the HGitaly tags test to make sure it works,
and in turn that test gets simplified.

There's a catch: `hg_git_repository.hg_tag` would not
work before `subject` has been used at least once, so that the
repository is indeed initialized on disk.
If we were in need to use `hg_git_repository` here, we'd have
to switch to `subject!` instead of just `subject`.

branch : heptapod
parent 23e38611a8c3
......@@ -454,6 +454,32 @@ def hg_commit(path, username, message, env, add_remove = false)
hgsha_from_rev('.', path)
# Low level method to create a tag.
# This is *not* meant to be a full override of Git::Repository::tag.
# Returns the Node ID of the tagging commit.
# Optional parameters:
# - env: allows to reuse a Hash of environment variables.
# If not specified, the standard one for given user is computed
# - tag_parent_revision: (tags have to be created on repository heads)
# A revision to update the workdir to, before creating the tag.
# It will indeed be the parent of the tagging commit.
def hg_tag(user, tag_name, revision, env: nil, tag_parent_revision: "default")
env = hg_env_for_write(user) if env.nil?
username = hg_prepare_user_encoding(env, user, "")
hg_tmp_workdir(tag_parent_revision) do |share_path|
cmd = [Gitlab.config.mercurial.bin_path,
'tag', tag_name,
'--config', 'ui.username=' + username]
output, status = popen(cmd, share_path, env)
raise HgError, "Could not tag (status code #{status}): #{output}" unless status == 0
hgsha_from_rev('.', share_path)
def has_tmp_workdir?(prefix)
......@@ -110,15 +110,8 @@
it 'returns the correct list after repository seeding' do
subject.hg_tag(user, "v1.0", "default")
# long-term form of assertion
hg_env = subject.hg_env_for_write(user)
output, status = popen(
[Gitlab.config.mercurial.bin_path, "up",
], repository_path, hg_env)
output, status = popen(
"tag", "v1.0",
], repository_path, hg_env)
tags =
expect(tags).to eq(["v1.0"])
# consistency with HgGitRepository
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