Skip to content

Commit

Permalink
Improved Mercurial support
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Apr 10, 2023
1 parent 6ccfa7d commit 560999d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bumpversion/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING, ChainMap, List, Optional, Type, Union
from typing import TYPE_CHECKING, List, MutableMapping, Optional, Type, Union

if TYPE_CHECKING: # pragma: no-coverage
from bumpversion.config import Config
Expand Down Expand Up @@ -89,7 +89,7 @@ def commit_to_scm(
cls,
files: List[Union[str, Path]],
config: "Config",
context: ChainMap,
context: MutableMapping,
extra_args: Optional[List[str]] = None,
dry_run: bool = False,
) -> None:
Expand Down Expand Up @@ -130,7 +130,7 @@ def commit_to_scm(
)

@classmethod
def tag_in_scm(cls, config: "Config", context: ChainMap, dry_run: bool = False) -> None:
def tag_in_scm(cls, config: "Config", context: MutableMapping, dry_run: bool = False) -> None:
"""Tag the current commit in the source code management system."""
sign_tags = config.sign_tags
tag_name = config.tag_name.format(**context)
Expand Down Expand Up @@ -165,7 +165,7 @@ def assert_nondirty(cls) -> None:

if lines:
joined_lines = b"\n".join(lines).decode()
raise DirtyWorkingDirectoryError(f"Git working directory is not clean:\n{joined_lines}")
raise DirtyWorkingDirectoryError(f"Git working directory is not clean:\n\n{joined_lines}")

@classmethod
def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
Expand Down Expand Up @@ -245,7 +245,19 @@ class Mercurial(SourceCodeManager):
@classmethod
def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
"""Return information about the latest tag."""
return SCMInfo(tool=cls)
current_version = None
re_pattern = tag_pattern.replace("*", ".*")
result = subprocess.run(
["hg", "log", "-r", f"tag('re:{re_pattern}')", "--template", "{latesttag}\n"],
text=True,
check=True,
capture_output=True,
)
result.check_returncode()
if result.stdout:
current_version = result.stdout.splitlines(keepends=False)[0].lstrip("v")
is_dirty = len(subprocess.check_output(["hg", "status", "-mard"])) != 0
return SCMInfo(tool=cls, current_version=current_version, dirty=is_dirty)

@classmethod
def assert_nondirty(cls) -> None:
Expand Down

0 comments on commit 560999d

Please sign in to comment.