Ver Fonte

Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (#734).

Dan Helfman há 1 ano atrás
pai
commit
14e2a6b89d
3 ficheiros alterados com 24 adições e 7 exclusões
  1. 2 0
      NEWS
  2. 3 0
      borgmatic/borg/flags.py
  3. 19 7
      tests/unit/borg/test_flags.py

+ 2 - 0
NEWS

@@ -11,6 +11,8 @@
  * #732: Include multiple configuration files with a single "!include". See the documentation for
    more information:
    https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#multiple-merge-includes
+ * #734: Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (meaning
+   all archives).
 
 1.8.0
  * #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting

+ 3 - 0
borgmatic/borg/flags.py

@@ -77,6 +77,9 @@ def make_match_archives_flags(match_archives, archive_name_format, local_borg_ve
 
     derived_match_archives = re.sub(r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format)
 
+    if derived_match_archives == '*':
+        return ()
+
     if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
         return ('--match-archives', f'sh:{derived_match_archives}')
     else:

+ 19 - 7
tests/unit/borg/test_flags.py

@@ -86,28 +86,28 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
 
 
 @pytest.mark.parametrize(
-    'match_archives, archive_name_format,feature_available,expected_result',
+    'match_archives,archive_name_format,feature_available,expected_result',
     (
         (None, None, True, ()),
         (None, '', True, ()),
         (
             're:foo-.*',
-            '{hostname}-{now}',
+            '{hostname}-{now}',  # noqa: FS003
             True,
             ('--match-archives', 're:foo-.*'),
-        ),  # noqa: FS003
+        ),
         (
             'sh:foo-*',
-            '{hostname}-{now}',
+            '{hostname}-{now}',  # noqa: FS003
             False,
             ('--glob-archives', 'foo-*'),
-        ),  # noqa: FS003
+        ),
         (
             'foo-*',
-            '{hostname}-{now}',
+            '{hostname}-{now}',  # noqa: FS003
             False,
             ('--glob-archives', 'foo-*'),
-        ),  # noqa: FS003
+        ),
         (
             None,
             '{hostname}-docs-{now}',  # noqa: FS003
@@ -133,6 +133,18 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
             False,
             ('--glob-archives', '{hostname}-docs-*'),  # noqa: FS003
         ),
+        (
+            None,
+            '{now}',  # noqa: FS003
+            False,
+            (),
+        ),
+        (
+            None,
+            '{now}',  # noqa: FS003
+            True,
+            (),
+        ),
         (None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')),  # noqa: FS003
     ),
 )