Bläddra i källkod

Update compact action for Borg 2 support (#557).

Dan Helfman 2 år sedan
förälder
incheckning
94321aec7a

+ 1 - 1
NEWS

@@ -1,4 +1,4 @@
-2.0.0.dev0
+1.7.0.dev0
  * #557: Support for Borg 2 while still working with Borg 1. If you install Borg 2, you'll need to
  * #557: Support for Borg 2 while still working with Borg 1. If you install Borg 2, you'll need to
    manually "borg transfer" or "borgmatic transfer" any existing Borg 1 repositories before use. See
    manually "borg transfer" or "borgmatic transfer" any existing Borg 1 repositories before use. See
    the Borg 2.0 changelog summary for more information about Borg 2:
    the Borg 2.0 changelog summary for more information about Borg 2:

+ 2 - 9
borgmatic/borg/check.py

@@ -5,7 +5,7 @@ import logging
 import os
 import os
 import pathlib
 import pathlib
 
 
-from borgmatic.borg import environment, extract, feature, rinfo, state
+from borgmatic.borg import environment, extract, flags, rinfo, state
 from borgmatic.execute import DO_NOT_CAPTURE, execute_command
 from borgmatic.execute import DO_NOT_CAPTURE, execute_command
 
 
 DEFAULT_CHECKS = (
 DEFAULT_CHECKS = (
@@ -304,14 +304,7 @@ def check_archives(
             + verbosity_flags
             + verbosity_flags
             + (('--progress',) if progress else ())
             + (('--progress',) if progress else ())
             + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
             + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
-            + (
-                ('--repo',)
-                if feature.available(
-                    feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version
-                )
-                else ()
-            )
-            + (repository,)
+            + flags.make_repository_flags(repository, local_borg_version)
         )
         )
 
 
         borg_environment = environment.make_environment(storage_config)
         borg_environment = environment.make_environment(storage_config)

+ 5 - 4
borgmatic/borg/compact.py

@@ -1,6 +1,6 @@
 import logging
 import logging
 
 
-from borgmatic.borg import environment
+from borgmatic.borg import environment, flags
 from borgmatic.execute import execute_command
 from borgmatic.execute import execute_command
 
 
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -10,6 +10,7 @@ def compact_segments(
     dry_run,
     dry_run,
     repository,
     repository,
     storage_config,
     storage_config,
+    local_borg_version,
     local_path='borg',
     local_path='borg',
     remote_path=None,
     remote_path=None,
     progress=False,
     progress=False,
@@ -17,8 +18,8 @@ def compact_segments(
     threshold=None,
     threshold=None,
 ):
 ):
     '''
     '''
-    Given dry-run flag, a local or remote repository path, and a storage config dict, compact Borg
-    segments in a repository.
+    Given dry-run flag, a local or remote repository path, a storage config dict, and the local
+    Borg version, compact the segments in a repository.
     '''
     '''
     umask = storage_config.get('umask', None)
     umask = storage_config.get('umask', None)
     lock_wait = storage_config.get('lock_wait', None)
     lock_wait = storage_config.get('lock_wait', None)
@@ -35,7 +36,7 @@ def compact_segments(
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
-        + (repository,)
+        + flags.make_repository_flags(repository, local_borg_version)
     )
     )
 
 
     if not dry_run:
     if not dry_run:

+ 14 - 0
borgmatic/borg/flags.py

@@ -1,5 +1,7 @@
 import itertools
 import itertools
 
 
+from borgmatic.borg import feature
+
 
 
 def make_flags(name, value):
 def make_flags(name, value):
     '''
     '''
@@ -29,3 +31,15 @@ def make_flags_from_arguments(arguments, excludes=()):
             if name not in excludes and not name.startswith('_')
             if name not in excludes and not name.startswith('_')
         )
         )
     )
     )
