private $minimumSeverity = null;
private $changedLines = array();
+ private $commitHookMode = false;
public function __construct() {
return idx($this->changedLines, $path);
}
+ public function setFileData($data) {
+ $this->fileData = $data + $this->fileData;
+ return $this;
+ }
+
+ public function setCommitHookMode($mode) {
+ $this->commitHookMode = $mode;
+ return $this;
+ }
+
protected function loadData($path) {
if (!isset($this->fileData[$path])) {
$disk_path = $this->getFilePathOnDisk($path);
return $this->fileData[$path];
}
+ public function pathExists($path) {
+ if ($this->getCommitHookMode()) {
+ return (idx($this->fileData, $path) !== null);
+ } else {
+ $disk_path = $this->getFilePathOnDisk($path);
+ return Filesystem::pathExists($disk_path);
+ }
+ }
+
public function getFilePathOnDisk($path) {
return Filesystem::resolvePath(
$path,
}
public function getCommitHookMode() {
- return false;
+ return $this->commitHookMode;
}
public function run() {
return $linters;
}
- public function pathExists($path) {
- $disk_path = $this->getFilePathOnDisk($path);
- return Filesystem::pathExists($disk_path);
- }
-
}
phutil_require_module('arcanist', 'lint/engine/base');
+phutil_require_module('arcanist', 'lint/linter/apachelicense');
phutil_require_module('arcanist', 'lint/linter/filename');
phutil_require_module('arcanist', 'lint/linter/generated');
phutil_require_module('arcanist', 'lint/linter/phutilmodule');
phutil_require_module('arcanist', 'lint/linter/text');
phutil_require_module('arcanist', 'lint/linter/xhpast');
-phutil_require_module('arcanist', 'lint/linter/apachelicense');
-
-phutil_require_module('phutil', 'filesystem');
phutil_require_source('PhutilLintEngine.php');
}
}
+ // TODO: The old 'arc amend' had a check here to see if you were running
+ // 'arc amend' with an explicit revision but HEAD already had another
+ // revision in it. Maybe this is worth restoring?
+
$conduit = $this->getConduit();
$message = $conduit->callMethodSynchronous(
'differential.getcommitmessage',
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
- **svn-hook-pre-receive** __repository__ __transaction__
+ **svn-hook-pre-commit** __repository__ __transaction__
Supports: svn
You can install this as an SVN pre-commit hook.
EOTEXT
$transaction,
$repository);
+ if (strpos($commit_message, '@bypass-lint') !== false) {
+ return 0;
+ }
+
+
// TODO: Do stuff with commit message.
- var_dump($commit_message);
list($changed) = execx(
'svnlook changed --transaction %s %s',
}
}
+
if ($failed && $resolved) {
$failed_paths = ' '.implode("\n ", $failed);
$resolved_paths = ' '.implode("\n ", array_keys($resolved));
if (!$resolved) {
// None of the affected paths are beneath a .arcconfig file.
- return 3;
+ return 0;
}
$groups = array();
$message);
}
- $project_root = key($groups);
+ $config_file = key($groups);
+ $project_root = dirname($config_file);
$paths = reset($groups);
+ list($config) = execx(
+ 'svnlook cat --transaction %s %s %s',
+ $transaction,
+ $repository,
+ $config_file);
+
$data = array();
foreach ($paths as $path) {
+ // TODO: This should be done in parallel.
list($err, $filedata) = exec_manual(
'svnlook cat --transaction %s %s %s',
$transaction,
$data[$path] = $err ? null : $filedata;
}
- // TODO: Do stuff with data.
- var_dump($data);
+ $working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile(
+ $project_root,
+ $config);
+
+ $lint_engine = $working_copy->getConfig('lint_engine');
+ if (!$lint_engine) {
+ return 0;
+ }
+
+ PhutilSymbolLoader::loadClass($lint_engine);
+
+ $engine = newv($lint_engine, array());
+ $engine->setWorkingCopy($working_copy);
+ $engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
+ $engine->setPaths(array_keys($data));
+ $engine->setFileData($data);
+ $engine->setCommitHookMode(true);
+
+ $results = $engine->run();
+
+ $renderer = new ArcanistLintRenderer();
+ $failures = array();
+ foreach ($results as $result) {
+ if (!$result->getMessages()) {
+ continue;
+ }
+ $failures[] = $result;
+ }
+
+ if ($failures) {
+ $at = "@";
+ $msg = phutil_console_format(
+ "\n**LINT ERRORS**\n\n".
+ "This changeset has lint errors. You must fix all lint errors before ".
+ "you can commit.\n\n".
+ "You can add '{$at}bypass-lint' to your commit message to disable ".
+ "lint checks for this commit, or '{$at}nolint' to the file with ".
+ "errors to disable lint for that file.\n\n");
+ echo phutil_console_wrap($msg);
+ foreach ($failures as $result) {
+ echo $renderer->renderLintResult($result);
+ }
+ return 1;
+ }
- return 1;
+ return 99;
}
}
phutil_require_module('arcanist', 'exception/usage');
+phutil_require_module('arcanist', 'lint/renderer');
+phutil_require_module('arcanist', 'lint/severity');
phutil_require_module('arcanist', 'workflow/base');
+phutil_require_module('arcanist', 'workingcopyidentity');
phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'future/exec');
+phutil_require_module('phutil', 'symbols');
+phutil_require_module('phutil', 'utils');
phutil_require_source('ArcanistSvnHookPreCommitWorkflow.php');
continue;
}
$proj_raw = Filesystem::readFile($config_file);
- $proj = json_decode($proj_raw, true);
- if (!is_array($proj)) {
- throw new Exception(
- "Unable to parse '.arcconfig' file in '{$dir}'. The file contents ".
- "should be valid JSON.");
- }
- $required_keys = array(
- 'project_id',
- );
- foreach ($required_keys as $key) {
- if (!array_key_exists($key, $proj)) {
- throw new Exception(
- "Required key '{$key}' is missing from '.arcconfig' file in ".
- "'{$dir}'.");
- }
- }
- $config = $proj;
+ $config = self::parseRawConfigFile($proj_raw);
$project_root = $dir;
break;
}
return new ArcanistWorkingCopyIdentity($project_root, $config);
}
+ public static function newFromRootAndConfigFile($root, $config_raw) {
+ $config = self::parseRawConfigFile($config_raw);
+ return new ArcanistWorkingCopyIdentity($root, $config);
+ }
+
+ private static function parseRawConfigFile($raw_config) {
+ $proj = json_decode($raw_config, true);
+ if (!is_array($proj)) {
+ throw new Exception(
+ "Unable to parse '.arcconfig' file in '{$dir}'. The file contents ".
+ "should be valid JSON.");
+ }
+ $required_keys = array(
+ 'project_id',
+ );
+ foreach ($required_keys as $key) {
+ if (!array_key_exists($key, $proj)) {
+ throw new Exception(
+ "Required key '{$key}' is missing from '.arcconfig' file in ".
+ "'{$dir}'.");
+ }
+ }
+ return $proj;
+ }
+
protected function __construct($root, array $config) {
$this->projectRoot = $root;
$this->projectConfig = $config;