mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Dispatch an event in arc land right before pushing a revision
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
This commit is contained in:
parent
955bfb5581
commit
7bf26484fb
2 changed files with 23 additions and 2 deletions
|
@ -10,4 +10,6 @@ final class ArcanistEventType extends PhutilEventType {
|
||||||
const TYPE_DIFF_WASCREATED = 'diff.wasCreated';
|
const TYPE_DIFF_WASCREATED = 'diff.wasCreated';
|
||||||
|
|
||||||
const TYPE_REVISION_WILLCREATEREVISION = 'revision.willCreateRevision';
|
const TYPE_REVISION_WILLCREATEREVISION = 'revision.willCreateRevision';
|
||||||
|
|
||||||
|
const TYPE_LAND_WILLPUSHREVISION = 'land.willPushRevision';
|
||||||
}
|
}
|
||||||
|
|
|
@ -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')) {
|
if ($this->getArgument('hold')) {
|
||||||
echo phutil_console_format(
|
echo phutil_console_format(
|
||||||
"Holding change in **%s**: it has NOT been pushed yet.\n",
|
"Holding change in **%s**: it has NOT been pushed yet.\n",
|
||||||
|
@ -818,9 +830,8 @@ EOTEXT
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
echo phutil_console_format("<bg:red>** PUSH FAILED! **</bg>\n");
|
echo phutil_console_format("<bg:red>** PUSH FAILED! **</bg>\n");
|
||||||
|
$this->executeCleanupAfterFailedPush();
|
||||||
if ($this->isGit) {
|
if ($this->isGit) {
|
||||||
$repository_api->execxLocal('reset --hard HEAD^');
|
|
||||||
$this->restoreBranch();
|
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
"'{$cmd}' failed! Fix the error and run 'arc land' again.");
|
"'{$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() {
|
private function cleanupBranch() {
|
||||||
$repository_api = $this->getRepositoryAPI();
|
$repository_api = $this->getRepositoryAPI();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue