Platformsh\Cli\Helper\GitHelper::init PHP Method

init() public method

Create a Git repository in a directory.
public init ( string $dir, boolean $mustRun = false ) : boolean
$dir string
$mustRun boolean Enable exceptions if the Git command fails.
return boolean
    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);
    }

Usage Example

 /**
  * @{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"');
 }
All Usage Examples Of Platformsh\Cli\Helper\GitHelper::init