From 3412da1cf3f1c3c8b34e1b6afddfdf05be413625 Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Tue, 14 Apr 2026 07:45:45 -0400 Subject: [PATCH 1/5] list: hint to use repo-list when no archive NAME is given Refs #9545 Add default value for archive name argument in list command --- src/borg/archiver/list_cmd.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/borg/archiver/list_cmd.py b/src/borg/archiver/list_cmd.py index 98abd18c3e..902008a2e7 100644 --- a/src/borg/archiver/list_cmd.py +++ b/src/borg/archiver/list_cmd.py @@ -19,6 +19,11 @@ class ListMixIn: @with_repository(compatibility=(Manifest.Operation.READ,)) def do_list(self, args, repository, manifest): """List archive contents.""" + if args.name is None: + self.parser.error( + "borg list requires an archive NAME.\n" + "To list the archives in a repository, use: borg repo-list" + ) # omitting args.pattern_roots here, restricting to paths only by cli args.paths: matcher = build_matcher(args.patterns, args.paths) if args.format is not None: @@ -126,7 +131,7 @@ def build_parser_list(self, subparsers, common_parser, mid_common_parser): subparser.add_argument( "--depth", metavar="N", dest="depth", type=int, help="only list files up to the specified directory depth" ) - subparser.add_argument("name", metavar="NAME", type=archivename_validator, help="specify the archive name") + subparser.add_argument("name", metavar="NAME", nargs="?", default=None, type=archivename_validator, help="specify the archive name") subparser.add_argument( "paths", metavar="PATH", nargs="*", type=PathSpec, help="paths to list; patterns are supported" ) From e211740346d396aec23e0807a6d282505b03e76e Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Tue, 14 Apr 2026 17:04:49 -0400 Subject: [PATCH 2/5] fix: address lint issues --- src/borg/archiver/list_cmd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/borg/archiver/list_cmd.py b/src/borg/archiver/list_cmd.py index 902008a2e7..39f703c257 100644 --- a/src/borg/archiver/list_cmd.py +++ b/src/borg/archiver/list_cmd.py @@ -21,8 +21,7 @@ def do_list(self, args, repository, manifest): """List archive contents.""" if args.name is None: self.parser.error( - "borg list requires an archive NAME.\n" - "To list the archives in a repository, use: borg repo-list" + "borg list requires an archive NAME.\nTo list the archives in a repository, use: borg repo-list" ) # omitting args.pattern_roots here, restricting to paths only by cli args.paths: matcher = build_matcher(args.patterns, args.paths) @@ -131,7 +130,9 @@ def build_parser_list(self, subparsers, common_parser, mid_common_parser): subparser.add_argument( "--depth", metavar="N", dest="depth", type=int, help="only list files up to the specified directory depth" ) - subparser.add_argument("name", metavar="NAME", nargs="?", default=None, type=archivename_validator, help="specify the archive name") + subparser.add_argument( + "name", metavar="NAME", nargs="?", default=None, type=archivename_validator, help="specify the archive name" + ) subparser.add_argument( "paths", metavar="PATH", nargs="*", type=PathSpec, help="paths to list; patterns are supported" ) From 3d88430d4caa5642d050d5a5639358c4d33fe19e Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:27:45 -0400 Subject: [PATCH 3/5] tests: add test for borg list missing archive name error Add test for list command without archive name --- src/borg/testsuite/archiver/list_cmd_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/borg/testsuite/archiver/list_cmd_test.py b/src/borg/testsuite/archiver/list_cmd_test.py index f9bb56e58a..3ce3796ed0 100644 --- a/src/borg/testsuite/archiver/list_cmd_test.py +++ b/src/borg/testsuite/archiver/list_cmd_test.py @@ -259,3 +259,11 @@ def test_fingerprint(archivers, request): # Even unmodified files should have different fingerprints because conditions_hash changed assert fingerprints1["input/file2"] != fingerprints5["input/file2"] + + +def test_list_without_archive_name_shows_helpful_error(archivers, request): + archiver = request.getfixturevalue(archivers) + cmd(archiver, "repo-create", RK_ENCRYPTION) + output = cmd(archiver, "list", exit_code=2) + assert "borg list requires an archive NAME" in output + assert "borg repo-list" in output From 3ce4fe09e036e2761671c06a8b9c00b1ca0332be Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Fri, 17 Apr 2026 07:27:45 -0400 Subject: [PATCH 4/5] Improve error message for missing archive name Updated error handling in the do_list method to print error message to stderr. --- src/borg/archiver/list_cmd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/borg/archiver/list_cmd.py b/src/borg/archiver/list_cmd.py index 39f703c257..c79b00f9f4 100644 --- a/src/borg/archiver/list_cmd.py +++ b/src/borg/archiver/list_cmd.py @@ -20,9 +20,12 @@ class ListMixIn: def do_list(self, args, repository, manifest): """List archive contents.""" if args.name is None: - self.parser.error( - "borg list requires an archive NAME.\nTo list the archives in a repository, use: borg repo-list" + print( + "Error: borg list requires an archive NAME.\n" + "To list the archives in a repository, use: borg repo-list", + file=sys.stderr, ) + return 2 # omitting args.pattern_roots here, restricting to paths only by cli args.paths: matcher = build_matcher(args.patterns, args.paths) if args.format is not None: From 80b967ea56997f88ebe8b3d0d1906b62b5a58454 Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Fri, 17 Apr 2026 08:52:11 -0400 Subject: [PATCH 5/5] Improve error handling in list_cmd.py Replace return code with set_ec for error handling. --- src/borg/archiver/list_cmd.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/borg/archiver/list_cmd.py b/src/borg/archiver/list_cmd.py index c79b00f9f4..b7c1cfac4c 100644 --- a/src/borg/archiver/list_cmd.py +++ b/src/borg/archiver/list_cmd.py @@ -6,7 +6,7 @@ from ..archive import Archive from ..cache import Cache from ..constants import * # NOQA -from ..helpers import ItemFormatter, BaseFormatter, archivename_validator, PathSpec +from ..helpers import ItemFormatter, BaseFormatter, archivename_validator, PathSpec, set_ec from ..helpers.argparsing import ArgumentParser from ..manifest import Manifest @@ -25,7 +25,8 @@ def do_list(self, args, repository, manifest): "To list the archives in a repository, use: borg repo-list", file=sys.stderr, ) - return 2 + set_ec(EXIT_ERROR) + return # omitting args.pattern_roots here, restricting to paths only by cli args.paths: matcher = build_matcher(args.patterns, args.paths) if args.format is not None: