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 @@ -311,27 +311,27 @@ } impl OnUnsupported { - const DEFAULT: Self = OnUnsupported::Abort; const DEFAULT_FALLBACK_EXECUTABLE: &'static [u8] = b"hg"; fn from_config(config: &Config) -> Self { - match config + let fallback = b"fallback"; + match &*config .get(b"rhg", b"on-unsupported") - .map(|value| value.to_ascii_lowercase()) - .as_deref() + .unwrap_or(fallback) + .to_ascii_lowercase() { - Some(b"abort") => OnUnsupported::Abort, - Some(b"abort-silent") => OnUnsupported::AbortSilent, - Some(b"fallback") => OnUnsupported::Fallback { - executable: config - .get(b"rhg", b"fallback-executable") - .unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE) - .to_owned(), - }, - None => Self::DEFAULT, - Some(_) => { - // TODO: warn about unknown config value - Self::DEFAULT + b"abort" => OnUnsupported::Abort, + b"abort-silent" => OnUnsupported::AbortSilent, + value => { + if value != fallback { + // TODO: warn about unknown config value + } + OnUnsupported::Fallback { + executable: config + .get(b"rhg", b"fallback-executable") + .unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE) + .to_owned(), + } } } } diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -11,6 +11,9 @@ > fi > } + $ echo "[rhg]" >> $HGRCPATH + $ echo "on-unsupported = abort" >> $HGRCPATH + Unimplemented command $ rhg unimplemented-command unsupported feature: error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context @@ -183,15 +186,15 @@ store $ echo indoor-pool >> .hg/requires - $ rhg files + $ rhg files --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252] - $ rhg cat -r 1 copy_of_original + $ rhg cat -r 1 copy_of_original --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252] - $ rhg debugrequirements + $ rhg debugrequirements --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252]