Skip to content

Commit

Permalink
Fixed bug #20402 : SVN pre-commit hook fails due to unknown argument …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
gsherwood committed Sep 11, 2014
1 parent 45d711d commit 2e12bfc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
19 changes: 13 additions & 6 deletions CodeSniffer/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ public function processShortArgument($arg, $pos)
if ($this->dieOnUnknownArg === false) {
$this->values[$arg] = $arg;
} else {
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
$this->processUnknownArgument('-'.$arg, $pos);
}
}//end switch

Expand Down Expand Up @@ -643,9 +641,7 @@ public function processLongArgument($arg, $pos)
$this->values[$arg] = $value;
}
} else {
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
$this->processUnknownArgument('--'.$arg, $pos);
}
}//end if

Expand All @@ -667,6 +663,17 @@ public function processLongArgument($arg, $pos)
*/
public function processUnknownArgument($arg, $pos)
{
// We don't know about any additional switches; just files.
if ($arg{0} === '-') {
if ($this->dieOnUnknownArg === false) {
return;
}

echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}

$file = PHP_CodeSniffer::realpath($arg);
if (file_exists($file) === false) {
if ($this->dieOnUnknownArg === false) {
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #20378 : Report appended to existing file if no errors found in run
- Fixed bug #20381 : Invalid "Comment closer must be on a new line"
-- Thanks to Brad Kent for the patch
- Fixed bug #20402 : SVN pre-commit hook fails due to unknown argument error
</notes>
<contents>
<dir name="/">
Expand Down
28 changes: 15 additions & 13 deletions scripts/phpcs-svn-pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,16 @@ class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
/**
* Processes an unknown command line argument.
*
* All unknown args are sent to SVN commands.
* Assumes all unknown arguments are files and folders to check.
*
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
* @param array $values An array of values determined from CLI args.
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
*
* @return array The updated CLI values.
* @see getCommandLineValues()
* @return void
*/
public function processUnknownArgument($arg, $pos, $values)
public function processUnknownArgument($arg, $pos)
{
$values['svnArgs'][] = escapeshellarg($arg);
return $values;
$this->values['svnArgs'][] = escapeshellarg($arg);

}//end processUnknownArgument()

Expand All @@ -80,12 +77,15 @@ class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
* @param array $values An array of values determined from CLI args.
*
* @return int The number of error and warning messages shown.
* @see getCommandLineValues()
* @see getCommandLineValues()
*/
public function process($values=array())
{
if (empty($values) === true) {
$values = parent::getCommandLineValues();
$values = $this->getCommandLineValues();
} else {
$values = array_merge($this->getDefaults(), $values);
$this->values = $values;
}

// Get list of files in this transaction.
Expand Down Expand Up @@ -127,6 +127,8 @@ class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
// let PHP_CodeSniffer decide on the defaults.
if (empty($values['extensions']) === false) {
$phpcs->setAllowedFileExtensions($values['extensions']);
} else {
$phpcs->setAllowedFileExtensions(array_keys($phpcs->defaultFileExtensions));
}

// Set ignore patterns if they were specified.
Expand Down Expand Up @@ -217,11 +219,11 @@ class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
}//end class

$phpcs = new PHP_CodeSniffer_SVN_Hook();

PHP_CodeSniffer_Reporting::startTiming();
$phpcs->checkRequirements();

$numErrors = $phpcs->process();
if ($numErrors !== 0) {
exit(1);
}

?>

0 comments on commit 2e12bfc

Please sign in to comment.