From 638498f9ea84317988179e33c26d44cc4178169f Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Thu, 21 Nov 2019 21:25:04 +1100 Subject: [PATCH] Fix verbosity output. (#33) --- src/ArtefactTrait.php | 6 +++--- src/GitTrait.php | 27 +++++++++++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/ArtefactTrait.php b/src/ArtefactTrait.php index 9610395..61ff365 100644 --- a/src/ArtefactTrait.php +++ b/src/ArtefactTrait.php @@ -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) { @@ -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; @@ -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; diff --git a/src/GitTrait.php b/src/GitTrait.php index de9b16e..315f56f 100644 --- a/src/GitTrait.php +++ b/src/GitTrait.php @@ -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()); @@ -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()); @@ -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())); @@ -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(); @@ -287,11 +293,14 @@ 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) @@ -299,7 +308,9 @@ protected function gitCommand($location = null) 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);