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

checkOut() public method

Check out a branch.
public checkOut ( string $name, string | null $dir = null, boolean $mustRun = false, boolean $quiet = false ) : boolean
$name string
$dir string | null The path to a Git repository.
$mustRun boolean Enable exceptions if the Git command fails.
$quiet boolean
return boolean
    public function checkOut($name, $dir = null, $mustRun = false, $quiet = false)
    {
        return (bool) $this->execute(['checkout', $name], $dir, $mustRun, $quiet);
    }

Usage Example

 /**
  * Clone the app to the build directory via Git.
  *
  * @param string $buildDir
  */
 private function cloneToBuildDir($buildDir)
 {
     $gitRoot = $this->gitHelper->getRoot($this->appRoot, true);
     $ref = $this->gitHelper->execute(['rev-parse', 'HEAD'], $gitRoot, true);
     $cloneArgs = ['--recursive', '--shared'];
     $tmpRepo = $buildDir . '-repo';
     if (file_exists($tmpRepo)) {
         $this->fsHelper->remove($tmpRepo, true);
     }
     $this->gitHelper->cloneRepo($gitRoot, $tmpRepo, $cloneArgs, true);
     $this->gitHelper->checkOut($ref, $tmpRepo, true, true);
     $this->fsHelper->remove($tmpRepo . '/.git');
     $appDir = $tmpRepo . '/' . substr($this->appRoot, strlen($gitRoot));
     if (!rename($appDir, $buildDir)) {
         throw new \RuntimeException(sprintf('Failed to move app from %s to %s', $appDir, $buildDir));
     }
     $this->fsHelper->remove($tmpRepo);
 }
All Usage Examples Of Platformsh\Cli\Helper\GitHelper::checkOut