Skip to content

Commit bee7027

Browse files
Merge pull request #10495 from ThomasWaldmann/completion-repo-url-followup
completion: repository directory completion fixes, refs #10460
2 parents 2ee7d26 + f3c82cd commit bee7027

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎src/borg/archiver/completion_cmd.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@
455455
# Complete local repository directories, but nothing for a URL like ssh://... or rclone:...
456456
_borg_complete_repo_dirs() {
457457
[[ "$PREFIX" == ({REPO_URL_SCHEMES}):* ]] && return 1
458-
_files -/
458+
_files -/ "$@"
459459
}
460460
461461
# Complete tags from repository
@@ -682,7 +682,7 @@
682682
if string match -qr -- '^({REPO_URL_SCHEMES}):' $cur
683683
return
684684
end
685-
__fish_complete_directories
685+
__fish_complete_directories $cur
686686
end
687687
688688
# Complete relative time markers

‎src/borg/testsuite/archiver/completion_cmd_test.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import borg
11-
from ...archiver.completion_cmd import TCSH_SORTBY_FN
11+
from ...archiver.completion_cmd import TCSH_REPO_URL_RULE, TCSH_SORTBY_FN
1212
from ...archiver.repo_create_cmd import ENCRYPTION_DESCRIPTIONS
1313
from . import cmd, generate_archiver_tests, RK_ENCRYPTION
1414

@@ -632,12 +632,13 @@ def test_zsh_repo_url_no_directories(archivers, request):
632632
archiver = request.getfixturevalue(archivers)
633633
script = cmd(archiver, "completion", "zsh")
634634
# stub the zsh directory completion, it needs the whole completion system
635-
setup = "_files() { print -r -- COMPLETING-DIRS }\n"
635+
setup = '_files() { print -r -- COMPLETING-DIRS "$@" }\n'
636636
for url in REPO_URLS:
637637
result = _run_zsh_completion_fn(script, setup + f"PREFIX='{url}'\n_borg_complete_repo_dirs\n")
638638
assert "COMPLETING-DIRS" not in result.stdout, f"directories offered for {url}"
639-
result = _run_zsh_completion_fn(script, setup + "PREFIX=/some/dir\n_borg_complete_repo_dirs\n")
640-
assert "COMPLETING-DIRS" in result.stdout
639+
# the arguments (_arguments gives the description of the option value) are passed on
640+
result = _run_zsh_completion_fn(script, setup + "PREFIX=/some/dir\n_borg_complete_repo_dirs -X REPO\n")
641+
assert result.stdout.split() == ["COMPLETING-DIRS", "-/", "-X", "REPO"]
641642

642643

643644
@needs_fish
@@ -655,7 +656,7 @@ def test_fish_repo_url_no_directories(archivers, request):
655656
def test_tcsh_repo_url_no_directories(archivers, request):
656657
"""tcsh uses the first matching rule, the one completing nothing for URLs must precede the directory ones."""
657658
lines = [line.strip().rstrip(" \\") for line in completion_lines(archivers, request, "tcsh")]
658-
url_rule = lines.index("'c/{--repo=,-r=,--other-repo=,}{ssh,sftp,http,https,s3,b2,rclone}:/n/'")
659+
url_rule = lines.index(TCSH_REPO_URL_RULE)
659660
for repo_rule in ("'c/--repo=/d/'", "'n/--repo/d/'", "'n/-r/d/'", "'c/--other-repo=/d/'", "'n/--other-repo/d/'"):
660661
assert url_rule < lines.index(repo_rule)
661662

@@ -673,6 +674,9 @@ def test_fish_repo_directory_completion(archivers, request, tmp_path):
673674
candidates = _fish_complete_candidates(script, f"borg list {option} {prefix}")
674675
assert any(c.rstrip("/").endswith("somerepo") for c in candidates), f"repo dir missing: {candidates}"
675676
assert not any(c.endswith("somefile.txt") for c in candidates), f"file offered: {candidates}"
677+
# the value attached to the short option
678+
candidates = _fish_complete_candidates(script, f"borg list -r{prefix}")
679+
assert [c.rstrip("/") for c in candidates] == [f"-r{prefix}repo"]
676680

677681

678682
@needs_fish

0 commit comments

Comments
 (0)