Changeset View
Changeset View
Standalone View
Standalone View
scripts/repository/commit_hook.php
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| 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); | ||||
| $args = new PhutilArgumentParser($argv); | |||||
| $args->parsePartial( | |||||
| array( | |||||
| array( | |||||
| 'name' => 'hook-mode', | |||||
| 'param' => 'mode', | |||||
| 'help' => pht('Hook execution mode.'), | |||||
| ), | |||||
| )); | |||||
| $argv = array_merge( | |||||
| array($argv[0]), | |||||
| $args->getUnconsumedArgumentVector()); | |||||
| // Figure out which user is writing the commit. | // Figure out which user is writing the commit. | ||||
| $hook_mode = $args->getArg('hook-mode'); | |||||
| if ($hook_mode !== null) { | |||||
| $known_modes = array( | |||||
| 'svn-revprop' => true, | |||||
| ); | |||||
| if (empty($known_modes[$hook_mode])) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Invalid Hook Mode: This hook was invoked in "%s" mode, but this '. | |||||
| 'is not a recognized hook mode. Valid modes are: %s.', | |||||
| $hook_mode, | |||||
| implode(', ', array_keys($known_modes)))); | |||||
| } | |||||
| } | |||||
| $is_svnrevprop = ($hook_mode == 'svn-revprop'); | |||||
| if ($is_svnrevprop) { | |||||
| // For now, we let these through if the repository allows dangerous changes | |||||
| // and prevent them if it doesn't. See T11208 for discussion. | |||||
| $revprop_key = $argv[5]; | |||||
| if ($repository->isGit() || $repository->isHg()) { | if ($repository->shouldAllowDangerousChanges()) { | ||||
| $err = 0; | |||||
| } else { | |||||
| $err = 1; | |||||
| $console = PhutilConsole::getConsole(); | |||||
| $console->writeErr( | |||||
| pht( | |||||
| "DANGEROUS CHANGE: Dangerous change protection is enabled for this ". | |||||
| "repository, so you can not change revision properties (you are ". | |||||
| "attempting to edit \"%s\").\n". | |||||
| "Edit the repository configuration before making dangerous changes.", | |||||
| $revprop_key)); | |||||
| } | |||||
| exit($err); | |||||
| } else 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( | ||||
| 'No Direct Pushes: You are pushing directly to a repository hosted '. | 'No Direct Pushes: You are pushing directly to a repository hosted '. | ||||
| 'by Phabricator. This will not work. See "No Direct Pushes" in the '. | 'by Phabricator. This will not work. See "No Direct Pushes" in the '. | ||||
| 'documentation for more information.')); | 'documentation for more information.')); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines | |||||