diff --git a/NEWS b/NEWS index 45f57cb3..d7083025 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ * #768: Fix a traceback when an invalid command-line flag or action is used. * #771: Fix normalization of deprecated sections ("location:", "storage:", "hooks:", etc.) to support empty sections without erroring. + * #774: Disallow the "--dry-run" flag with the "borg" action, as borgmatic can't guarantee the Borg + command won't have side effects. 1.8.3 * #665: BREAKING: Simplify logging logic as follows: Syslog verbosity is now disabled by diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index b6ac2d9a..caf25abd 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -1328,4 +1328,7 @@ def parse_arguments(*unparsed_arguments): 'With the info action, only one of --archive, --prefix, or --match-archives flags can be used.' ) + if 'borg' in arguments and arguments['global'].dry_run: + raise ValueError('With the borg action, --dry-run is not supported.') + return arguments diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index e64030c6..392082ff 100644 --- a/tests/integration/commands/test_arguments.py +++ b/tests/integration/commands/test_arguments.py @@ -622,3 +622,16 @@ def test_parse_arguments_config_with_subaction_and_explicit_config_file_does_not module.parse_arguments( 'config', 'bootstrap', '--repository', 'repo.borg', '--config', 'test.yaml' ) + + +def test_parse_arguments_with_borg_action_and_dry_run_raises(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(ValueError): + module.parse_arguments('--dry-run', 'borg', 'list') + + +def test_parse_arguments_with_borg_action_and_no_dry_run_does_not_raise(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('borg', 'list')