Skip to content

Commit

Permalink
GitRepository: uses '--no-color' option for 'git branch' commands
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed May 9, 2021
1 parent 96aca96 commit 0d437f2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function removeBranch($name)
public function getCurrentBranchName()
{
try {
$branch = $this->extractFromCommand(['branch', '-a'], function($value) {
$branch = $this->extractFromCommand(['branch', '-a', '--no-color'], function($value) {
if (isset($value[0]) && $value[0] === '*') {
return trim(substr($value, 1));
}
Expand All @@ -193,7 +193,7 @@ public function getCurrentBranchName()
*/
public function getBranches()
{
return $this->extractFromCommand(['branch', '-a'], function($value) {
return $this->extractFromCommand(['branch', '-a', '--no-color'], function($value) {
return trim(substr($value, 1));
});
}
Expand All @@ -206,7 +206,7 @@ public function getBranches()
*/
public function getRemoteBranches()
{
return $this->extractFromCommand(['branch', '-r'], function($value) {
return $this->extractFromCommand(['branch', '-r', '--no-color'], function($value) {
return trim(substr($value, 1));
});
}
Expand All @@ -219,7 +219,7 @@ public function getRemoteBranches()
*/
public function getLocalBranches()
{
return $this->extractFromCommand(['branch'], function($value) {
return $this->extractFromCommand(['branch', '--no-color'], function($value) {
return trim(substr($value, 1));
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/GitPhp/GitRepository.getBranches.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $runner = new MemoryRunner(__DIR__);
$git = new Git($runner);
$repo = $git->open(__DIR__);

$runner->setResult(['branch', '-a'], [], [
$runner->setResult(['branch', '-a', '--no-color'], [], [
' master',
'* develop',
' remotes/origin/master',
Expand All @@ -23,5 +23,5 @@ Assert::same([
], $repo->getBranches());


$runner->setResult(['branch', '-a'], [], []);
$runner->setResult(['branch', '-a', '--no-color'], [], []);
Assert::null($repo->getBranches());
6 changes: 3 additions & 3 deletions tests/GitPhp/GitRepository.getCurrentBranchName.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ $runner = new MemoryRunner(__DIR__);
$git = new Git($runner);
$repo = $git->open(__DIR__);

$runner->setResult(['branch', '-a'], [], [
$runner->setResult(['branch', '-a', '--no-color'], [], [
' master',
'* develop',
' remotes/origin/master',
]);
Assert::same('develop', $repo->getCurrentBranchName());


$runner->setResult(['branch', '-a'], [], []);
$runner->setResult(['branch', '-a', '--no-color'], [], []);
Assert::exception(function () use ($repo) {
$repo->getCurrentBranchName();
}, GitException::class, 'Getting of current branch name failed.');


$runner->setResult(['branch', '-a'], [], [], [], 1);
$runner->setResult(['branch', '-a', '--no-color'], [], [], [], 1);
Assert::exception(function () use ($repo) {
$repo->getCurrentBranchName();
}, GitException::class, 'Getting of current branch name failed.');
4 changes: 2 additions & 2 deletions tests/GitPhp/GitRepository.getLocalBranches.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $runner = new MemoryRunner(__DIR__);
$git = new Git($runner);
$repo = $git->open(__DIR__);

$runner->setResult(['branch'], [], [
$runner->setResult(['branch', '--no-color'], [], [
' master',
'* develop',
]);
Expand All @@ -21,5 +21,5 @@ Assert::same([
], $repo->getLocalBranches());


$runner->setResult(['branch'], [], []);
$runner->setResult(['branch', '--no-color'], [], []);
Assert::null($repo->getLocalBranches());
4 changes: 2 additions & 2 deletions tests/GitPhp/GitRepository.getRemoteBranches.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $runner = new MemoryRunner(__DIR__);
$git = new Git($runner);
$repo = $git->open(__DIR__);

$runner->setResult(['branch', '-r'], [], [
$runner->setResult(['branch', '-r', '--no-color'], [], [
' origin/master',
'* origin/version-2'
]);
Expand All @@ -21,5 +21,5 @@ Assert::same([
], $repo->getRemoteBranches());


$runner->setResult(['branch', '-r'], [], []);
$runner->setResult(['branch', '-r', '--no-color'], [], []);
Assert::null($repo->getRemoteBranches());

0 comments on commit 0d437f2

Please sign in to comment.