+
+
+def make_repository_flags(repository, local_borg_version):
+    '''
+    Given the path of a Borg repository and the local Borg version, return Borg-version-appropriate
+    command-line flags (as a tuple) for selecting that repository.
+    '''
+    return (
+        ('--repo',)
+        if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version)
+        else ()
+    ) + (repository,)

+ 2 - 7
borgmatic/borg/prune.py

@@ -1,6 +1,6 @@
 import logging
 import logging
 
 
-from borgmatic.borg import environment, feature
+from borgmatic.borg import environment, flags
 from borgmatic.execute import execute_command
 from borgmatic.execute import execute_command
 
 
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -64,12 +64,7 @@ def prune_archives(
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--dry-run',) if dry_run else ())
         + (('--dry-run',) if dry_run else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
-        + (
-            ('--repo',)
-            if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version)
-            else ()
-        )
-        + (repository,)
+        + flags.make_repository_flags(repository, local_borg_version)
     )
     )
 
 
     if (stats or files) and logger.getEffectiveLevel() == logging.WARNING:
     if (stats or files) and logger.getEffectiveLevel() == logging.WARNING:

+ 2 - 7
borgmatic/borg/rcreate.py

@@ -2,7 +2,7 @@ import argparse
 import logging
 import logging
 import subprocess
 import subprocess
 
 
-from borgmatic.borg import environment, feature, rinfo
+from borgmatic.borg import environment, feature, flags, rinfo
 from borgmatic.execute import DO_NOT_CAPTURE, execute_command
 from borgmatic.execute import DO_NOT_CAPTURE, execute_command
 
 
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -57,12 +57,7 @@ def create_repository(
         + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--remote-path', remote_path) if remote_path else ())
         + (('--remote-path', remote_path) if remote_path else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
-        + (
-            ('--repo',)
-            if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version)
-            else ()
-        )
-        + (repository,)
+        + flags.make_repository_flags(repository, local_borg_version)
     )
     )
 
 
     # Do not capture output here, so as to support interactive prompts.
     # Do not capture output here, so as to support interactive prompts.

+ 4 - 10
borgmatic/borg/rinfo.py

@@ -1,7 +1,6 @@
 import logging
 import logging
 
 
-from borgmatic.borg import environment, feature
-from borgmatic.borg.flags import make_flags
+from borgmatic.borg import environment, feature, flags
 from borgmatic.execute import execute_command
 from borgmatic.execute import execute_command
 
 
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -39,15 +38,10 @@ def display_repository_info(
             if logger.isEnabledFor(logging.DEBUG) and not rinfo_arguments.json
             if logger.isEnabledFor(logging.DEBUG) and not rinfo_arguments.json
             else ()
             else ()
         )
         )
-        + make_flags('remote-path', remote_path)
-        + make_flags('lock-wait', lock_wait)
+        + flags.make_flags('remote-path', remote_path)
+        + flags.make_flags('lock-wait', lock_wait)
         + (('--json',) if rinfo_arguments.json else ())
         + (('--json',) if rinfo_arguments.json else ())
-        + (
-            ('--repo',)
-            if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version)
-            else ()
-        )
-        + (repository,)
+        + flags.make_repository_flags(repository, local_borg_version)
     )
     )
 
 
     return execute_command(
     return execute_command(

+ 1 - 0
borgmatic/commands/borgmatic.py

@@ -305,6 +305,7 @@ def run_actions(
                 global_arguments.dry_run,
                 global_arguments.dry_run,
                 repository,
                 repository,
                 storage,
                 storage,
+                local_borg_version,
                 local_path=local_path,
                 local_path=local_path,
                 remote_path=remote_path,
                 remote_path=remote_path,
                 progress=arguments['compact'].progress,
                 progress=arguments['compact'].progress,

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 from setuptools import find_packages, setup
 
 
-VERSION = '2.0.0.dev0'
+VERSION = '1.7.0.dev0'
 
 
 
 
 setup(
 setup(

+ 11 - 37
tests/unit/borg/test_check.py

@@ -301,7 +301,7 @@ def test_check_archives_with_progress_calls_borg_with_progress_parameter():
     )
     )
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('execute_command').never()
     flexmock(module).should_receive('execute_command').never()
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'check', '--progress', 'repo'),
         ('borg', 'check', '--progress', 'repo'),
@@ -331,7 +331,7 @@ def test_check_archives_with_repair_calls_borg_with_repair_parameter():
     )
     )
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('execute_command').never()
     flexmock(module).should_receive('execute_command').never()
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'check', '--repair', 'repo'),
         ('borg', 'check', '--repair', 'repo'),
