Skip to content

Commit

Permalink
GitRepository: checkout - removed '--end-of-options' (closes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Apr 24, 2022
1 parent 807e59f commit 8a84f69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,19 @@ public function getLocalBranches()
*/
public function checkout($name)
{
$this->run('checkout', '--end-of-options', $name);
if (!is_string($name)) {
throw new InvalidArgumentException('Branch name must be string.');
}

if ($name === '') {
throw new InvalidArgumentException('Branch name cannot be empty.');
}

if ($name[0] === '-') {
throw new InvalidArgumentException('Branch name cannot be option name.');
}

$this->run('checkout', $name);
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/GitPhp/GitRepository.branches.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ $git = new Git($runner);

$runner->assert(['branch', '--end-of-options', 'master']);
$runner->assert(['branch', '--end-of-options', 'develop']);
$runner->assert(['checkout', '--end-of-options', 'develop']);
$runner->assert(['checkout', 'develop']);
$runner->assert(['merge', '--end-of-options', 'feature-1']);
$runner->assert(['branch', '-d', 'feature-1']);
$runner->assert(['checkout', '--end-of-options', 'master']);
$runner->assert(['checkout', 'master']);

$repo = $git->open(__DIR__);
$repo->createBranch('master');
Expand Down

0 comments on commit 8a84f69

Please sign in to comment.