diff --git a/src/pycalver/vcs.py b/src/pycalver/vcs.py index 9176a81..816ea94 100644 --- a/src/pycalver/vcs.py +++ b/src/pycalver/vcs.py @@ -42,7 +42,7 @@ VCS_SUBCOMMANDS_BY_NAME = { 'ls_tags' : "hg tags", 'status' : "hg status -mard", 'add_path' : "hg add {path}", - 'commit' : "hg commit --logfile", + 'commit' : "hg commit --logfile {path}", 'tag' : "hg tag {tag} --message {tag}", 'push_tag' : "hg push {tag}", 'show_remotes': "hg paths", @@ -122,7 +122,14 @@ class VCS: def add(self, path: str) -> None: """Add updates to be included in next commit.""" 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: """Commit added files.""" diff --git a/test/test_cli.py b/test/test_cli.py index b287a0d..1ee3413 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1,5 +1,6 @@ import os import io +import time import shutil import pathlib2 as pl import subprocess as sp @@ -34,11 +35,15 @@ requires = ["setuptools", "wheel"] def runner(tmpdir): runner = CliRunner() 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 if _debug: tmpdir = pl.Path("..") / "tmp_test_pycalver_project" if tmpdir.exists(): + time.sleep(0.2) shutil.rmtree(str(tmpdir)) tmpdir.mkdir() @@ -306,3 +311,20 @@ def test_git_bump(runner): with io.open("README.md") as fh: content = fh.read() 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