Skip to content

Commit

Permalink
Issue #399: Improve artifact clone time by doing shallow clone / fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
omarlopesino committed Oct 30, 2024
1 parent f1709af commit ceb2647
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/DrupalArtifactBuilderGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ protected function gitSetup() {
// This is done after creating the artifact and not before
// so there are no residual files, plus giving more options
// to create artifacts than pushing the changes to a git repository (s.e.: generating a .tar.gz.).
$this->runCommand(sprintf('git clone %s %s', $this->getConfiguration()->getRepository(), self::ARTIFACT_REPOSITORY_FOLDER));
$this->runCommand(sprintf('git clone --depth 1 %s %s', $this->getConfiguration()->getRepository(), self::ARTIFACT_REPOSITORY_FOLDER));

// Checkout to the branch (create if new):
chdir(self::ARTIFACT_REPOSITORY_FOLDER);
$ls_remote = $this->runCommand(sprintf('git ls-remote --heads origin %s', $this->getConfiguration()->getBranch()));
$branch = $this->getConfiguration()->getBranch();
$ls_remote = $this->runCommand(sprintf('git ls-remote --heads origin %s', $branch));
$ls_remote_output = trim($ls_remote->getOutput());
$this->runCommand(sprintf('git checkout %s %s', empty($ls_remote_output) ? '-b': '', $this->getConfiguration()->getBranch()));
$branch_exists = !empty($ls_remote_output);
if ($branch_exists) {
$this->runCommand(sprintf('git fetch --depth 1 origin %s', $branch));
}

$this->runCommand(sprintf('git checkout %s %s', !$branch_exists ? '-b': '', $this->getConfiguration()->getBranch()));
chdir($this->rootFolder);

$this->runCommand(sprintf('cp -r %s/.git %s', self::ARTIFACT_REPOSITORY_FOLDER, SELF::ARTIFACT_FOLDER));
Expand Down

0 comments on commit ceb2647

Please sign in to comment.