Skip to content

Commit

Permalink
Merge pull request #32 from utopia-php/feat-git-shallow-clone
Browse files Browse the repository at this point in the history
feat: git optimizations
  • Loading branch information
christyjacob4 authored and loks0n committed Dec 10, 2024
1 parent 7622330 commit b10225f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
docker run --rm -v $PWD:/app composer:2.6 sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
11 changes: 8 additions & 3 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,22 +532,27 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri
"git config --global init.defaultBranch main",
"git init",
"git remote add origin {$cloneUrl}",
// Enable sparse checkout
"git config core.sparseCheckout true",
"echo {$rootDirectory} >> .git/info/sparse-checkout",
// Disable fetching of refs we don't need
"git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'",
// Disable fetching of tags
"git config remote.origin.tagopt --no-tags",
];

switch ($versionType) {
case self::CLONE_TYPE_BRANCH:
$branchName = escapeshellarg($version);
$commands[] = "if git ls-remote --exit-code --heads origin {$branchName}; then git pull origin {$branchName} && git checkout {$branchName}; else git checkout -b {$branchName}; fi";
$commands[] = "if git ls-remote --exit-code --heads origin {$branchName}; then git pull --depth=1 origin {$branchName} && git checkout {$branchName}; else git checkout -b {$branchName}; fi";
break;
case self::CLONE_TYPE_COMMIT:
$commitHash = escapeshellarg($version);
$commands[] = "git pull origin {$commitHash}";
$commands[] = "git fetch --depth=1 origin {$commitHash} && git checkout {$commitHash}";
break;
case self::CLONE_TYPE_TAG:
$tagName = escapeshellarg($version);
$commands[] = "git pull origin $(git ls-remote --tags origin {$tagName} | tail -n 1 | awk -F '/' '{print $3}')";
$commands[] = "git fetch --depth=1 origin refs/tags/$(git ls-remote --tags origin {$tagName} | tail -n 1 | awk -F '/' '{print $3}') && git checkout FETCH_HEAD";
break;
}

Expand Down

0 comments on commit b10225f

Please sign in to comment.