Skip to content

Commit dfcebb2

Browse files
committed
fix mercurial for several tags on changeset and distance only consisting of tag commits
1 parent 570f7f5 commit dfcebb2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

setuptools_scm/hg.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
def _hg_tagdist_normalize_tagcommit(root, tag, dist, node):
99
dirty = node.endswith('+')
1010
node = node.strip('+')
11-
st = do('hg st --no-status --change %s' % str(node), root)
12-
13-
trace('normalize', locals())
14-
if int(dist) == 1 and st == '.hgtags' and not dirty:
15-
return meta(tag)
11+
revset = ("(branch(.) and tag('{0}')::. and file('re:^(?!\.hgtags).*$')"
12+
" - tag('{0}'))").format(str(tag))
13+
if tag != '0.0':
14+
commits = do(['hg', 'log', '-r', revset, '-T', '{node|short}'],
15+
root)
1616
else:
17+
commits = True
18+
trace('normalize', locals())
19+
if commits or dirty:
1720
return meta(tag, distance=dist, node=node, dirty=dirty)
21+
else:
22+
return meta(tag)
1823

1924

2025
def parse(root):
@@ -36,7 +41,9 @@ def parse(root):
3641
out = do(cmd, root)
3742
try:
3843
# in merge state we assume parent 1 is fine
39-
tag, dist = out.splitlines()[0].split()
44+
tags, dist = out.splitlines()[0].split()
45+
# pick latest tag from tag list
46+
tag = tags.split(':')[-1]
4047
if tag == 'null':
4148
tag = '0.0'
4249
dist = int(dist) + 1

testing/test_mercurial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def test_version_from_hg_id(wd):
6565
wd.commit_testfile()
6666
assert wd.version.startswith('0.2.dev1+')
6767

68+
# several tags
69+
wd('hg up')
70+
wd('hg tag v0.2 -u test -d "0 0"')
71+
wd('hg tag v0.3 -u test -d "0 0" -r v0.2')
72+
assert wd.version == '0.3'
73+
6874

6975
def test_version_from_archival(wd):
7076
# entrypoints are unordered,

0 commit comments

Comments
 (0)