@@ -371,7 +371,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
     flexmock(module).should_receive('make_check_flags').with_args(
     flexmock(module).should_receive('make_check_flags').with_args(
         checks, check_last, module.DEFAULT_PREFIX
         checks, check_last, module.DEFAULT_PREFIX
     ).and_return(())
     ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg', 'check', 'repo'))
     insert_execute_command_mock(('borg', 'check', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
@@ -385,32 +385,6 @@ def test_check_archives_calls_borg_with_parameters(checks):
     )
     )
 
 
 
 
-def test_check_archives_with_borg_features_calls_borg_with_repo_flag():
-    checks = ('repository',)
-    check_last = flexmock()
-    consistency_config = {'check_last': check_last}
-    flexmock(module).should_receive('parse_checks')
-    flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
-    flexmock(module.rinfo).should_receive('display_repository_info').and_return(
-        '{"repository": {"id": "repo"}}'
-    )
-    flexmock(module).should_receive('make_check_flags').with_args(
-        checks, check_last, module.DEFAULT_PREFIX
-    ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(True)
-    insert_execute_command_mock(('borg', 'check', '--repo', 'repo'))
-    flexmock(module).should_receive('make_check_time_path')
-    flexmock(module).should_receive('write_check_time')
-
-    module.check_archives(
-        repository='repo',
-        location_config={},
-        storage_config={},
-        consistency_config=consistency_config,
-        local_borg_version='1.2.3',
-    )
-
-
 def test_check_archives_with_json_error_raises():
 def test_check_archives_with_json_error_raises():
     checks = ('archives',)
     checks = ('archives',)
     check_last = flexmock()
     check_last = flexmock()
@@ -459,7 +433,7 @@ def test_check_archives_with_extract_check_calls_extract_only():
         '{"repository": {"id": "repo"}}'
         '{"repository": {"id": "repo"}}'
     )
     )
     flexmock(module).should_receive('make_check_flags').never()
     flexmock(module).should_receive('make_check_flags').never()
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     flexmock(module.extract).should_receive('extract_last_archive_dry_run').once()
     flexmock(module.extract).should_receive('extract_last_archive_dry_run').once()
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
     insert_execute_command_never()
     insert_execute_command_never()
@@ -482,7 +456,7 @@ def test_check_archives_with_log_info_calls_borg_with_info_parameter():
         '{"repository": {"id": "repo"}}'
         '{"repository": {"id": "repo"}}'
     )
     )
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('make_check_flags').and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
     insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
     insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
@@ -506,7 +480,7 @@ def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
         '{"repository": {"id": "repo"}}'
         '{"repository": {"id": "repo"}}'
     )
     )
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('make_check_flags').and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_logging_mock(logging.DEBUG)
     insert_logging_mock(logging.DEBUG)
     insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
     insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
