From a95f7551204d176be3984dd53408f2190e637f6e Mon Sep 17 00:00:00 2001 From: Clayton Carter Date: Tue, 8 Nov 2022 23:38:34 -0400 Subject: [PATCH] refactor(smartlog): Make [revset] an Option This doesn't do much for us now, but will soon be used to help us determine what type of smartlog we should be rendering. Unfortunately, this prevents clap from rendering the default revset in the help message, but I believe this is the only way (via the derive API) to detect if the user has or has not not supplied an arg for a particular value. See https://github.com/clap-rs/clap/issues/3846 fmi on getting the value_source of an arg via the derive API. --- git-branchless/src/commands/mod.rs | 2 +- git-branchless/src/commands/smartlog.rs | 4 +++- git-branchless/src/opts.rs | 4 ++-- git-branchless/tests/command/test_init.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/git-branchless/src/commands/mod.rs b/git-branchless/src/commands/mod.rs index e4178d0f5..cf4c08568 100644 --- a/git-branchless/src/commands/mod.rs +++ b/git-branchless/src/commands/mod.rs @@ -340,7 +340,7 @@ fn do_main_and_drop_locals() -> eyre::Result { &git_run_info, &SmartlogOptions { event_id, - revset, + revset: revset.unwrap_or_else(|| SmartlogOptions::default().revset), resolve_revset_options, }, )?, diff --git a/git-branchless/src/commands/smartlog.rs b/git-branchless/src/commands/smartlog.rs index c804fcca3..cc1166984 100644 --- a/git-branchless/src/commands/smartlog.rs +++ b/git-branchless/src/commands/smartlog.rs @@ -521,7 +521,9 @@ mod render { fn default() -> Self { Self { event_id: Default::default(), - revset: Revset("draft() | branches() | @".to_string()), + revset: Revset( + "((draft() | branches() | @) % main()) | branches() | @".to_string(), + ), resolve_revset_options: Default::default(), } } diff --git a/git-branchless/src/opts.rs b/git-branchless/src/opts.rs index 47802cc9f..695f3789b 100644 --- a/git-branchless/src/opts.rs +++ b/git-branchless/src/opts.rs @@ -462,8 +462,8 @@ pub enum Command { /// The commits to render. These commits and their ancestors up to the /// main branch will be rendered. - #[clap(value_parser, default_value = "draft() | branches() | @")] - revset: Revset, + #[clap(value_parser)] + revset: Option, /// Options for resolving revset expressions. #[clap(flatten)] diff --git a/git-branchless/tests/command/test_init.rs b/git-branchless/tests/command/test_init.rs index 11b59c9b3..327c875c7 100644 --- a/git-branchless/tests/command/test_init.rs +++ b/git-branchless/tests/command/test_init.rs @@ -327,7 +327,7 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> { ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 0: git_branchless::commands::smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: Revset("draft() | branches() | @"), resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } + 0: git_branchless::commands::smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: Revset("((draft() | branches() | @) % main()) | branches() | @"), resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } at some/file/path.rs:123 Suggestion: