|
9 | 9 | from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, MutableMapping, Optional, Type, Union
|
10 | 10 |
|
11 | 11 | from bumpversion.ui import get_indented_logger
|
12 |
| -from bumpversion.utils import extract_regex_flags, run_command |
| 12 | +from bumpversion.utils import extract_regex_flags, format_and_raise_error, run_command |
13 | 13 |
|
14 | 14 | if TYPE_CHECKING: # pragma: no-coverage
|
15 | 15 | from bumpversion.config import Config
|
16 | 16 |
|
17 |
| -from bumpversion.exceptions import BumpVersionError, DirtyWorkingDirectoryError, SignedTagsError |
| 17 | +from bumpversion.exceptions import DirtyWorkingDirectoryError, SignedTagsError |
18 | 18 |
|
19 | 19 | logger = get_indented_logger(__name__)
|
20 | 20 |
|
@@ -53,7 +53,7 @@ def path_in_repo(self, path: Union[Path, str]) -> bool:
|
53 | 53 | if self.repository_root is None:
|
54 | 54 | return True
|
55 | 55 |
|
56 |
| - return Path(path).is_relative_to(self.repository_root) |
| 56 | + return str(path).startswith(str(self.repository_root)) |
57 | 57 |
|
58 | 58 |
|
59 | 59 | class SourceCodeManager:
|
@@ -93,14 +93,7 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
|
93 | 93 | @classmethod
|
94 | 94 | def format_and_raise_error(cls, exc: Union[TypeError, subprocess.CalledProcessError]) -> None:
|
95 | 95 | """Format the error message from an exception and re-raise it as a BumpVersionError."""
|
96 |
| - if isinstance(exc, subprocess.CalledProcessError): |
97 |
| - output = "\n".join([x for x in [exc.stdout.decode("utf8"), exc.stderr.decode("utf8")] if x]) |
98 |
| - cmd = " ".join(exc.cmd) |
99 |
| - err_msg = f"Failed to run `{cmd}`: return code {exc.returncode}, output: {output}" |
100 |
| - else: # pragma: no-coverage |
101 |
| - err_msg = f"Failed to run {cls._COMMIT_COMMAND}: {exc}" |
102 |
| - logger.exception(err_msg) |
103 |
| - raise BumpVersionError(err_msg) from exc |
| 96 | + format_and_raise_error(exc) |
104 | 97 |
|
105 | 98 | @classmethod
|
106 | 99 | def is_usable(cls) -> bool:
|
@@ -355,8 +348,14 @@ def _revision_info(cls) -> dict:
|
355 | 348 | def add_path(cls, path: Union[str, Path]) -> None:
|
356 | 349 | """Add a path to the VCS."""
|
357 | 350 | info = SCMInfo(**cls._revision_info())
|
358 |
| - if info.path_in_repo(path): |
359 |
| - run_command(["git", "add", "--update", str(path)]) |
| 351 | + if not info.path_in_repo(path): |
| 352 | + return |
| 353 | + cwd = Path.cwd() |
| 354 | + temp_path = os.path.relpath(path, cwd) |
| 355 | + try: |
| 356 | + run_command(["git", "add", "--update", str(temp_path)]) |
| 357 | + except subprocess.CalledProcessError as e: |
| 358 | + format_and_raise_error(e) |
360 | 359 |
|
361 | 360 | @classmethod
|
362 | 361 | def tag(cls, name: str, sign: bool = False, message: Optional[str] = None) -> None:
|
|
0 commit comments