Skip to content

Commit

Permalink
#36: Implement direct clone functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Rombauts committed Dec 12, 2017
1 parent 51c356e commit ad41c45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Joomlatools/Console/Command/Site/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ protected function configure()
->addOption(
'clone',
null,
InputOption::VALUE_NONE,
'Clone the Git repository instead of creating a copy in the target directory.'
InputOption::VALUE_OPTIONAL,
'Clone the Git repository instead of creating a copy in the target directory. Use --clone=shallow for a shallow clone or leave empty.',
true
);
}

Expand Down
24 changes: 16 additions & 8 deletions src/Joomlatools/Console/Command/Site/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected function configure()
->addOption(
'clone',
null,
InputOption::VALUE_NONE,
'Clone the Git repository instead of creating a copy in the target directory.'
InputOption::VALUE_OPTIONAL,
'Clone the Git repository instead of creating a copy in the target directory. Use --clone=shallow for a shallow clone or leave empty.'
)
;
}
Expand Down Expand Up @@ -227,9 +227,7 @@ protected function _setupClone()
throw new \RuntimeException(sprintf('The --clone flag requires a valid Git repository'));
}

$repository = $this->versions->getRepository();

$this->_clone();
$this->_clone($this->target_dir, $this->version);
}

protected function _getTarball()
Expand Down Expand Up @@ -315,18 +313,28 @@ protected function _download($target)
/**
* Clone Git repository to $target directory
*
* @param $target
* @param $target Target directory
* @param $tag Tag or branch to check out
* @return bool
*/
protected function _clone($directory)
protected function _clone($directory, $tag = false)
{
$repository = $this->versions->getRepository();

if (!file_exists($directory))
{
$this->output->writeln("<info>Cloning $repository - this could take a few minutes ..</info>");

exec(sprintf("git clone --recursive %s %s", escapeshellarg($repository), escapeshellarg($directory)), $result, $exit_code);
$option = strtolower($this->input->getOption('clone'));
$args = $option == 'shallow' ? '--depth 1' : '';

if (is_string($tag)) {
$args .= sprintf(' --branch %s', escapeshellarg($tag));
}

$command = sprintf("git clone %s --recursive %s %s", $args, escapeshellarg($repository), escapeshellarg($directory));

exec($command, $result, $exit_code);

if ($exit_code > 0) {
return false;
Expand Down

0 comments on commit ad41c45

Please sign in to comment.