Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: git optimizations #32

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -529,22 +529,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
Loading