diff rust/rhg/src/main.rs @ 48075:f11f233546ce

rhg: fallback if the current command has any generic hook defined We do not handle hooks yet. Differential Revision: https://phab.mercurial-scm.org/D11380
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 01 Sep 2021 17:41:51 +0200
parents cff41e168c25
children b44e1184b7e1
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Wed Sep 01 17:41:08 2021 +0200
+++ b/rust/rhg/src/main.rs	Wed Sep 01 17:41:51 2021 +0200
@@ -68,6 +68,17 @@
     let matches = app.clone().get_matches_safe()?;
 
     let (subcommand_name, subcommand_matches) = matches.subcommand();
+
+    for prefix in ["pre", "post", "fail"].iter() {
+        // Mercurial allows users to define generic hooks for commands,
+        // fallback if any are detected
+        let item = format!("{}-{}", prefix, subcommand_name);
+        let hook_for_command = config.get_str(b"hooks", item.as_bytes())?;
+        if hook_for_command.is_some() {
+            let msg = format!("{}-{} hook defined", prefix, subcommand_name);
+            return Err(CommandError::unsupported(msg));
+        }
+    }
     let run = subcommand_run_fn(subcommand_name)
         .expect("unknown subcommand name from clap despite AppSettings::SubcommandRequired");
     let subcommand_args = subcommand_matches