From fc3e99d0e93a907008feb291f9a3d3b5ddaa43ee Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 25 Oct 2024 18:19:03 +0900 Subject: [PATCH] cli: bookmark list: extend --remote filter to string patterns I don't have a practical use case, but I think this is more consistent with NAMES arguments. --- cli/src/commands/bookmark/list.rs | 25 ++++++++++++++++++------- cli/tests/cli-reference@.md.snap | 6 +++++- cli/tests/test_bookmark_command.rs | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cli/src/commands/bookmark/list.rs b/cli/src/commands/bookmark/list.rs index 194853ad1..fa3792673 100644 --- a/cli/src/commands/bookmark/list.rs +++ b/cli/src/commands/bookmark/list.rs @@ -44,10 +44,21 @@ pub struct BookmarkListArgs { all_remotes: bool, /// Show all tracking and non-tracking remote bookmarks belonging - /// to this remote. Can be combined with `--tracked` or - /// `--conflicted` to filter the bookmarks shown (can be repeated) - #[arg(long = "remote", value_name = "REMOTE", conflicts_with_all = ["all_remotes"])] - remotes: Option>, + /// to this remote + /// + /// Can be combined with `--tracked` or `--conflicted` to filter the + /// bookmarks shown (can be repeated.) + /// + /// By default, the specified remote name matches exactly. Use `glob:` + /// prefix to select remotes by wildcard pattern. For details, see + /// https://martinvonz.github.io/jj/latest/revsets/#string-patterns. + #[arg( + long = "remote", + value_name = "REMOTE", + conflicts_with_all = ["all_remotes"], + value_parser = StringPattern::parse, + )] + remotes: Option>, /// Show remote tracked bookmarks only. Omits local Git-tracking bookmarks /// by default @@ -151,9 +162,9 @@ pub fn cmd_bookmark_list( .iter() .copied() .filter(|&(remote_name, _)| { - args.remotes - .as_ref() - .map_or(true, |names| names.iter().any(|r| r == remote_name)) + args.remotes.as_ref().map_or(true, |patterns| { + patterns.iter().any(|pattern| pattern.matches(remote_name)) + }) }) .partition::, _>(|&(_, remote_ref)| remote_ref.is_tracking()); diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 9a2e067e6..0589b9a41 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -318,7 +318,11 @@ For information about bookmarks, see https://martinvonz.github.io/jj/latest/book ###### **Options:** * `-a`, `--all-remotes` — Show all tracking and non-tracking remote bookmarks including the ones whose targets are synchronized with the local bookmarks -* `--remote ` — Show all tracking and non-tracking remote bookmarks belonging to this remote. Can be combined with `--tracked` or `--conflicted` to filter the bookmarks shown (can be repeated) +* `--remote ` — Show all tracking and non-tracking remote bookmarks belonging to this remote + + Can be combined with `--tracked` or `--conflicted` to filter the bookmarks shown (can be repeated.) + + By default, the specified remote name matches exactly. Use `glob:` prefix to select remotes by wildcard pattern. For details, see https://martinvonz.github.io/jj/latest/revsets/#string-patterns. * `-t`, `--tracked` — Show remote tracked bookmarks only. Omits local Git-tracking bookmarks by default * `-c`, `--conflicted` — Show conflicted bookmarks only * `-r`, `--revisions ` — Show bookmarks whose local targets are in the given revisions diff --git a/cli/tests/test_bookmark_command.rs b/cli/tests/test_bookmark_command.rs index c0b751ae6..32e99c037 100644 --- a/cli/tests/test_bookmark_command.rs +++ b/cli/tests/test_bookmark_command.rs @@ -1547,7 +1547,7 @@ fn test_bookmark_list_filtered() { insta::assert_snapshot!(stderr, @r#" Hint: Bookmarks marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this. "#); - let (stdout, stderr) = query(&["--remote", "git"]); + let (stdout, stderr) = query(&["--remote", "glob:gi?"]); insta::assert_snapshot!(stdout, @r#" local-keep: kpqxywon c7b4c09c (empty) local-keep @git: kpqxywon c7b4c09c (empty) local-keep