Skip to content

Commit

Permalink
Fix verbosity output. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Skrypnyk authored Nov 21, 2019
1 parent 6d0f7a0 commit 638498f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/ArtefactTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ protected function resolveOriginalBranch($location)
// capture the source of detachment, if exist.
if ($branch == 'HEAD') {
$branch = null;
$result = $this->gitCommandRun($location, 'branch');
$result = $this->gitCommandRun($location, 'branch', true);
$branchList = array_filter(preg_split('/\R/', $result->getMessage()));

foreach ($branchList as $branch) {
Expand Down Expand Up @@ -690,7 +690,7 @@ protected function removeIgnoredFiles($location, $gitignorePath = null)
}

$command = sprintf('ls-files --directory -i --exclude-from=%s %s', $gitignorePath, $location);
$result = $this->gitCommandRun($location, $command, 'Unable to remove ignored files');
$result = $this->gitCommandRun($location, $command, 'Unable to remove ignored files', true);
$files = array_filter(preg_split('/\R/', $result->getMessage()));
foreach ($files as $file) {
$fileName = $location.DIRECTORY_SEPARATOR.$file;
Expand All @@ -715,7 +715,7 @@ protected function removeIgnoredFiles($location, $gitignorePath = null)
protected function removeOtherFiles($location)
{
$command = sprintf('ls-files --others --exclude-standard');
$result = $this->gitCommandRun($location, $command, 'Unable to remove other files');
$result = $this->gitCommandRun($location, $command, 'Unable to remove other files', true);
$files = array_filter(preg_split('/\R/', $result->getMessage()));
foreach ($files as $file) {
$fileName = $location.DIRECTORY_SEPARATOR.$file;
Expand Down
27 changes: 19 additions & 8 deletions src/GitTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected function gitRemoteExists($location, $name)
$result = $this->gitCommandRun(
$location,
sprintf('remote'),
'Unable to list remotes'
'Unable to list remotes',
true
);

$lines = preg_split('/\R/', $result->getMessage());
Expand Down Expand Up @@ -222,7 +223,8 @@ protected function gitGetCurrentBranch($location)
$result = $this->gitCommandRun(
$location,
'rev-parse --abbrev-ref HEAD',
'Unable to get current repository branch'
'Unable to get current repository branch',
true
);

return trim($result->getMessage());
Expand All @@ -244,7 +246,8 @@ protected function gitGetTags($location)
$result = $this->gitCommandRun(
$location,
'tag -l --points-at HEAD',
'Unable to retrieve tags'
'Unable to retrieve tags',
true
);

return array_filter(preg_split('/\R/', $result->getMessage()));
Expand All @@ -263,14 +266,17 @@ protected function gitGetTags($location)
* Command to run.
* @param null $errorMessage
* Optional error message.
* @param bool $noDebug
* Flag to enforce no-debug mode. Used by commands that use output for
* values.
*
* @return \Robo\Result
* Result object.
* @throws \Exception If command did not finish successfully.
*/
protected function gitCommandRun($location, $command, $errorMessage = null)
protected function gitCommandRun($location, $command, $errorMessage = null, $noDebug = false)
{
$git = $this->gitCommand($location);
$git = $this->gitCommand($location, $noDebug);
$git->rawArg($command);
$result = $git->run();

Expand All @@ -287,19 +293,24 @@ protected function gitCommandRun($location, $command, $errorMessage = null)
*
* @param string $location
* Optional repository location.
* @param bool $noDebug
* Flag to enforce no-debug mode. Used by commands that use output for
* values.
*
* @return \Robo\Task\Base\Exec
* Exect task.
* Exec task.
*/
protected function gitCommand($location = null)
protected function gitCommand($location = null, $noDebug = false)
{
$git = $this->taskExec('git')
->printOutput(false)
->arg('--no-pager');

if ($this->debug) {
$git->env('GIT_SSH_COMMAND', 'ssh -vvv');
$git->printOutput(true);
if (!$noDebug) {
$git->printOutput(true);
}
$git->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_NORMAL);
} else {
$git->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG);
Expand Down

0 comments on commit 638498f

Please sign in to comment.