@@ -551,7 +525,7 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
     flexmock(module).should_receive('make_check_flags').with_args(
     flexmock(module).should_receive('make_check_flags').with_args(
         checks, check_last, module.DEFAULT_PREFIX
         checks, check_last, module.DEFAULT_PREFIX
     ).and_return(())
     ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg1', 'check', 'repo'))
     insert_execute_command_mock(('borg1', 'check', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
@@ -578,7 +552,7 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
     flexmock(module).should_receive('make_check_flags').with_args(
     flexmock(module).should_receive('make_check_flags').with_args(
         checks, check_last, module.DEFAULT_PREFIX
         checks, check_last, module.DEFAULT_PREFIX
     ).and_return(())
     ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
     insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
@@ -605,7 +579,7 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
     flexmock(module).should_receive('make_check_flags').with_args(
     flexmock(module).should_receive('make_check_flags').with_args(
         checks, check_last, module.DEFAULT_PREFIX
         checks, check_last, module.DEFAULT_PREFIX
     ).and_return(())
     ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
     insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
@@ -632,7 +606,7 @@ def test_check_archives_with_retention_prefix():
     flexmock(module).should_receive('make_check_flags').with_args(
     flexmock(module).should_receive('make_check_flags').with_args(
         checks, check_last, prefix
         checks, check_last, prefix
     ).and_return(())
     ).and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg', 'check', 'repo'))
     insert_execute_command_mock(('borg', 'check', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')
@@ -655,7 +629,7 @@ def test_check_archives_with_extra_borg_options_calls_borg_with_extra_options():
         '{"repository": {"id": "repo"}}'
         '{"repository": {"id": "repo"}}'
     )
     )
     flexmock(module).should_receive('make_check_flags').and_return(())
     flexmock(module).should_receive('make_check_flags').and_return(())
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg', 'check', '--extra', '--options', 'repo'))
     insert_execute_command_mock(('borg', 'check', '--extra', '--options', 'repo'))
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('make_check_time_path')
     flexmock(module).should_receive('write_check_time')
     flexmock(module).should_receive('write_check_time')

+ 51 - 11
tests/unit/borg/test_compact.py

@@ -21,94 +21,134 @@ COMPACT_COMMAND = ('borg', 'compact')
 
 
 
 
 def test_compact_segments_calls_borg_with_parameters():
 def test_compact_segments_calls_borg_with_parameters():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('repo',), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('repo',), logging.INFO)
 
 
-    module.compact_segments(dry_run=False, repository='repo', storage_config={})
+    module.compact_segments(
+        dry_run=False, repository='repo', storage_config={}, local_borg_version='1.2.3'
+    )
 
 
 
 
 def test_compact_segments_with_log_info_calls_borg_with_info_parameter():
 def test_compact_segments_with_log_info_calls_borg_with_info_parameter():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--info', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--info', 'repo'), logging.INFO)
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
 
 
-    module.compact_segments(repository='repo', storage_config={}, dry_run=False)
+    module.compact_segments(
+        repository='repo', storage_config={}, local_borg_version='1.2.3', dry_run=False
+    )
 
 
 
 
 def test_compact_segments_with_log_debug_calls_borg_with_debug_parameter():
 def test_compact_segments_with_log_debug_calls_borg_with_debug_parameter():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
     insert_logging_mock(logging.DEBUG)
     insert_logging_mock(logging.DEBUG)
 
 
-    module.compact_segments(repository='repo', storage_config={}, dry_run=False)
+    module.compact_segments(
+        repository='repo', storage_config={}, local_borg_version='1.2.3', dry_run=False
+    )
 
 
 
 
 def test_compact_segments_with_dry_run_skips_borg_call():
 def test_compact_segments_with_dry_run_skips_borg_call():
     flexmock(module).should_receive('execute_command').never()
     flexmock(module).should_receive('execute_command').never()
 
 
-    module.compact_segments(repository='repo', storage_config={}, dry_run=True)
+    module.compact_segments(
+        repository='repo', storage_config={}, local_borg_version='1.2.3', dry_run=True
+    )
 
 
 
 
 def test_compact_segments_with_local_path_calls_borg_via_local_path():
 def test_compact_segments_with_local_path_calls_borg_via_local_path():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg1',) + COMPACT_COMMAND[1:] + ('repo',), logging.INFO)
     insert_execute_command_mock(('borg1',) + COMPACT_COMMAND[1:] + ('repo',), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config={}, local_path='borg1',
+        dry_run=False,
+        repository='repo',
+        storage_config={},
+        local_borg_version='1.2.3',
+        local_path='borg1',
     )
     )
 
 
 
 
 def test_compact_segments_with_remote_path_calls_borg_with_remote_path_parameters():
 def test_compact_segments_with_remote_path_calls_borg_with_remote_path_parameters():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config={}, remote_path='borg1',
+        dry_run=False,
+        repository='repo',
+        storage_config={},
+        local_borg_version='1.2.3',
+        remote_path='borg1',
     )
     )
 
 
 
 
 def test_compact_segments_with_progress_calls_borg_with_progress_parameter():
 def test_compact_segments_with_progress_calls_borg_with_progress_parameter():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--progress', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--progress', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config={}, progress=True,
