public function branchExists($branchName, $dir = null, $mustRun = false)
{
// The porcelain command 'git branch' is less strict about character
// encoding than (otherwise simpler) plumbing commands such as
// 'git show-ref'.
$result = $this->execute(['branch'], $dir, $mustRun);
$branches = array_map(function ($line) {
return trim(ltrim($line, '* '));
}, explode("\n", $result));
return in_array($branchName, $branches, TRUE);
}