You are here

function hackedProjectWebDevDownloader::git_clone in Hacked! 8.2

Clones a git repository in a temporary directory.

Parameters

$giturl: URL of the project.

$path: The location in which to place the checkout.

$branch: The branch to check out.

Throws

Exception on failure.

1 call to hackedProjectWebDevDownloader::git_clone()
hackedProjectWebDevDownloader::download in src/hackedProjectWebDevDownloader.php
Download the version of the project to compare.

File

src/hackedProjectWebDevDownloader.php, line 102

Class

hackedProjectWebDevDownloader
Downloads a development snapshot of a project using Git.

Namespace

Drupal\hacked

Code

function git_clone($giturl, $path, $branch) {

  // Get the Git command and location information.
  $git_cmd = $this
    ->git_get_command();
  $dirname = dirname($path);
  $basename = basename($path);

  // Prepare the download location.
  \Drupal::service('file_system')
    ->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY);
  \Drupal::service('file_system')
    ->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);

  // Perform the clone operation, and leave us in the appropriate branch.
  exec("cd {$dirname}; {$git_cmd} clone --branch {$branch} {$giturl} {$basename}", $output_lines, $return_value);

  // Throw an exception if it didn't work.
  if ($return_value != 0) {
    throw new Exception($this
      ->t('Could not clone project %project into path %path at branch %branch.', [
      '%project' => $this->project
        ->title(),
      '%path' => $path,
      '%branch' => $branch,
    ]));
  }
}