Browse Source

fix dry run not working borg 1.4.1+

Vandal 1 month ago
parent
commit
1cde65b4eb
2 changed files with 7 additions and 0 deletions
  1. 5 0
      borgmatic/borg/compact.py
  2. 2 0
      tests/unit/borg/test_compact.py

+ 5 - 0
borgmatic/borg/compact.py

@@ -37,6 +37,11 @@ def compact_segments(
         + (('--threshold', str(threshold)) if threshold else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+        + (
+            ('--dry-run',)
+            if dry_run and feature.available(feature.Feature.DRY_RUN_COMPACT, local_borg_version)
+            else ()
+        )
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + flags.make_repository_flags(repository_path, local_borg_version)
     )

+ 2 - 0
tests/unit/borg/test_compact.py

@@ -73,6 +73,8 @@ def test_compact_segments_with_dry_run_skips_borg_call_when_feature_unavailable(
     flexmock(module.feature).should_receive('available').with_args(
         module.feature.Feature.DRY_RUN_COMPACT, '1.2.3'
     ).and_return(False)
+    flexmock(module.environment).should_receive('make_environment').never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').never()
     flexmock(module).should_receive('execute_command').never()
     flexmock(logging).should_receive('info').with_args('Skipping compact (dry run)').once()