Commit 199d5e68 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Merged heptapod-stable into support branch

--HG--
branch : heptapod-0-21
......@@ -16,7 +16,7 @@ default:
# but it gives us in particular a working
# recent Mercurial, proper Ruby versions (of course),
# and it should already be present in all runners
image: "registry.heptapod.net/heptapod/ci-images/heptapod-base:oldstable"
image: "registry.heptapod.net/heptapod/ci-images/heptapod-base:stable"
workflow:
rules:
......
......@@ -26,6 +26,11 @@ def parse_gitlab_branch_for_hg(gitlab_branch)
end
end
# true if the given revision is a full hexadecimal changeset hash
def full_hex_hash?(revision)
revision =~ /\A\h{40}\z/
end
# Provide branchmap key for named branch and topic
# Branchmap keys are displayed when using `hg heads`, and can
# be used directly for some operations, notably to address remote
......
......@@ -349,23 +349,37 @@ def hgsha_from_rev(hgrev, path = nil)
# Find the named branch of a Mercurial changeset
def hg_changeset_branch(hgsha)
hg_call(['log', '-r', hgsha, '-T', '{branch}']).first.strip
rescue HgError => e
raise HgError, "Could not get hg branch of changeset #{hgsha}: "\
"#{e.message}"
if Gitlab::Mercurial.full_hex_hash?(hgsha)
begin
hg_call(['log', '--hidden', '-r', hgsha, '-T', '{branch}']).first.strip
rescue HgError => e
raise HgError, "Could not get hg branch of changeset #{hgsha}: "\
"#{e.message}"
end
else
raise HgError, "hg_changeset_branch() is only applicable "\
"to full hexadecimal hashes (got #{hgsha})"
end
end
def hg_changeset_branch_topic(hgsha)
out = hg_call(['log', '-r', hgsha, '-T', '{branch}:{topic}'])
.first.strip
# legacy branches with colons are possible (restriction for all
# names appeared in 2012), topics are not (introduced in 2015)
branch, _sep, topic = out.rpartition(':')
topic = nil if topic.empty? # our general convention
[branch, topic]
rescue HgError => e
raise HgError, "Could not get hg branch and topic "\
"of changeset #{hgsha}: #{e.message}"
if Gitlab::Mercurial.full_hex_hash?(hgsha)
begin
out = hg_call(['log', '--hidden', '-r', hgsha, '-T', '{branch}:{topic}'])
.first.strip
# legacy branches with colons are possible (restriction for all
# names appeared in 2012), topics are not (introduced in 2015)
branch, _sep, topic = out.rpartition(':')
topic = nil if topic.empty? # our general convention
[branch, topic]
rescue HgError => e
raise HgError, "Could not get hg branch and topic "\
"of changeset #{hgsha}: #{e.message}"
end
else
raise HgError, "hg_changeset_branch_topic() is only applicable "\
"to full hexadecimal hashes (got #{hgsha})"
end
end
def hg_env_minimal
......
......@@ -61,11 +61,23 @@
subject.remove
end
it "returns the branch or proper error" do
expect(subject.hg_changeset_branch(subject.hgsha_from_rev('default')))
.to eq('default')
it "returns the branch, even for obsolete changeset, or proper error" do
hgsha = subject.hgsha_from_rev('default')
expect(subject.hg_changeset_branch(hgsha)).to eq('default')
# making changeset obsolete and checking it still works
# for that, we need a proper draft
subject.hg_call(['phase', '-df', hgsha], user: user, for_write: true)
subject.hg_call(['update', hgsha])
subject.hg_call(['amend', '-e', '-m', 'amended'], user: user, for_write: true)
expect(subject.hg_changeset_branch(hgsha)).to eq('default')
# unknown changeset
expect { subject.hg_changeset_branch('0123456789' * 4) }
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError, /Could not get/)
# invalid call
expect { subject.hg_changeset_branch('not-a-sha') }
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError)
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError, /hexadecimal/)
end
end
......@@ -76,7 +88,7 @@
subject.remove
end
it "returns correct branch and (topic or nil)" do
it "returns correct branch and (topic or nil), even for obsolete changeset" do
sha0 = subject.hgsha_from_rev('default')
subject.multi_action(user,
......@@ -92,8 +104,18 @@
expect(subject.hg_changeset_branch_topic(sha0)).to eq(['default', nil])
expect(subject.hg_changeset_branch_topic(sha1)).to eq(%w[default antilope])
# on an obsolete changeset
subject.hg_call(['update', sha1])
subject.hg_call(['amend', '-e', '-m', 'amended'], user: user, for_write: true)
expect(subject.hg_changeset_branch_topic(sha1)).to eq(%w[default antilope])
# unknown changeset
expect { subject.hg_changeset_branch_topic('0123456789' * 4) }
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError, /Could not get/)
# invalid call
expect { subject.hg_changeset_branch_topic('garbage') }
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError)
.to raise_error(Gitlab::Mercurial::HgGitRepository::HgError, /hexadecimal/)
end
end
......
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