From 03423c632c5acb9a41042eadfe5bdb3ade3306ea Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 31 Jul 2017 13:21:58 -0700 Subject: [PATCH] Treat commit hook execution in observed repositories as a no-op, not an error Summary: See PHI24. If you create a hosted Mercurial repository and switch it to observed, you can end up with a hook installed that runs on pulls and complains. Instead, just bail out if we're running on a pull. The corresponding Git hook doesn't run on pulls, so there's no issue in Git. Test Plan: Executed the hook in an observed Mercurial repository, got a clean exit. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D18307 --- scripts/repository/commit_hook.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/repository/commit_hook.php b/scripts/repository/commit_hook.php index 44c772225c..51abcb6c89 100755 --- a/scripts/repository/commit_hook.php +++ b/scripts/repository/commit_hook.php @@ -48,8 +48,13 @@ if (!$repository) { } if (!$repository->isHosted()) { - // This should be redundant, but double check just in case. - throw new Exception(pht('Repository "%s" is not hosted!', $argv[1])); + // In Mercurial, the "pretxnchangegroup" hook fires for both pulls and + // pushes. Normally we only install the hook for hosted repositories, but + // if a hosted repository is later converted into an observed repository we + // can end up with an observed repository that has the hook installed. + // If we're running hooks from an observed repository, just exit without + // taking action. For more discussion, see PHI24. + return 0; } $engine->setRepository($repository);