Skip to content

Commit 7ee189b

Browse files
refactor(switch): split match into explicit conditions
1 parent 10fdf3d commit 7ee189b

File tree

1 file changed

+16
-20
lines changed
  • git-branchless-navigation/src

1 file changed

+16
-20
lines changed

git-branchless-navigation/src/lib.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ pub fn switch(
474474
switch_options: &SwitchOptions,
475475
) -> EyreExitOr<()> {
476476
let SwitchOptions {
477-
interactive: _,
477+
interactive,
478478
branch_name,
479479
force,
480480
merge,
@@ -510,27 +510,23 @@ pub fn switch(
510510
false,
511511
)?;
512512

513-
let initial_query = match switch_options {
514-
SwitchOptions {
515-
interactive: true,
516-
branch_name: _,
517-
force: _,
518-
merge: _,
519-
detach: _,
520-
target,
521-
} => Some(target.clone().unwrap_or_default()),
522-
SwitchOptions {
523-
interactive: false,
524-
branch_name: _,
525-
force: _,
526-
merge: _,
527-
detach: _,
528-
target: _,
529-
} => None,
513+
enum Target {
514+
/// The (possibly empty) target expression should be used as the initial
515+
/// query in the commit selector.
516+
Interactive(String),
517+
518+
/// No target expression was specified.
519+
None,
520+
}
521+
let initial_query = match (interactive, target) {
522+
(true, Some(target)) => Target::Interactive(target.clone()),
523+
(true, None) => Target::Interactive(String::new()),
524+
(false, Some(_)) => Target::None,
525+
(false, None) => Target::None,
530526
};
531527
let target: Option<CheckoutTarget> = match initial_query {
532-
None => target.clone().map(CheckoutTarget::Unknown),
533-
Some(initial_query) => {
528+
Target::None => None,
529+
Target::Interactive(initial_query) => {
534530
match prompt_select_commit(
535531
None,
536532
&initial_query,

0 commit comments

Comments
 (0)