From e9813d2539c72cb7273ace83972a80d30f42891d Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 21 Jan 2024 18:25:44 -0800 Subject: [PATCH] Allow the "--repository" flag to match across multiple configuration files (#818). --- NEWS | 3 +++ borgmatic/config/validate.py | 9 +++------ setup.py | 2 +- tests/unit/config/test_validate.py | 15 --------------- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index ef7758a..9266110 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.8.8.dev0 + * #818: Allow the "--repository" flag to match across multiple configuration files. + 1.8.7 * #736: Store included configuration files within each backup archive in support of the "config bootstrap" action. Previously, only top-level configuration files were stored. diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index 3ac205e..bf9869b 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -167,11 +167,10 @@ def repositories_match(first, second): def guard_configuration_contains_repository(repository, configurations): ''' Given a repository path and a dict mapping from config filename to corresponding parsed config - dict, ensure that the repository is declared exactly once in all of the configurations. If no + dict, ensure that the repository is declared at least once in all of the configurations. If no repository is given, skip this check. - Raise ValueError if the repository is not found in a configuration, or is declared multiple - times. + Raise ValueError if the repository is not found in any configurations. ''' if not repository: return @@ -186,9 +185,7 @@ def guard_configuration_contains_repository(repository, configurations): ) if count == 0: - raise ValueError(f'Repository {repository} not found in configuration files') - if count > 1: - raise ValueError(f'Repository {repository} found in multiple configuration files') + raise ValueError(f'Repository "{repository}" not found in configuration files') def guard_single_repository_selected(repository, configurations): diff --git a/setup.py b/setup.py index b7d5b29..dd98bc5 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.8.7' +VERSION = '1.8.8.dev0' setup( diff --git a/tests/unit/config/test_validate.py b/tests/unit/config/test_validate.py index 182cbd1..9330515 100644 --- a/tests/unit/config/test_validate.py +++ b/tests/unit/config/test_validate.py @@ -184,21 +184,6 @@ def test_guard_configuration_contains_repository_errors_when_repository_missing_ ) -def test_guard_configuration_contains_repository_errors_when_repository_matches_config_twice(): - flexmock(module).should_receive('repositories_match').replace_with( - lambda first, second: first == second - ) - - with pytest.raises(ValueError): - module.guard_configuration_contains_repository( - repository='repo', - configurations={ - 'config.yaml': {'repositories': ['repo', 'repo2']}, - 'other.yaml': {'repositories': ['repo']}, - }, - ) - - def test_guard_single_repository_selected_raises_when_multiple_repositories_configured_and_none_selected(): with pytest.raises(ValueError): module.guard_single_repository_selected(