|
6 | 6 | from dataclasses import dataclass
|
7 | 7 | from pathlib import Path
|
8 | 8 | from tempfile import NamedTemporaryFile
|
9 |
| -from typing import TYPE_CHECKING, ChainMap, List, Optional, Type, Union |
| 9 | +from typing import TYPE_CHECKING, List, MutableMapping, Optional, Type, Union |
10 | 10 |
|
11 | 11 | if TYPE_CHECKING: # pragma: no-coverage
|
12 | 12 | from bumpversion.config import Config
|
@@ -89,7 +89,7 @@ def commit_to_scm(
|
89 | 89 | cls,
|
90 | 90 | files: List[Union[str, Path]],
|
91 | 91 | config: "Config",
|
92 |
| - context: ChainMap, |
| 92 | + context: MutableMapping, |
93 | 93 | extra_args: Optional[List[str]] = None,
|
94 | 94 | dry_run: bool = False,
|
95 | 95 | ) -> None:
|
@@ -130,7 +130,7 @@ def commit_to_scm(
|
130 | 130 | )
|
131 | 131 |
|
132 | 132 | @classmethod
|
133 |
| - def tag_in_scm(cls, config: "Config", context: ChainMap, dry_run: bool = False) -> None: |
| 133 | + def tag_in_scm(cls, config: "Config", context: MutableMapping, dry_run: bool = False) -> None: |
134 | 134 | """Tag the current commit in the source code management system."""
|
135 | 135 | sign_tags = config.sign_tags
|
136 | 136 | tag_name = config.tag_name.format(**context)
|
@@ -165,7 +165,7 @@ def assert_nondirty(cls) -> None:
|
165 | 165 |
|
166 | 166 | if lines:
|
167 | 167 | joined_lines = b"\n".join(lines).decode()
|
168 |
| - raise DirtyWorkingDirectoryError(f"Git working directory is not clean:\n{joined_lines}") |
| 168 | + raise DirtyWorkingDirectoryError(f"Git working directory is not clean:\n\n{joined_lines}") |
169 | 169 |
|
170 | 170 | @classmethod
|
171 | 171 | def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
|
@@ -245,7 +245,19 @@ class Mercurial(SourceCodeManager):
|
245 | 245 | @classmethod
|
246 | 246 | def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
|
247 | 247 | """Return information about the latest tag."""
|
248 |
| - return SCMInfo(tool=cls) |
| 248 | + current_version = None |
| 249 | + re_pattern = tag_pattern.replace("*", ".*") |
| 250 | + result = subprocess.run( |
| 251 | + ["hg", "log", "-r", f"tag('re:{re_pattern}')", "--template", "{latesttag}\n"], |
| 252 | + text=True, |
| 253 | + check=True, |
| 254 | + capture_output=True, |
| 255 | + ) |
| 256 | + result.check_returncode() |
| 257 | + if result.stdout: |
| 258 | + current_version = result.stdout.splitlines(keepends=False)[0].lstrip("v") |
| 259 | + is_dirty = len(subprocess.check_output(["hg", "status", "-mard"])) != 0 |
| 260 | + return SCMInfo(tool=cls, current_version=current_version, dirty=is_dirty) |
249 | 261 |
|
250 | 262 | @classmethod
|
251 | 263 | def assert_nondirty(cls) -> None:
|
|
0 commit comments