rhg: allow setting defaults.cmd to an empty string
authorSpencer Baugh <sbaugh@janestreet.com>
Thu, 31 Aug 2023 19:47:33 -0400
changeset 50909 12476986d89c
parent 50908 2eca8b5c8cbd
child 50910 8edfd28a01d1
rhg: allow setting defaults.cmd to an empty string This is used by at least one hg UI to prevent defaults from affecting the command: https://github.com/emacs-mirror/emacs/blob/b71beb7ae7c60a5c5af608420d28fdda5265a264/lisp/vc/vc-hg.el#L245 Let's let it work.
rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs	Sun Aug 20 17:19:33 2023 -0400
+++ b/rust/rhg/src/main.rs	Thu Aug 31 19:47:33 2023 -0400
@@ -76,10 +76,15 @@
 
     // Mercurial allows users to define "defaults" for commands, fallback
     // if a default is detected for the current command
-    let defaults = config.get_str(b"defaults", subcommand_name.as_bytes());
-    if defaults?.is_some() {
-        let msg = "`defaults` config set";
-        return Err(CommandError::unsupported(msg));
+    let defaults = config.get_str(b"defaults", subcommand_name.as_bytes())?;
+    match defaults {
+        // Programmatic usage might set defaults to an empty string to unset
+        // it; allow that
+        None | Some("") => {}
+        Some(_) => {
+            let msg = "`defaults` config set";
+            return Err(CommandError::unsupported(msg));
+        }
     }
 
     for prefix in ["pre", "post", "fail"].iter() {