Skip to content

Commit

Permalink
completion: teach git commands about bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Nov 14, 2024
1 parent 26ccc1c commit e4fdc91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cli/src/commands/git/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
13 changes: 13 additions & 0 deletions cli/tests/test_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e4fdc91

Please sign in to comment.