public function getActiveBranchName($defaultBranch = null)
{
$activeBranch = $this->processHelper->runCommand('git rev-parse --abbrev-ref HEAD');
// Detached head, use default branch
if ('HEAD' === $activeBranch) {
$activeBranch = $defaultBranch;
}
if (null === $activeBranch) {
throw new \RuntimeException('You are currently in a detached HEAD state, unable to get active branch-name.' . 'Please run `git checkout` first.');
}
return $activeBranch;
}
/** * @test */ public function gets_current_git_branch_name() { exec('git rev-parse --abbrev-ref HEAD', $output); if ('HEAD' === $output[0]) { $this->markTestSkipped('Unable to run this test in a detached HEAD state.'); } $this->assertEquals($output[0], $this->git->getActiveBranchName()); }