changeset 50909:12476986d89c

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.
author Spencer Baugh <sbaugh@janestreet.com>
date Thu, 31 Aug 2023 19:47:33 -0400
parents 2eca8b5c8cbd
children 8edfd28a01d1
files rust/rhg/src/main.rs
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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() {