Patchwork D11380: rhg: fallback if the current command has any generic hook defined

login
register
mail settings
Submitter phabricator
Date Sept. 1, 2021, 4:43 p.m.
Message ID <differential-rev-PHID-DREV-e5pli2jkvdhhpj47zqwz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49695/
State New
Headers show

Comments

phabricator - Sept. 1, 2021, 4:43 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We do not handle hooks yet.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11380

AFFECTED FILES
  rust/rhg/src/main.rs
  tests/test-rhg.t

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -212,6 +212,19 @@ 
   unsupported feature: fileset
   [252]
 
+Fallback with generic hooks
+  $ $NO_FALLBACK rhg cat original --config hooks.pre-cat=something
+  unsupported feature: pre-cat hook defined
+  [252]
+
+  $ $NO_FALLBACK rhg cat original --config hooks.post-cat=something
+  unsupported feature: post-cat hook defined
+  [252]
+
+  $ $NO_FALLBACK rhg cat original --config hooks.fail-cat=something
+  unsupported feature: fail-cat hook defined
+  [252]
+
 Requirements
   $ $NO_FALLBACK rhg debugrequirements
   dotencode
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
@@ -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