From 0182dbd914edce4b577230929677803621af5ee6 Mon Sep 17 00:00:00 2001 From: Gautam Aggarwal Date: Sat, 29 Mar 2025 03:43:58 +0000 Subject: [PATCH] Added 2 new unit tests and updated docs --- docs/how-to/set-up-backups.md | 10 +++++++++ tests/unit/commands/test_borgmatic.py | 30 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/docs/how-to/set-up-backups.md b/docs/how-to/set-up-backups.md index c90b9136e..d63368f37 100644 --- a/docs/how-to/set-up-backups.md +++ b/docs/how-to/set-up-backups.md @@ -296,6 +296,16 @@ skip_actions: - compact ``` +## Disabling default actions + +By default, running `borgmatic` without any arguments will perform the default backup actions (create, prune, and compact). If you want to disable this behavior and require explicit actions to be specified, add the following to your configuration: + +```yaml +default_actions: false +``` + +With this setting, running `borgmatic` without arguments will show the help message instead of performing any actions. + ## Autopilot diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 15512a678..27e91cf5b 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -2099,3 +2099,33 @@ def test_check_and_show_help_on_no_args_does_not_show_help_when_args_provided(): flexmock(module.sys).should_receive('exit').never() module.check_and_show_help_on_no_args({'test.yaml': {'default_actions': False}}) +def test_check_and_show_help_on_no_args_with_no_default_actions_in_all_configs(): + flexmock(module.sys).should_receive('argv').and_return(['borgmatic']) + + # Both configs have default_actions set to False, so help should be shown + configs = { + 'config1.yaml': {'default_actions': False}, + 'config2.yaml': {'default_actions': False} + } + + # Expect help to be shown + flexmock(module).should_receive('parse_arguments').with_args('--help').once() + flexmock(module.sys).should_receive('exit').with_args(0).once() + + module.check_and_show_help_on_no_args(configs) + +def test_check_and_show_help_on_no_args_with_conflicting_configs(): + flexmock(module.sys).should_receive('argv').and_return(['borgmatic']) + + # Simulate two config files with conflicting 'default_actions' values + configs = { + 'config1.yaml': {'default_actions': True}, + 'config2.yaml': {'default_actions': False} + } + + # Expect help not to be shown because at least one config enables default actions + flexmock(module).should_receive('parse_arguments').never() + flexmock(module.sys).should_receive('exit').never() + + module.check_and_show_help_on_no_args(configs) +