Skip to content

Commit

Permalink
implement "borg version", fixes #7829
Browse files Browse the repository at this point in the history
Since long, we have borg --version to display the borg (client) version string
in its very detailed form provided by setuptools_scm, e.g.:

borg 1.4.0.dev119+gc7cef548.d20240119).

Now there is an additional new command "borg version <REPO>",
which shows e.g.:

1.4.0a / 1.2.7     # client 1.4.0 alpha, server 1.2.7 release
1.4.0rc / 1.4.0rc  # client and server both run 1.4.0 release candidate

When a local repo is given, the client code directly accesses the repository,
thus we show the client version also as the server version.

When a remote repo is given (e.g. ssh:), the remote borg is queried and
its version is displayed as the server version.

Due to the version tuple format used in borg client/server negotiation, only
a simplified version is displayed (as provided by borg.version.format_version).
  • Loading branch information
ThomasWaldmann committed Jan 19, 2024
1 parent c7cef54 commit fe3cda8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/borg/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ def do_serve(self, args):
storage_quota=args.storage_quota,
).serve()

def do_version(self, args):
"""Display the borg client / borg server version"""
from borg.version import parse_version, format_version
client_version = parse_version(__version__)
if args.location.proto == 'ssh':
with RemoteRepository(args.location.omit_archive(), lock=False, args=args) as repository:
server_version = repository.server_version
else:
server_version = client_version
print(f"{format_version(client_version)} / {format_version(server_version)}")

@with_repository(create=True, exclusive=True, manifest=False)
def do_init(self, args, repository):
"""Initialize an empty repository"""
Expand Down Expand Up @@ -4134,6 +4145,19 @@ def define_borg_mount(parser):
help='format output as JSON')
define_archive_filters_group(subparser)

# borg version
version_epilog = process_epilog("""
This command displays the borg client version / borg server version.
""")
subparser = subparsers.add_parser('version', parents=[common_parser], add_help=False,
description=self.do_version.__doc__, epilog=version_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
help='display borg client version / borg server version')
subparser.set_defaults(func=self.do_version)
subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
type=location_validator(archive=False),
help='repository (used to determine client/server situation)')

# borg init
init_epilog = process_epilog("""
This command initializes an empty repository. A repository is a filesystem
Expand Down

0 comments on commit fe3cda8

Please sign in to comment.