瀏覽代碼

Disallow the "--dry-run" flag with the "borg" action (#774).

Dan Helfman 1 年之前
父節點
當前提交
257ab77bea
共有 3 個文件被更改,包括 18 次插入0 次删除
  1. 2 0
      NEWS
  2. 3 0
      borgmatic/commands/arguments.py
  3. 13 0
      tests/integration/commands/test_arguments.py

+ 2 - 0
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

+ 3 - 0
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

+ 13 - 0
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')