Skip to content

Commit

Permalink
Do not fetch branches, perform instead a single git clone
Browse files Browse the repository at this point in the history
  • Loading branch information
omarlopesino committed Oct 30, 2024
1 parent ceb2647 commit de24b5f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/DrupalArtifactBuilderGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,26 @@ 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 --depth 1 %s %s', $this->getConfiguration()->getRepository(), self::ARTIFACT_REPOSITORY_FOLDER));

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

$this->runCommand(sprintf(
'git clone %s %s --depth 1 %s',
$this->getConfiguration()->getRepository(),
$branch_exists ? sprintf('--branch %s', $branch) : '',
self::ARTIFACT_REPOSITORY_FOLDER)
);

chdir(self::ARTIFACT_REPOSITORY_FOLDER);

// Checkout to new branch only when branch does not exists.
if (!$branch_exists) {
$this->runCommand(sprintf('git checkout -b %s', $this->getConfiguration()->getBranch()));
}

$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 de24b5f

Please sign in to comment.