public function init($dir, $mustRun = false) { if (is_dir($dir . '/.git')) { throw new \InvalidArgumentException("Already a repository: {$dir}"); } return (bool) $this->execute(['init'], $dir, $mustRun, false); }
/** * @{inheritdoc} * * Set up before every test. * * @throws \Exception */ public function setUp() { $this->tempDirSetUp(); $repository = $this->getRepositoryDir(); if (!is_dir($repository) && !mkdir($repository, 0755, true)) { throw new \Exception("Failed to create directories."); } $this->gitHelper = new GitHelper(); $this->gitHelper->init($repository, true); $this->gitHelper->setDefaultRepositoryDir($repository); chdir($repository); // Ensure we are on the master branch. $this->gitHelper->checkOut('master'); // Add required Git config before committing. shell_exec('git config user.email [email protected]'); shell_exec('git config user.name "Test"'); shell_exec('git config commit.gpgsign false'); // Make a dummy commit so that there is a HEAD. touch($repository . '/README.txt'); shell_exec('git add -A && git commit -qm "Initial commit"'); }