completion: teach git commands about bookmarks

This commit is contained in:
Remo Senekowitsch 2024-11-14 20:14:18 +01:00
parent 26ccc1c4cc
commit e4fdc91b69
3 changed files with 26 additions and 2 deletions

View file

@ -37,7 +37,13 @@ pub struct GitFetchArgs {
///
/// By default, the specified name matches exactly. Use `glob:` prefix to
/// expand `*` as a glob. The other wildcard characters aren't supported.
#[arg(long, short, alias="bookmark", default_value = "glob:*", value_parser = StringPattern::parse)]
#[arg(
long, short,
alias = "bookmark",
default_value = "glob:*",
value_parser = StringPattern::parse,
add = ArgValueCandidates::new(complete::bookmarks),
)]
branch: Vec<StringPattern>,
/// The remote to fetch from (only named remotes are supported, can be
/// repeated)

View file

@ -86,7 +86,12 @@ pub struct GitPushArgs {
/// By default, the specified name matches exactly. Use `glob:` prefix to
/// select bookmarks by wildcard pattern. For details, see
/// https://martinvonz.github.io/jj/latest/revsets#string-patterns.
#[arg(long, short, alias="branch", value_parser = StringPattern::parse)]
#[arg(
long, short,
alias = "branch",
value_parser = StringPattern::parse,
add = ArgValueCandidates::new(complete::local_bookmarks),
)]
bookmark: Vec<StringPattern>,
/// Push all bookmarks (including deleted bookmarks)
#[arg(long)]

View file

@ -126,6 +126,19 @@ fn test_bookmark_names() {
let stdout = test_env.jj_cmd_success(&repo_path, &["--", "jj", "bookmark", "untrack", "a"]);
insta::assert_snapshot!(stdout, @"aaa-tracked@origin");
let stdout = test_env.jj_cmd_success(&repo_path, &["--", "jj", "git", "push", "-b", "a"]);
insta::assert_snapshot!(stdout, @r"
aaa-local
aaa-tracked
");
let stdout = test_env.jj_cmd_success(&repo_path, &["--", "jj", "git", "fetch", "-b", "a"]);
insta::assert_snapshot!(stdout, @r"
aaa-local
aaa-tracked
aaa-untracked
");
}
#[test]