diff --git a/src/GitRepository.php b/src/GitRepository.php index e677f3e..98fc99e 100644 --- a/src/GitRepository.php +++ b/src/GitRepository.php @@ -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; } diff --git a/tests/GitPhp/GitRepository.branches.phpt b/tests/GitPhp/GitRepository.branches.phpt index 3b41d48..3b596cb 100644 --- a/tests/GitPhp/GitRepository.branches.phpt +++ b/tests/GitPhp/GitRepository.branches.phpt @@ -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');