Skip to content

Commit c473cd7

Browse files
Merge pull request #220 from avirshup/master
Fix #219
2 parents 632b02b + 4263f57 commit c473cd7

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

setuptools_scm/hg.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
def _hg_tagdist_normalize_tagcommit(root, tag, dist, node):
99
dirty = node.endswith('+')
1010
node = 'h' + node.strip('+')
11-
revset = ("(branch(.) and tag({tag!r})::. and file('re:^(?!\.hgtags).*$')"
12-
" - tag({tag!r}))").format(tag=tag)
11+
12+
# Detect changes since the specified tag
13+
revset = ("(branch(.)" # look for revisions in this branch only
14+
" and tag({tag!r})::." # after the last tag
15+
# ignore commits that only modify .hgtags and nothing else:
16+
" and (merge() or file('re:^(?!\.hgtags).*$'))"
17+
" and not tag({tag!r}))" # ignore the tagged commit itself
18+
).format(tag=tag)
1319
if tag != '0.0':
1420
commits = do(['hg', 'log', '-r', revset, '--template', '{node|short}'],
1521
root)

testing/test_mercurial.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,47 @@ def test_version_in_merge(wd):
108108
def test_parse_no_worktree(tmpdir):
109109
ret = parse(str(tmpdir))
110110
assert ret is None
111+
112+
113+
@pytest.fixture
114+
def version_1_0(wd):
115+
wd('hg branch default')
116+
wd.commit_testfile()
117+
wd('hg tag 1.0 -u test -d "0 0"')
118+
return wd
119+
120+
121+
@pytest.fixture
122+
def pre_merge_commit_after_tag(wd, version_1_0):
123+
wd('hg branch testbranch')
124+
wd.write('branchfile', 'branchtext')
125+
wd(wd.add_command)
126+
wd.commit()
127+
wd('hg update default')
128+
wd('hg merge testbranch')
129+
return wd
130+
131+
132+
@pytest.mark.usefixtures("pre_merge_commit_after_tag")
133+
def test_version_bump_before_merge_commit(wd):
134+
assert wd.version.startswith('1.1.dev1+')
135+
136+
137+
@pytest.mark.issue(219)
138+
@pytest.mark.usefixtures("pre_merge_commit_after_tag")
139+
def test_version_bump_from_merge_commit(wd):
140+
wd.commit()
141+
assert wd.version.startswith('1.1.dev3+') # issue 219
142+
143+
144+
@pytest.mark.usefixtures("version_1_0")
145+
def test_version_bump_from_commit_including_hgtag_mods(wd):
146+
""" Test the case where a commit includes changes to .hgtags and other files
147+
"""
148+
with wd.cwd.join('.hgtags').open('a') as tagfile:
149+
tagfile.write('0 0\n')
150+
wd.write('branchfile', 'branchtext')
151+
wd(wd.add_command)
152+
assert wd.version.startswith('1.1.dev1+') # bump from dirty version
153+
wd.commit() # commits both the testfile _and_ .hgtags
154+
assert wd.version.startswith('1.1.dev2+')

0 commit comments

Comments
 (0)