You are here

class Provision_PlatformGit in Aegir Deploy 7.3

@file The Provision_PlatformGit class.

Hierarchy

Expanded class hierarchy of Provision_PlatformGit

File

modules/platform_git/drush/Provision/PlatformGit.php, line 7
The Provision_PlatformGit class.

View source
class Provision_PlatformGit extends Provision_ShellCommand {

  // The prefix used for properties in Aegir contexts.
  protected $context_prefix = 'git_';

  // List of properties to load from the Aegir context.
  protected $context_properties = [
    'repository_url',
    'repository_path',
    'reference',
  ];

  // The Git reporitory URL from whence we'll clone.
  protected $repository_url = FALSE;

  // The local path to which we'll clone the repository.
  protected $repository_path = FALSE;

  // The Git reference that we'll clone or checkout.
  protected $reference = FALSE;

  // A list of references fetched from a Git repository.
  protected $references = [];
  public function validateProvisionVerify() {
    if ($this
      ->pathExists($this->repository_path)) {
      return $this
        ->notice(dt('Platform Git repository path already exists. Aborting.'));
    }
    else {
      return $this
        ->deployPlatform();
    }
  }
  protected function deployPlatform() {
    $this
      ->notice(dt('Deploying platform.'));
    return $this
      ->gitClone() && $this
      ->gitCheckout();
  }
  protected function gitClone() {
    $this
      ->notice(dt('Cloning `:url` to `:path`', [
      ':url' => $this->repository_url,
      ':path' => $this->repository_path,
    ]));
    return $this
      ->runCommand($this
      ->buildGitCloneCommand());
  }
  protected function gitCheckout() {
    if ($this
      ->referenceIsACommit()) {
      $this
        ->notice(dt('Fetching full Git history and checking out commit `:ref`', [
        ':ref' => $this->reference,
      ]));
      return $this
        ->runCommand($this
        ->buildGitCheckoutCommand());
    }
    return TRUE;
  }
  protected function buildGitCloneCommand() {
    $command = 'git clone --recursive --depth 1 --no-progress --quiet';
    if ($this
      ->referenceIsABranch() || $this
      ->referenceIsATag()) {
      $command .= ' --branch ' . escapeshellarg(trim($this->reference));
    }
    $command .= ' ' . escapeshellarg(trim($this->repository_url));
    $command .= ' ' . escapeshellarg(trim($this->repository_path));
    return $command;
  }
  protected function buildGitCheckoutCommand() {
    $command = 'cd ' . escapeshellarg(trim($this->repository_path));
    $command .= ' && git fetch --unshallow && ';
    $command .= 'git checkout ' . escapeshellarg(trim($this->reference));
    return $command;
  }
  protected function referenceIsABranch() {
    return $this->reference && in_array($this->reference, $this
      ->lsRemote('heads'));
  }
  protected function referenceIsATag() {
    return $this->reference && in_array($this->reference, $this
      ->lsRemote('tags'));
  }
  protected function referenceIsACommit() {
    return $this->reference && !$this
      ->referenceIsABranch() && !$this
      ->referenceIsATag();
  }
  protected function lsRemote($type = FALSE) {
    if (empty($this->references)) {
      $this
        ->notice(dt('Scanning remote git repository tags and branches.'));
      $debug = drush_get_context('DRUSH_DEBUG');
      drush_set_context('DRUSH_DEBUG', FALSE);
      drush_shell_exec('git ls-remote ' . escapeshellarg(trim($this->repository_url)));
      drush_set_context('DRUSH_DEBUG', $debug);
      $lines = drush_shell_exec_output();
      foreach ($lines as $line) {
        $ref = explode('/', $line);
        if (isset($ref[1]) && isset($ref[2])) {
          $this->references[$ref[1]][] = $ref[2];
        }
      }
    }
    return $type ? $this->references[$type] : $this->references;
  }
  public function postProvisionDelete() {
    if ($this->repository_path != d()->root) {
      $this
        ->notice(dt('Deleting repo path at: ') . d()->repo_path);
      _provision_recursive_delete($this->repository_path);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Provision_PlatformGit::$context_prefix protected property Overrides Provision_ShellCommand::$context_prefix
Provision_PlatformGit::$context_properties protected property Overrides Provision_ShellCommand::$context_properties
Provision_PlatformGit::$reference protected property
Provision_PlatformGit::$references protected property
Provision_PlatformGit::$repository_path protected property
Provision_PlatformGit::$repository_url protected property
Provision_PlatformGit::buildGitCheckoutCommand protected function
Provision_PlatformGit::buildGitCloneCommand protected function
Provision_PlatformGit::deployPlatform protected function
Provision_PlatformGit::gitCheckout protected function
Provision_PlatformGit::gitClone protected function
Provision_PlatformGit::lsRemote protected function
Provision_PlatformGit::postProvisionDelete public function
Provision_PlatformGit::referenceIsABranch protected function
Provision_PlatformGit::referenceIsACommit protected function
Provision_PlatformGit::referenceIsATag protected function
Provision_PlatformGit::validateProvisionVerify public function
Provision_ShellCommand::abort protected function
Provision_ShellCommand::error protected function
Provision_ShellCommand::execCommand protected function Run a command in a subprocess, and stream the output.
Provision_ShellCommand::log protected function
Provision_ShellCommand::notice protected function
Provision_ShellCommand::pathExists protected function
Provision_ShellCommand::runCommand protected function Run a command in a subshell, and post the output once complete.
Provision_ShellCommand::setProperty protected function
Provision_ShellCommand::success protected function
Provision_ShellCommand::warning protected function
Provision_ShellCommand::__construct public function Initialize properties from the current Aegir context.