From e4fdc91b690379716c73190647170f702684ee6e Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 14 Nov 2024 20:14:18 +0100 Subject: [PATCH] completion: teach git commands about bookmarks --- cli/src/commands/git/fetch.rs | 8 +++++++- cli/src/commands/git/push.rs | 7 ++++++- cli/tests/test_completion.rs | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/src/commands/git/fetch.rs b/cli/src/commands/git/fetch.rs index 21b21f1d39..f806bb3033 100644 --- a/cli/src/commands/git/fetch.rs +++ b/cli/src/commands/git/fetch.rs @@ -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, /// The remote to fetch from (only named remotes are supported, can be /// repeated) diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index 9be3eab78c..b2c0c32f7f 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -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, /// Push all bookmarks (including deleted bookmarks) #[arg(long)] diff --git a/cli/tests/test_completion.rs b/cli/tests/test_completion.rs index c9484106c9..659876aff6 100644 --- a/cli/tests/test_completion.rs +++ b/cli/tests/test_completion.rs @@ -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]