mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
Remove dependence on callsigns from bin/commit-hook
Summary: Ref T4245. Two effects: - First, let hooks work for future repositories without callsigns. - Second, provide a better error when users push directly to hosted repositories. Test Plan: Ran `bin/commit-hook PHID-REPO-xxx`. Reviewers: chad, avivey Reviewed By: avivey Maniphest Tasks: T4245 Differential Revision: https://secure.phabricator.com/D15293
This commit is contained in:
parent
f5e2f9587c
commit
973b8ace86
3 changed files with 42 additions and 6 deletions
|
@ -32,14 +32,14 @@ $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();
|
||||||
|
|
||||||
|
@ -62,8 +62,9 @@ if ($repository->isGit() || $repository->isHg()) {
|
||||||
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()) {
|
||||||
|
@ -77,7 +78,7 @@ if ($repository->isGit() || $repository->isHg()) {
|
||||||
// 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];
|
||||||
|
|
|
@ -192,7 +192,7 @@ final class PhabricatorRepositoryPullEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getHookContextIdentifier(PhabricatorRepository $repository) {
|
private function getHookContextIdentifier(PhabricatorRepository $repository) {
|
||||||
$identifier = $repository->getCallsign();
|
$identifier = $repository->getPHID();
|
||||||
|
|
||||||
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
||||||
if (strlen($instance)) {
|
if (strlen($instance)) {
|
||||||
|
|
|
@ -371,6 +371,41 @@ with `sudoers` configuration.
|
||||||
is caused by SVN wiping the environment (including PATH) when invoking
|
is caused by SVN wiping the environment (including PATH) when invoking
|
||||||
commit hooks.
|
commit hooks.
|
||||||
|
|
||||||
|
No Direct Pushes
|
||||||
|
================
|
||||||
|
|
||||||
|
You may get an error about "No Direct Pushes" when trying to push. This means
|
||||||
|
you are pushing directly to the repository instead of pushing through
|
||||||
|
Phabricator. This is not supported: writes to hosted repositories must go
|
||||||
|
through Phabricator so it can perform authentication, enforce permissions,
|
||||||
|
write logs, proxy requests, apply rewriting, etc.
|
||||||
|
|
||||||
|
One way to do a direct push by mistake is to use a `file:///` URI to interact
|
||||||
|
with the repository from the same machine. This is not supported. Instead, use
|
||||||
|
one of the repository URIs provided in the web interface, even if you're
|
||||||
|
working on the same machine.
|
||||||
|
|
||||||
|
Another way to do a direct push is to misconfigure SSH (or not configure it at
|
||||||
|
all) so that none of the logic described above runs and you just connect
|
||||||
|
normally as a system user. In this case, the `ssh` test described above will
|
||||||
|
fail (you'll get a command prompt when you connect, instead of the message you
|
||||||
|
are supposed to get, as described above).
|
||||||
|
|
||||||
|
If you encounter this error: make sure you're using a remote URI given to
|
||||||
|
you by Diffusion in the web interface, then run through the troubleshooting
|
||||||
|
steps above carefully.
|
||||||
|
|
||||||
|
Sometimes users encounter this problem because they skip this whole document
|
||||||
|
assuming they don't need to configure anything. This will not work, and you
|
||||||
|
MUST configure things as described above for hosted repositories to work.
|
||||||
|
|
||||||
|
The technical reason this error occurs is that the `PHABRICATOR_USER` variable
|
||||||
|
is not defined in the environment when commit hooks run. This variable is set
|
||||||
|
by Phabricator when a request passes through the authentication layer that this
|
||||||
|
document provides instructions for configuring. Its absence indicates that the
|
||||||
|
request did not pass through Phabricator.
|
||||||
|
|
||||||
|
|
||||||
= Next Steps =
|
= Next Steps =
|
||||||
|
|
||||||
Once hosted repositories are set up:
|
Once hosted repositories are set up:
|
||||||
|
|
Loading…
Reference in a new issue