Skip to content

Commit

Permalink
Added --ignore-missing-files option to bump
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Feb 11, 2024
1 parent b473a19 commit fcfaac7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def cli(ctx: Context) -> None:
"--search",
"--replace",
"--no-configured-files",
"--ignore-missing-files",
"--ignore-missing-version",
],
},
Expand Down Expand Up @@ -160,6 +161,12 @@ def cli(ctx: Context) -> None:
"ignoring the files from the configuration file."
),
)
@click.option(
"--ignore-missing-files",
is_flag=True,
envvar="BUMPVERSION_IGNORE_MISSING_FILES",
help="Ignore any missing files when searching and replacing in files.",
)
@click.option(
"--ignore-missing-version",
is_flag=True,
Expand Down Expand Up @@ -240,6 +247,7 @@ def bump(
replace: Optional[str],
regex: Optional[bool],
no_configured_files: bool,
ignore_missing_files: bool,
ignore_missing_version: bool,
dry_run: bool,
commit: Optional[bool],
Expand All @@ -256,7 +264,7 @@ def bump(
ARGS may contain any of the following:
VERSION_PART is the part of the version to increase, e.g. `minor` .
VERSION_PART is the part of the version to increase, e.g. `minor`.
Valid values include those given in the `--serialize` / `--parse` option.
FILES are additional file(s) to modify.
Expand All @@ -281,6 +289,7 @@ def bump(
tag_message=tag_message,
message=message,
commit_args=commit_args,
ignore_missing_files=ignore_missing_files,
ignore_missing_version=ignore_missing_version,
regex=regex,
)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_cli/test_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import shutil
import subprocess
import traceback
from datetime import datetime
from pathlib import Path

Expand Down Expand Up @@ -350,3 +351,41 @@ def test_detects_bad_or_missing_version_part(version_part: str, tmp_path: Path,
# Assert
assert result.exception is not None
assert "Unknown version part:" in result.stdout


def test_ignores_missing_files_with_option(tmp_path, fixtures_path):
"""The replace subcommand should ignore missing."""

config_file = tmp_path / ".bumpversion.toml"
config_file.write_text(
"[tool.bumpversion]\n"
'current_version = "0.0.1"\n'
"allow_dirty = true\n\n"
"[[tool.bumpversion.files]]\n"
'filename = "VERSION"\n'
"regex = false\n"
)

# Act
runner: CliRunner = CliRunner()
with inside_dir(tmp_path):
result: Result = runner.invoke(
cli.cli,
[
"bump",
"--verbose",
"--no-regex",
"--no-configured-files",
"--ignore-missing-files",
"minor",
"VERSION",
],
)

# Assert
if result.exit_code != 0:
print("Here is the output:")
print(result.output)
print(traceback.print_exception(result.exc_info[1]))

assert result.exit_code == 0

0 comments on commit fcfaac7

Please sign in to comment.