Changeset View
Changeset View
Standalone View
Standalone View
scripts/repository/commit_hook.php
| Show All 26 Lines | if (count($context) > 1) { | ||||
| putenv('PHABRICATOR_INSTANCE='.$context[1]); | putenv('PHABRICATOR_INSTANCE='.$context[1]); | ||||
| } | } | ||||
| } | } | ||||
| $root = dirname(dirname(dirname(__FILE__))); | $root = dirname(dirname(dirname(__FILE__))); | ||||
| require_once $root.'/scripts/__init_script__.php'; | require_once $root.'/scripts/__init_script__.php'; | ||||
| if ($argc < 2) { | if ($argc < 2) { | ||||
| throw new Exception(pht('usage: commit-hook <callsign>')); | throw new Exception(pht('usage: commit-hook <repository>')); | ||||
| } | } | ||||
| $engine = new DiffusionCommitHookEngine(); | $engine = new DiffusionCommitHookEngine(); | ||||
| $repository = id(new PhabricatorRepositoryQuery()) | $repository = id(new PhabricatorRepositoryQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withCallsigns(array($argv[1])) | ->withIdentifiers(array($argv[1])) | ||||
| ->needProjectPHIDs(true) | ->needProjectPHIDs(true) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$repository) { | if (!$repository) { | ||||
| throw new Exception(pht('No such repository "%s"!', $argv[1])); | throw new Exception(pht('No such repository "%s"!', $argv[1])); | ||||
| } | } | ||||
| if (!$repository->isHosted()) { | if (!$repository->isHosted()) { | ||||
| // This should be redundant, but double check just in case. | // This should be redundant, but double check just in case. | ||||
| throw new Exception(pht('Repository "%s" is not hosted!', $argv[1])); | throw new Exception(pht('Repository "%s" is not hosted!', $argv[1])); | ||||
| } | } | ||||
| $engine->setRepository($repository); | $engine->setRepository($repository); | ||||
| // Figure out which user is writing the commit. | // Figure out which user is writing the commit. | ||||
| if ($repository->isGit() || $repository->isHg()) { | if ($repository->isGit() || $repository->isHg()) { | ||||
| $username = getenv(DiffusionCommitHookEngine::ENV_USER); | $username = getenv(DiffusionCommitHookEngine::ENV_USER); | ||||
| if (!strlen($username)) { | if (!strlen($username)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Usage: %s should be defined!', | 'No Direct Pushes: You are pushing directly to a repository hosted '. | ||||
| DiffusionCommitHookEngine::ENV_USER)); | 'by Phabricator. This will not work. See "No Direct Pushes" in the '. | ||||
| 'documentation for more information.')); | |||||
| } | } | ||||
| if ($repository->isHg()) { | if ($repository->isHg()) { | ||||
| // We respond to several different hooks in Mercurial. | // We respond to several different hooks in Mercurial. | ||||
| $engine->setMercurialHook($argv[2]); | $engine->setMercurialHook($argv[2]); | ||||
| } | } | ||||
| } else if ($repository->isSVN()) { | } else if ($repository->isSVN()) { | ||||
| // NOTE: In Subversion, the entire environment gets wiped so we can't read | // NOTE: In Subversion, the entire environment gets wiped so we can't read | ||||
| // DiffusionCommitHookEngine::ENV_USER. Instead, we've set "--tunnel-user" to | // DiffusionCommitHookEngine::ENV_USER. Instead, we've set "--tunnel-user" to | ||||
| // specify the correct user; read this user out of the commit log. | // specify the correct user; read this user out of the commit log. | ||||
| if ($argc < 4) { | if ($argc < 4) { | ||||
| throw new Exception(pht('usage: commit-hook <callsign> <repo> <txn>')); | throw new Exception(pht('usage: commit-hook <repository> <repo> <txn>')); | ||||
| } | } | ||||
| $svn_repo = $argv[2]; | $svn_repo = $argv[2]; | ||||
| $svn_txn = $argv[3]; | $svn_txn = $argv[3]; | ||||
| list($username) = execx('svnlook author -t %s %s', $svn_txn, $svn_repo); | list($username) = execx('svnlook author -t %s %s', $svn_txn, $svn_repo); | ||||
| $username = rtrim($username, "\n"); | $username = rtrim($username, "\n"); | ||||
| $engine->setSubversionTransactionInfo($svn_txn, $svn_repo); | $engine->setSubversionTransactionInfo($svn_txn, $svn_repo); | ||||
| ▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines | |||||