From 6daa2b6c2efa7faebd7b9bc084466886fe431b86 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 23 Dec 2013 10:43:45 -0800 Subject: [PATCH] Fix a commit hook issue with the initial commit to Mercurial repositories Summary: Fixes T4257. The `hg heads` command exits with an error code and no output in an empty repository. Just ignore the error code: we don't have a great way to distinguish between errors, and we ran another `hg` command moments before, so we have at least some confidence it isn't a PATH sort of thing. Test Plan: Created a new Mercurial repository and pushed to hit the error in T4257. Applied this fix and got a clean push with an accurate push log. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4257 Differential Revision: https://secure.phabricator.com/D7817 --- .../diffusion/engine/DiffusionCommitHookEngine.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php index 285b4ad57e..667e2013b2 100644 --- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php @@ -583,17 +583,22 @@ final class DiffusionCommitHookEngine extends Phobject { // Resolve all of the futures now. We don't need the 'commits' future yet, // but it simplifies the logic to just get it out of the way. foreach (Futures($futures) as $future) { - $future->resolvex(); + $future->resolve(); } list($commit_raw) = $futures['commits']->resolvex(); $commit_map = $this->parseMercurialCommits($commit_raw); $this->mercurialCommits = $commit_map; - list($old_raw) = $futures['old']->resolvex(); + // NOTE: `hg heads` exits with an error code and no output if the repository + // has no heads. Most commonly this happens on a new repository. We know + // we can run `hg` successfully since the `hg log` above didn't error, so + // just ignore the error code. + + list($err, $old_raw) = $futures['old']->resolve(); $old_refs = $this->parseMercurialHeads($old_raw); - list($new_raw) = $futures['new']->resolvex(); + list($err, $new_raw) = $futures['new']->resolve(); $new_refs = $this->parseMercurialHeads($new_raw); $all_refs = array_keys($old_refs + $new_refs);