]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Dispatch an event in arc land right before pushing a revision
authorAlok Menghrajani <amenghra@fb.com>
Sat, 9 Mar 2013 02:32:36 +0000 (18:32 -0800)
committerAlok Menghrajani <amenghra@fb.com>
Sat, 9 Mar 2013 02:32:36 +0000 (18:32 -0800)
Summary: I looked at the pros & cons at adding hooks in git/hg vs arc land and I prefer arc land.

Test Plan:
* added an event listener and made sure I could handle the event.
* made sure things get reverted when the event handler throws an exception.

Reviewers: vrana, epriestley, pieter

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5268

src/events/constant/ArcanistEventType.php
src/workflow/ArcanistLandWorkflow.php

index 26dfa26091343d9666ba711adab6a94b36cc30ac..8c988dbd328c57af4a0d9a621f7368f690a21a2e 100644 (file)
@@ -10,4 +10,6 @@ final class ArcanistEventType extends PhutilEventType {
   const TYPE_DIFF_WASCREATED        = 'diff.wasCreated';
 
   const TYPE_REVISION_WILLCREATEREVISION = 'revision.willCreateRevision';
+
+  const TYPE_LAND_WILLPUSHREVISION  = 'land.willPushRevision';
 }
index 1a3f9a2e47da86b8e4b5a57fb0071f9e3f9b39fb..0aa674b1e760751c7c267886b4299115f8b4d5a0 100644 (file)
@@ -782,6 +782,18 @@ EOTEXT
       }
     }
 
+    // We dispatch this event so we can run checks on the merged revision, right
+    // before it gets pushed out. It's easier to do this in arc land than to
+    // try to hook into git/hg.
+    try {
+      $this->dispatchEvent(
+        ArcanistEventType::TYPE_LAND_WILLPUSHREVISION,
+        array());
+    } catch (Exception $ex) {
+      $this->executeCleanupAfterFailedPush();
+      throw $ex;
+    }
+
     if ($this->getArgument('hold')) {
       echo phutil_console_format(
         "Holding change in **%s**: it has NOT been pushed yet.\n",
@@ -818,9 +830,8 @@ EOTEXT
 
       if ($err) {
         echo phutil_console_format("<bg:red>**   PUSH FAILED!   **</bg>\n");
+        $this->executeCleanupAfterFailedPush();
         if ($this->isGit) {
-          $repository_api->execxLocal('reset --hard HEAD^');
-          $this->restoreBranch();
           throw new ArcanistUsageException(
             "'{$cmd}' failed! Fix the error and run 'arc land' again.");
         }
@@ -841,6 +852,14 @@ EOTEXT
     }
   }
 
+  private function executeCleanupAfterFailedPush() {
+    if ($this->isGit) {
+      $repository_api = $this->getRepositoryAPI();
+      $repository_api->execxLocal('reset --hard HEAD^');
+      $this->restoreBranch();
+    }
+  }
+
   private function cleanupBranch() {
     $repository_api = $this->getRepositoryAPI();