-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add git workflow to README * Add runGitWorkflow to executable * Add ShellException * Add exitWithCode and printError to ShellOperator * Add exitWithCode and printError to UnixShell * Always return a string from executeCommand * Use ShellOperator printError and exitWithCode * Add git option to cli docs * Use ShellException in SvnWorkflow * Add untracked/unmodified tests to SvnWorkflowTest * Add GitWorkflow * Add runGitWorkflow
- Loading branch information
1 parent
f8f124a
commit 30cfcaa
Showing
11 changed files
with
557 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PhpcsChanged\GitWorkflow; | ||
|
||
use PhpcsChanged\NonFatalException; | ||
use PhpcsChanged\ShellException; | ||
|
||
function validateGitFileExists(string $gitFile, string $git, callable $isReadable, callable $executeCommand, callable $debug): void { | ||
if (! $isReadable($gitFile)) { | ||
throw new ShellException("Cannot read file '{$gitFile}'"); | ||
} | ||
$gitStatusCommand = "${git} status --short " . escapeshellarg($gitFile); | ||
$debug('checking git existence of file with command:', $gitStatusCommand); | ||
$gitStatusOutput = $executeCommand($gitStatusCommand); | ||
$debug('git status output:', $gitStatusOutput); | ||
if (isset($gitStatusOutput[0]) && $gitStatusOutput[0] === '?') { | ||
throw new ShellException("File does not appear to be tracked by git: '{$gitFile}'"); | ||
} | ||
} | ||
|
||
function getGitUnifiedDiff(string $gitFile, string $git, callable $executeCommand, callable $debug): string { | ||
$unifiedDiffCommand = "{$git} diff --staged --no-prefix " . escapeshellarg($gitFile); | ||
$debug('running diff command:', $unifiedDiffCommand); | ||
$unifiedDiff = $executeCommand($unifiedDiffCommand); | ||
if (! $unifiedDiff) { | ||
throw new NonFatalException("Cannot get git diff for file '{$gitFile}'; skipping"); | ||
} | ||
$debug('diff command output:', $unifiedDiff); | ||
return $unifiedDiff; | ||
} | ||
|
||
function isNewGitFile(string $gitFile, string $git, callable $executeCommand, callable $debug): bool { | ||
$gitStatusCommand = "${git} status --short " . escapeshellarg($gitFile); | ||
$debug('checking git status of file with command:', $gitStatusCommand); | ||
$gitStatusOutput = $executeCommand($gitStatusCommand); | ||
$debug('git status output:', $gitStatusOutput); | ||
if (! $gitStatusOutput || false === strpos($gitStatusOutput, $gitFile)) { | ||
throw new ShellException("Cannot get git status for file '{$gitFile}'"); | ||
} | ||
if (isset($gitStatusOutput[0]) && $gitStatusOutput[0] === '?') { | ||
throw new ShellException("File does not appear to be tracked by git: '{$gitFile}'"); | ||
} | ||
return isset($gitStatusOutput[0]) && $gitStatusOutput[0] === 'A'; | ||
} | ||
|
||
function getGitBasePhpcsOutput(string $gitFile, string $git, string $phpcs, string $phpcsStandardOption, callable $executeCommand, callable $debug): string { | ||
$oldFilePhpcsOutputCommand = "${git} show HEAD:" . escapeshellarg($gitFile) . " | {$phpcs} --report=json" . $phpcsStandardOption; | ||
$debug('running orig phpcs command:', $oldFilePhpcsOutputCommand); | ||
$oldFilePhpcsOutput = $executeCommand($oldFilePhpcsOutputCommand); | ||
if (! $oldFilePhpcsOutput) { | ||
throw new ShellException("Cannot get old phpcs output for file '{$gitFile}'"); | ||
} | ||
$debug('orig phpcs command output:', $oldFilePhpcsOutput); | ||
return $oldFilePhpcsOutput; | ||
} | ||
|
||
function getGitNewPhpcsOutput(string $gitFile, string $phpcs, string $cat, string $phpcsStandardOption, callable $executeCommand, callable $debug): string { | ||
$newFilePhpcsOutputCommand = "{$cat} " . escapeshellarg($gitFile) . " | {$phpcs} --report=json" . $phpcsStandardOption; | ||
$debug('running new phpcs command:', $newFilePhpcsOutputCommand); | ||
$newFilePhpcsOutput = $executeCommand($newFilePhpcsOutputCommand); | ||
if (! $newFilePhpcsOutput) { | ||
throw new ShellException("Cannot get new phpcs output for file '{$gitFile}'"); | ||
} | ||
$debug('new phpcs command output:', $newFilePhpcsOutput); | ||
return $newFilePhpcsOutput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PhpcsChanged; | ||
|
||
class ShellException extends \Exception { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.