Skip to content

Commit 044dbe5

Browse files
committed
Add verbose message
1 parent 3250512 commit 044dbe5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Git.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ class Git
88
/** @var IRunner */
99
protected $runner;
1010

11+
/** @var bool */
12+
protected $verboseException;
1113

12-
public function __construct(IRunner $runner = NULL)
14+
public function __construct(IRunner $runner = NULL, $verboseException = false)
1315
{
1416
$this->runner = $runner !== NULL ? $runner : new Runners\CliRunner;
17+
$this->verboseException = $verboseException;
1518
}
1619

1720

@@ -21,7 +24,7 @@ public function __construct(IRunner $runner = NULL)
2124
*/
2225
public function open($directory)
2326
{
24-
return new GitRepository($directory, $this->runner);
27+
return new GitRepository($directory, $this->runner, $this->verboseException);
2528
}
2629

2730

@@ -142,7 +145,8 @@ private function run($cwd, array $args, array $env = NULL)
142145
$result = $this->runner->run($cwd, $args, $env);
143146

144147
if (!$result->isOk()) {
145-
throw new GitException("Command '{$result->getCommand()}' failed (exit-code {$result->getExitCode()}).", $result->getExitCode(), NULL, $result);
148+
$exceptionMessage = $this->verboseException ? $result->toText() : "Command '{$result->getCommand()}' failed (exit-code {$result->getExitCode()}).";
149+
throw new GitException($exceptionMessage, $result->getExitCode(), NULL, $result);
146150
}
147151

148152
return $result;

src/GitRepository.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ class GitRepository
1111
/** @var IRunner */
1212
protected $runner;
1313

14+
/** @var bool */
15+
protected $verboseException;
1416

1517
/**
1618
* @param string $repository
1719
* @throws GitException
1820
*/
19-
public function __construct($repository, IRunner $runner = NULL)
21+
public function __construct($repository, IRunner $runner = NULL, $verboseException = false)
2022
{
2123
if (basename($repository) === '.git') {
2224
$repository = dirname($repository);
@@ -30,6 +32,7 @@ public function __construct($repository, IRunner $runner = NULL)
3032

3133
$this->repository = $path;
3234
$this->runner = $runner !== NULL ? $runner : new Runners\CliRunner;
35+
$this->verboseException = $verboseException;
3336
}
3437

3538

@@ -601,7 +604,8 @@ protected function run(...$args)
601604
$result = $this->runner->run($this->repository, $args);
602605

603606
if (!$result->isOk()) {
604-
throw new GitException("Command '{$result->getCommand()}' failed (exit-code {$result->getExitCode()}).", $result->getExitCode(), NULL, $result);
607+
$exceptionMessage = $this->verboseException ? $result->toText() : "Command '{$result->getCommand()}' failed (exit-code {$result->getExitCode()}).";
608+
throw new GitException($exceptionMessage, $result->getExitCode(), NULL, $result);
605609
}
606610

607611
return $result;

0 commit comments

Comments
 (0)