Skip to content

Commit fcfaac7

Browse files
committed
Added --ignore-missing-files option to bump
1 parent b473a19 commit fcfaac7

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

bumpversion/cli.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def cli(ctx: Context) -> None:
5454
"--search",
5555
"--replace",
5656
"--no-configured-files",
57+
"--ignore-missing-files",
5758
"--ignore-missing-version",
5859
],
5960
},
@@ -160,6 +161,12 @@ def cli(ctx: Context) -> None:
160161
"ignoring the files from the configuration file."
161162
),
162163
)
164+
@click.option(
165+
"--ignore-missing-files",
166+
is_flag=True,
167+
envvar="BUMPVERSION_IGNORE_MISSING_FILES",
168+
help="Ignore any missing files when searching and replacing in files.",
169+
)
163170
@click.option(
164171
"--ignore-missing-version",
165172
is_flag=True,
@@ -240,6 +247,7 @@ def bump(
240247
replace: Optional[str],
241248
regex: Optional[bool],
242249
no_configured_files: bool,
250+
ignore_missing_files: bool,
243251
ignore_missing_version: bool,
244252
dry_run: bool,
245253
commit: Optional[bool],
@@ -256,7 +264,7 @@ def bump(
256264
257265
ARGS may contain any of the following:
258266
259-
VERSION_PART is the part of the version to increase, e.g. `minor` .
267+
VERSION_PART is the part of the version to increase, e.g. `minor`.
260268
Valid values include those given in the `--serialize` / `--parse` option.
261269
262270
FILES are additional file(s) to modify.
@@ -281,6 +289,7 @@ def bump(
281289
tag_message=tag_message,
282290
message=message,
283291
commit_args=commit_args,
292+
ignore_missing_files=ignore_missing_files,
284293
ignore_missing_version=ignore_missing_version,
285294
regex=regex,
286295
)

tests/test_cli/test_bump.py

+39
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import shutil
44
import subprocess
5+
import traceback
56
from datetime import datetime
67
from pathlib import Path
78

@@ -350,3 +351,41 @@ def test_detects_bad_or_missing_version_part(version_part: str, tmp_path: Path,
350351
# Assert
351352
assert result.exception is not None
352353
assert "Unknown version part:" in result.stdout
354+
355+
356+
def test_ignores_missing_files_with_option(tmp_path, fixtures_path):
357+
"""The replace subcommand should ignore missing."""
358+
359+
config_file = tmp_path / ".bumpversion.toml"
360+
config_file.write_text(
361+
"[tool.bumpversion]\n"
362+
'current_version = "0.0.1"\n'
363+
"allow_dirty = true\n\n"
364+
"[[tool.bumpversion.files]]\n"
365+
'filename = "VERSION"\n'
366+
"regex = false\n"
367+
)
368+
369+
# Act
370+
runner: CliRunner = CliRunner()
371+
with inside_dir(tmp_path):
372+
result: Result = runner.invoke(
373+
cli.cli,
374+
[
375+
"bump",
376+
"--verbose",
377+
"--no-regex",
378+
"--no-configured-files",
379+
"--ignore-missing-files",
380+
"minor",
381+
"VERSION",
382+
],
383+
)
384+
385+
# Assert
386+
if result.exit_code != 0:
387+
print("Here is the output:")
388+
print(result.output)
389+
print(traceback.print_exception(result.exc_info[1]))
390+
391+
assert result.exit_code == 0

0 commit comments

Comments
 (0)