This commit is contained in:
Charmi Kadi 2026-05-17 16:24:22 +00:00 committed by GitHub
commit 0a1ed6a4e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -6,7 +6,7 @@ from ._common import with_repository, build_matcher, Highlander
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
@ -19,6 +19,14 @@ class ListMixIn:
@with_repository(compatibility=(Manifest.Operation.READ,))
def do_list(self, args, repository, manifest):
"""List archive contents."""
if args.name is None:
print(
"Error: borg list requires an archive NAME.\n"
"To list the archives in a repository, use: borg repo-list",
file=sys.stderr,
)
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:
@ -126,7 +134,9 @@ class ListMixIn:
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"
)

View file

@ -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