/** * Set up the git repository for our build. * * @param GitWorkingCopy $workingCopy * @param string $url * @param string $branch * @return mixed */ protected function doGitInit(GitWorkingCopy $workingCopy, $url, $branch) { $workingCopy->init(); $workingCopy->remote('add', 'origin', $url); try { $this->output->writeln("Attempting to fetch <path>origin/{$branch}</path>", OutputInterface::VERBOSITY_VERBOSE); $workingCopy->fetch('origin', $branch)->checkout('-f', $branch); } catch (GitException $exception) { $this->output->writeln("Fetch failed, creating new branch instead", OutputInterface::VERBOSITY_VERBOSE); $workingCopy->checkout('--orphan', $branch)->run(['commit', '--allow-empty', '-m', "Branch created by steak"])->push('-u', 'origin', $branch); } return $workingCopy->clearOutput(); }