+        dry_run=False,
+        repository='repo',
+        storage_config={},
+        local_borg_version='1.2.3',
+        progress=True,
     )
     )
 
 
 
 
 def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_parameter():
 def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_parameter():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--cleanup-commits', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--cleanup-commits', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config={}, cleanup_commits=True,
+        dry_run=False,
+        repository='repo',
+        storage_config={},
+        local_borg_version='1.2.3',
+        cleanup_commits=True,
     )
     )
 
 
 
 
 def test_compact_segments_with_threshold_calls_borg_with_threshold_parameter():
 def test_compact_segments_with_threshold_calls_borg_with_threshold_parameter():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--threshold', '20', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--threshold', '20', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config={}, threshold=20,
+        dry_run=False,
+        repository='repo',
+        storage_config={},
+        local_borg_version='1.2.3',
+        threshold=20,
     )
     )
 
 
 
 
 def test_compact_segments_with_umask_calls_borg_with_umask_parameters():
 def test_compact_segments_with_umask_calls_borg_with_umask_parameters():
     storage_config = {'umask': '077'}
     storage_config = {'umask': '077'}
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config=storage_config,
+        dry_run=False, repository='repo', storage_config=storage_config, local_borg_version='1.2.3'
     )
     )
 
 
 
 
 def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_parameters():
 def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_parameters():
     storage_config = {'lock_wait': 5}
     storage_config = {'lock_wait': 5}
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
-        dry_run=False, repository='repo', storage_config=storage_config,
+        dry_run=False, repository='repo', storage_config=storage_config, local_borg_version='1.2.3'
     )
     )
 
 
 
 
 def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options():
 def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(COMPACT_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
     insert_execute_command_mock(COMPACT_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
 
 
     module.compact_segments(
     module.compact_segments(
         dry_run=False,
         dry_run=False,
         repository='repo',
         repository='repo',
         storage_config={'extra_borg_options': {'compact': '--extra --options'}},
         storage_config={'extra_borg_options': {'compact': '--extra --options'}},
+        local_borg_version='1.2.3',
     )
     )

+ 15 - 0
tests/unit/borg/test_flags.py

@@ -45,3 +45,18 @@ def test_make_flags_from_arguments_omits_excludes():
     arguments = flexmock(foo='bar', baz='quux')
     arguments = flexmock(foo='bar', baz='quux')
 
 
     assert module.make_flags_from_arguments(arguments, excludes=('baz', 'other')) == ('foo', 'bar')
     assert module.make_flags_from_arguments(arguments, excludes=('baz', 'other')) == ('foo', 'bar')
+
+
+def test_make_repository_flags_with_borg_features_includes_repo_flag():
+    flexmock(module.feature).should_receive('available').and_return(True)
+
+    assert module.make_repository_flags(repository='repo', local_borg_version='1.2.3') == (
+        '--repo',
+        'repo',
+    )
+
+
+def test_make_repository_flags_without_borg_features_includes_omits_flag():
+    flexmock(module.feature).should_receive('available').and_return(False)
+
+    assert module.make_repository_flags(repository='repo', local_borg_version='1.2.3') == ('repo',)

+ 13 - 30
tests/unit/borg/test_prune.py

@@ -67,7 +67,7 @@ def test_prune_archives_calls_borg_with_parameters():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -79,29 +79,12 @@ def test_prune_archives_calls_borg_with_parameters():
     )
     )
 
 
 
 
