Skip to content

Commit

Permalink
refactor(smartlog): Make [revset] an Option<Revset>
Browse files Browse the repository at this point in the history
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 clap-rs/clap#3846 fmi on getting the
value_source of an arg via the derive API.
  • Loading branch information
claytonrcarter committed Nov 9, 2022
1 parent 8417222 commit a95f755
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion git-branchless/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn do_main_and_drop_locals() -> eyre::Result<i32> {
&git_run_info,
&SmartlogOptions {
event_id,
revset,
revset: revset.unwrap_or_else(|| SmartlogOptions::default().revset),
resolve_revset_options,
},
)?,
Expand Down
4 changes: 3 additions & 1 deletion git-branchless/src/commands/smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions git-branchless/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Revset>,

/// Options for resolving revset expressions.
#[clap(flatten)]
Expand Down
2 changes: 1 addition & 1 deletion git-branchless/tests/command/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> {
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
0: git_branchless::commands::smartlog::smartlog with effects=<Output fancy=false> git_run_info=<GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> 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=<Output fancy=false> git_run_info=<GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> 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:
Expand Down

0 comments on commit a95f755

Please sign in to comment.