Commit: 4e53bfd3ee5c31216ceacffbbdbe5aef113a1696
Author: David Persson | Date: 2009-12-04 23:25:30 +0100
diff --git a/extensions/command/BranchUpgrade.php b/extensions/command/BranchUpgrade.php
index 309864e..ce53ca0 100644
--- a/extensions/command/BranchUpgrade.php
+++ b/extensions/command/BranchUpgrade.php
@@ -13,7 +13,7 @@ namespace app\extensions\command;
* When pushing a new version, cleans up all local version-dependent feature branches which are
* based on the existing version, and re-clones them based on the new version. For example:
*
- * {{{li3 branch_upgrade --project=/path/to 1.5 1.6}}}
+ * {{{li3 branch_upgrade /path/to/project 1.5 1.6}}}
*
* Given the local branch `data`, cloned from `origin/1.5-data`, the `data` branch will be dropped
* and re-checked-out from `origin/1.6-data`.
@@ -23,20 +23,20 @@ namespace app\extensions\command;
*/
class BranchUpgrade extends \lithium\console\Command {
- public $project;
-
- public function run() {
- if (count($this->request->params['passed']) < 2) {
- $this->_stop();
+ public function run($path) {
+ if (count($this->request->params['passed']) < 3) {
+ $this->error('Not enough arguments given.');
+ return false;
}
- if (!$this->project) {
- $this->project = $this->request->env['working'];
+ if (!$path = realpath($path) || !is_dir($path)) {
+ $this->error('Not a valid path to a project directory.');
+ return false;
}
list($old, $new) = $this->request->params['passed'];
$locals = $remotes = $trackings = array();
$current = null;
- chdir($this->project);
+ chdir($path);
`git pull origin`;
`git remote prune origin`;
diff --git a/extensions/command/Syntax.php b/extensions/command/Syntax.php
index c8e35fb..70b3d05 100644
--- a/extensions/command/Syntax.php
+++ b/extensions/command/Syntax.php
@@ -25,7 +25,7 @@ class Syntax extends \lithium\console\Command {
*
* @var string
*/
- public $checks;
+ public $checks = 'phpca';
/**
* A regex to exclude paths from being checked.
@@ -48,39 +48,57 @@ class Syntax extends \lithium\console\Command {
*/
public $blame;
- protected $_vcs;
+ protected $_project;
- public $project;
+ protected $_vcs;
- public function run($file = null) {
- if (!$this->checks) {
- $this->help();
- return 1;
- }
+ /**
+ * Main method.
+ *
+ * @param string $path Absolute path to file or directory.
+ */
+ public function run($path) {
$this->checks = explode(',' , $this->checks);
- if (!$this->project) {
- $this->project = $this->request->env['working'];
+ if (!$path = realpath($path)) {
+ $this->error('Not a valid path.');
+ return false;
}
- $this->project = realpath($this->project);
-
- if (is_dir($this->project . '/.git')) {
- $this->_vcs = 'git';
+ if (!$this->_project = $this->_project($path)) {
+ $this->error('Not a valid project.');
+ return false;
}
-
- if ($file[0] !== '/') {
- $file = $this->project . '/' . $file;
+ if (is_dir($this->_project . '/.git')) {
+ $this->_vcs = 'git';
}
- $failures = is_file($file) ? $this->_checkFile($file) : $this->_checkDirectory($file);
+ $failures = is_file($path) ? $this->_checkFile($path) : $this->_checkDirectory($path);
if ($this->metrics) {
$this->_metrics($failures);
}
- return $failures ? 1 : 0;
+ return !$failures;
+ }
+
+ public function checks() {
+ $this->header('Available Checks:');
+ $classes = array_unique(Libraries::locate('command.syntax', null, array(
+ 'recursive' => false
+ )));
+ foreach ($classes as $command) {
+ $command = explode('\\', $command);
+ $this->out(' - ' . Inflector::underscore(array_pop($command)));
+ }
+ }
+
+ protected function _project($path) {
+ while ($path && !is_dir($path . '/.git') && !is_dir($path . '/config/bootstrap.php')) {
+ $path = ($parent = dirname($path)) != $path ? $parent : false;
+ }
+ return $path;
}
protected function _checkFile($file) {
- $message = 'Checking syntax of `' . str_replace($this->project . '/', null, $file) .'`. ';
+ $message = 'Checking syntax of `' . str_replace($this->_project . '/', null, $file) .'`. ';
$this->out($message, false);
$failures = array();
@@ -133,17 +151,6 @@ class Syntax extends \lithium\console\Command {
return $failures;
}
- public function checks() {
- $this->header('Available Checks:');
- $classes = array_unique(Libraries::locate('command.syntax', null, array(
- 'recursive' => false
- )));
- foreach ($classes as $command) {
- $command = explode('\\', $command);
- $this->out(' - ' . Inflector::underscore(array_pop($command)));
- }
- }
-
protected function _metrics($failures) {
$this->header('Metrics');
$this->nl();
@@ -177,7 +184,7 @@ class Syntax extends \lithium\console\Command {
return null;
}
$backup = getcwd();
- chdir($this->project);
+ chdir($this->_project);
$lines = count(file($failure['file']));
$command = 'git blame -L{:start},{:end} --porcelain {:file}';