-def test_prune_archives_with_borg_features_calls_borg_with_repo_flag():
-    retention_config = flexmock()
-    flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
-        BASE_PRUNE_FLAGS
-    )
-    flexmock(module.feature).should_receive('available').and_return(True)
-    insert_execute_command_mock(PRUNE_COMMAND + ('--repo', 'repo'), logging.INFO)
-
-    module.prune_archives(
-        dry_run=False,
-        repository='repo',
-        storage_config={},
-        retention_config=retention_config,
-        local_borg_version='1.2.3',
-    )
-
-
 def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
 def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
     retention_config = flexmock()
     retention_config = flexmock()
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
 
 
@@ -119,7 +102,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
     insert_logging_mock(logging.DEBUG)
     insert_logging_mock(logging.DEBUG)
 
 
@@ -137,7 +120,7 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -154,7 +137,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
     insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -172,7 +155,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -190,7 +173,7 @@ def test_prune_archives_with_stats_calls_borg_with_stats_parameter_and_warning_o
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING)
     insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -208,7 +191,7 @@ def test_prune_archives_with_stats_and_log_info_calls_borg_with_stats_parameter_
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo'), logging.INFO)
 
 
@@ -227,7 +210,7 @@ def test_prune_archives_with_files_calls_borg_with_list_parameter_and_warning_ou
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), logging.WARNING)
     insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), logging.WARNING)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -245,7 +228,7 @@ def test_prune_archives_with_files_and_log_info_calls_borg_with_list_parameter_a
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--info', '--list', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--info', '--list', 'repo'), logging.INFO)
 
 
@@ -265,7 +248,7 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -283,7 +266,7 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(
@@ -300,7 +283,7 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
     flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
         BASE_PRUNE_FLAGS
         BASE_PRUNE_FLAGS
     )
     )
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
     insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
 
 
     module.prune_archives(
     module.prune_archives(

+ 10 - 10
tests/unit/borg/test_rcreate.py

@@ -36,16 +36,7 @@ def test_create_repository_calls_borg_with_parameters():
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
-
-    module.create_repository(
-        repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
-    )
-
-
-def test_create_repository_without_borg_features_calls_borg_with_init_sub_command():
-    insert_rinfo_command_not_found_mock()
-    insert_rcreate_command_mock(('borg', 'init', '--encryption', 'repokey', 'repo'))
-    flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
@@ -55,6 +46,7 @@ def test_create_repository_without_borg_features_calls_borg_with_init_sub_comman
 def test_create_repository_raises_for_borg_rcreate_error():
 def test_create_repository_raises_for_borg_rcreate_error():
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').and_raise(
     flexmock(module).should_receive('execute_command').and_raise(
         module.subprocess.CalledProcessError(2, 'borg rcreate')
         module.subprocess.CalledProcessError(2, 'borg rcreate')
@@ -72,6 +64,7 @@ def test_create_repository_raises_for_borg_rcreate_error():
 def test_create_repository_skips_creation_when_repository_already_exists():
 def test_create_repository_skips_creation_when_repository_already_exists():
     insert_rinfo_command_found_mock()
     insert_rinfo_command_found_mock()
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
@@ -96,6 +89,7 @@ def test_create_repository_with_append_only_calls_borg_with_append_only_paramete
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo',
         repository='repo',
@@ -110,6 +104,7 @@ def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_para
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--storage-quota', '5G', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--storage-quota', '5G', '--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo',
         repository='repo',
@@ -125,6 +120,7 @@ def test_create_repository_with_log_info_calls_borg_with_info_parameter():
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--info', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--info', '--repo', 'repo'))
     insert_logging_mock(logging.INFO)
     insert_logging_mock(logging.INFO)
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
@@ -136,6 +132,7 @@ def test_create_repository_with_log_debug_calls_borg_with_debug_parameter():
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--debug', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--debug', '--repo', 'repo'))
     insert_logging_mock(logging.DEBUG)
     insert_logging_mock(logging.DEBUG)
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
         repository='repo', storage_config={}, local_borg_version='2.3.4', encryption_mode='repokey'
