Fix pycalver bump for mercurial repos

This commit is contained in:
Manuel Barkhau 2018-12-21 19:51:58 +01:00
parent 57aa1a2ae0
commit fc36f31cb0
2 changed files with 31 additions and 2 deletions

View file

@ -42,7 +42,7 @@ VCS_SUBCOMMANDS_BY_NAME = {
'ls_tags' : "hg tags", 'ls_tags' : "hg tags",
'status' : "hg status -mard", 'status' : "hg status -mard",
'add_path' : "hg add {path}", 'add_path' : "hg add {path}",
'commit' : "hg commit --logfile", 'commit' : "hg commit --logfile {path}",
'tag' : "hg tag {tag} --message {tag}", 'tag' : "hg tag {tag} --message {tag}",
'push_tag' : "hg push {tag}", 'push_tag' : "hg push {tag}",
'show_remotes': "hg paths", 'show_remotes': "hg paths",
@ -122,7 +122,14 @@ class VCS:
def add(self, path: str) -> None: def add(self, path: str) -> None:
"""Add updates to be included in next commit.""" """Add updates to be included in next commit."""
log.info(f"{self.name} add {path}") log.info(f"{self.name} add {path}")
self('add_path', path=path) try:
self('add_path', path=path)
except sp.CalledProcessError as ex:
if "already tracked!" in str(ex):
# mercurial
return
else:
raise
def commit(self, message: str) -> None: def commit(self, message: str) -> None:
"""Commit added files.""" """Commit added files."""

View file

@ -1,5 +1,6 @@
import os import os
import io import io
import time
import shutil import shutil
import pathlib2 as pl import pathlib2 as pl
import subprocess as sp import subprocess as sp
@ -34,11 +35,15 @@ requires = ["setuptools", "wheel"]
def runner(tmpdir): def runner(tmpdir):
runner = CliRunner() runner = CliRunner()
orig_cwd = os.getcwd() orig_cwd = os.getcwd()
os.environ['GIT_AUTHOR_NAME' ] = "pycalver_tester"
os.environ['GIT_AUTHOR_EMAIL'] = "pycalver_tester@nowhere.com"
os.environ['HGUSER' ] = "pycalver_tester"
_debug = 0 _debug = 0
if _debug: if _debug:
tmpdir = pl.Path("..") / "tmp_test_pycalver_project" tmpdir = pl.Path("..") / "tmp_test_pycalver_project"
if tmpdir.exists(): if tmpdir.exists():
time.sleep(0.2)
shutil.rmtree(str(tmpdir)) shutil.rmtree(str(tmpdir))
tmpdir.mkdir() tmpdir.mkdir()
@ -306,3 +311,20 @@ def test_git_bump(runner):
with io.open("README.md") as fh: with io.open("README.md") as fh:
content = fh.read() content = fh.read()
assert calver + ".0002-alpha !\n" in content assert calver + ".0002-alpha !\n" in content
def test_hg_bump(runner):
_add_project_files("README.md")
_vcs_init("hg")
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
assert result.exit_code == 0
result = runner.invoke(pycalver.cli, ['bump', "--verbose"])
assert result.exit_code == 0
calver = config._initial_version()[:7]
with io.open("README.md") as fh:
content = fh.read()
assert calver + ".0002-alpha !\n" in content