diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs +++ b/rust/rhg/src/main.rs @@ -179,7 +179,7 @@ exit( &initial_current_dir, &ui, - OnUnsupported::from_config(&ui, &non_repo_config), + OnUnsupported::from_config(&non_repo_config), Err(error.into()), non_repo_config .get_bool(b"ui", b"detailed-exit-code") @@ -197,7 +197,7 @@ exit( &initial_current_dir, &ui, - OnUnsupported::from_config(&ui, &non_repo_config), + OnUnsupported::from_config(&non_repo_config), Err(CommandError::UnsupportedFeature { message: format_bytes!( b"URL-like --repository {}", @@ -287,7 +287,7 @@ Err(error) => exit( &initial_current_dir, &ui, - OnUnsupported::from_config(&ui, &non_repo_config), + OnUnsupported::from_config(&non_repo_config), Err(error.into()), // TODO: show a warning or combine with original error if // `get_bool` returns an error @@ -302,7 +302,7 @@ } else { &non_repo_config }; - let on_unsupported = OnUnsupported::from_config(&ui, config); + let on_unsupported = OnUnsupported::from_config(config); let result = main_with_result( &process_start_time, @@ -362,6 +362,20 @@ ) = (&on_unsupported, &result) { let mut args = std::env::args_os(); + let executable = match executable { + None => { + exit_no_fallback( + ui, + OnUnsupported::Abort, + Err(CommandError::abort( + "abort: 'rhg.on-unsupported=fallback' without \ + 'rhg.fallback-executable' set.", + )), + false, + ); + } + Some(executable) => executable, + }; let executable_path = get_path_from_bytes(&executable); let this_executable = args.next().expect("exepcted argv[0] to exist"); if executable_path == &PathBuf::from(this_executable) { @@ -374,7 +388,8 @@ )); on_unsupported = OnUnsupported::Abort } else { - // `args` is now `argv[1..]` since we’ve already consumed `argv[0]` + // `args` is now `argv[1..]` since we’ve already consumed + // `argv[0]` let mut command = Command::new(executable_path); command.args(args); if let Some(initial) = initial_current_dir { @@ -549,13 +564,13 @@ /// Silently exit with code 252. AbortSilent, /// Try running a Python implementation - Fallback { executable: Vec }, + Fallback { executable: Option> }, } impl OnUnsupported { const DEFAULT: Self = OnUnsupported::Abort; - fn from_config(ui: &Ui, config: &Config) -> Self { + fn from_config(config: &Config) -> Self { match config .get(b"rhg", b"on-unsupported") .map(|value| value.to_ascii_lowercase()) @@ -566,18 +581,7 @@ Some(b"fallback") => OnUnsupported::Fallback { executable: config .get(b"rhg", b"fallback-executable") - .unwrap_or_else(|| { - exit_no_fallback( - ui, - Self::Abort, - Err(CommandError::abort( - "abort: 'rhg.on-unsupported=fallback' without \ - 'rhg.fallback-executable' set." - )), - false, - ) - }) - .to_owned(), + .map(|x| x.to_owned()), }, None => Self::DEFAULT, Some(_) => { diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -168,13 +168,12 @@ $ rhg cat original --exclude="*.rs" original content - $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE" - $ unset RHG_FALLBACK_EXECUTABLE - $ rhg cat original --exclude="*.rs" + $ (unset RHG_FALLBACK_EXECUTABLE; rhg cat original --exclude="*.rs") abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set. [255] - $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE" - $ export RHG_FALLBACK_EXECUTABLE + + $ (unset RHG_FALLBACK_EXECUTABLE; rhg cat original) + original content $ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false [1]