Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions setuptools_scm/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ def parse(root):
trace('initial node', root)
return meta('0.0', dirty=dirty)

# the newline is needed for merge stae, see issue 72
cmd = 'hg parents --template "{latesttag} {latesttagdistance}\n"'
out = do(cmd, root)
try:
# in merge state we assume parent 1 is fine
tags, dist = out.splitlines()[0].split()
# pick latest tag from tag list
tag = tags.split(':')[-1]
tag = get_latest_normalizable_tag(root)
dist = get_graph_distance(root, tag)
if tag == 'null':
tag = '0.0'
dist = int(dist) + 1
Expand All @@ -62,6 +57,23 @@ def parse(root):
pass # unpacking failed, old hg


def get_latest_normalizable_tag(root):
# Gets all tags containing a '.' (see #229) from oldest to newest
cmd = ['hg', 'log',
'-r', "ancestors(.) and tag('re:\.')", '--template', "{tags}\n"]
outlines = do(cmd, root).split()
if not outlines:
return 'null'
tag = outlines[-1].split()[-1]
return tag


def get_graph_distance(root, rev1, rev2='.'):
cmd = ['hg', 'log', '-q', '-r', '%s::%s' % (rev1, rev2)]
out = do(cmd, root)
return len(out.strip().splitlines()) - 1


def archival_to_version(data):
trace('data', data)
node = data.get('node', '')[:12]
Expand Down
10 changes: 10 additions & 0 deletions testing/test_mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,13 @@ def test_version_bump_from_commit_including_hgtag_mods(wd):
assert wd.version.startswith('1.1.dev1+') # bump from dirty version
wd.commit() # commits both the testfile _and_ .hgtags
assert wd.version.startswith('1.1.dev2+')


@pytest.mark.issue(229)
@pytest.mark.usefixtures("version_1_0")
def test_latest_tag_detection(wd):
""" Tests that tags not containing a "." are ignored, the same as for git.
Note that will be superceded by the fix for pypa/setuptools_scm/issues/235
"""
wd('hg tag some-random-tag')
assert wd.version == '1.0'