@@ -146,6 +143,7 @@ def test_create_repository_with_local_path_calls_borg_via_local_path():
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(('borg1',) + RCREATE_COMMAND[1:] + ('--repo', 'repo'))
     insert_rcreate_command_mock(('borg1',) + RCREATE_COMMAND[1:] + ('--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo',
         repository='repo',
@@ -160,6 +158,7 @@ def test_create_repository_with_remote_path_calls_borg_with_remote_path_paramete
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--remote-path', 'borg1', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--remote-path', 'borg1', '--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo',
         repository='repo',
@@ -174,6 +173,7 @@ def test_create_repository_with_extra_borg_options_calls_borg_with_extra_options
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--extra', '--options', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--extra', '--options', '--repo', 'repo'))
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
 
 
     module.create_repository(
     module.create_repository(
         repository='repo',
         repository='repo',

+ 10 - 0
tests/unit/borg/test_rinfo.py

@@ -9,6 +9,7 @@ from ..test_verbosity import insert_logging_mock
 
 
 def test_display_repository_info_calls_borg_with_parameters():
 def test_display_repository_info_calls_borg_with_parameters():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--repo', 'repo'),
         ('borg', 'rinfo', '--repo', 'repo'),
@@ -27,6 +28,7 @@ def test_display_repository_info_calls_borg_with_parameters():
 
 
 def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_command():
 def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_command():
     flexmock(module.feature).should_receive('available').and_return(False)
     flexmock(module.feature).should_receive('available').and_return(False)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'info', 'repo'),
         ('borg', 'info', 'repo'),
@@ -45,6 +47,7 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
 
 
 def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
 def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--info', '--repo', 'repo'),
         ('borg', 'rinfo', '--info', '--repo', 'repo'),
@@ -63,6 +66,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
 
 
 def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_output():
 def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_output():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
@@ -84,6 +88,7 @@ def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_out
 
 
 def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter():
 def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--debug', '--show-rc', '--repo', 'repo'),
         ('borg', 'rinfo', '--debug', '--show-rc', '--repo', 'repo'),
@@ -103,6 +108,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter(
 
 
 def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_output():
 def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_output():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
@@ -124,6 +130,7 @@ def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_ou
 
 
 def test_display_repository_info_with_json_calls_borg_with_json_parameter():
 def test_display_repository_info_with_json_calls_borg_with_json_parameter():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
         ('borg', 'rinfo', '--json', '--repo', 'repo'),
@@ -144,6 +151,7 @@ def test_display_repository_info_with_json_calls_borg_with_json_parameter():
 
 
 def test_display_repository_info_with_local_path_calls_borg_via_local_path():
 def test_display_repository_info_with_local_path_calls_borg_via_local_path():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg1', 'rinfo', '--repo', 'repo'),
         ('borg1', 'rinfo', '--repo', 'repo'),
@@ -163,6 +171,7 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
 
 
 def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_parameters():
 def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_parameters():
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--remote-path', 'borg1', '--repo', 'repo'),
         ('borg', 'rinfo', '--remote-path', 'borg1', '--repo', 'repo'),
@@ -183,6 +192,7 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_pa
 def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
 def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
     storage_config = {'lock_wait': 5}
     storage_config = {'lock_wait': 5}
     flexmock(module.feature).should_receive('available').and_return(True)
     flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module.environment).should_receive('make_environment')
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('borg', 'rinfo', '--lock-wait', '5', '--repo', 'repo'),
         ('borg', 'rinfo', '--lock-wait', '5', '--repo', 'repo'),