diff --git a/borgmatic/borg/compact.py b/borgmatic/borg/compact.py index 640b5361..dc44d53f 100644 --- a/borgmatic/borg/compact.py +++ b/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) ) diff --git a/tests/unit/borg/test_compact.py b/tests/unit/borg/test_compact.py index 00e1e86f..85a68b25 100644 --- a/tests/unit/borg/test_compact.py +++ b/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()