refactor(git): improve submodule cloning

This commit is contained in:
peaklabs-dev 2025-08-27 17:13:28 +02:00
parent 21fc1ba254
commit 6c560261f2
No known key found for this signature in database

View file

@ -999,7 +999,7 @@ public function setGitImportSettings(string $deployment_uuid, string $git_clone_
}
// Add shallow submodules flag if shallow clone is enabled
$submoduleFlags = $isShallowCloneEnabled ? '--depth=1' : '';
$git_clone_command = "{$git_clone_command} GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git submodule update --init --recursive {$submoduleFlags}; fi";
$git_clone_command = "{$git_clone_command} git submodule sync && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git submodule update --init --recursive {$submoduleFlags}; fi";
}
if ($this->settings->is_git_lfs_enabled) {
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git lfs pull";
@ -1139,9 +1139,17 @@ public function generateGitImportCommands(string $deployment_uuid, int $pull_req
$isShallowCloneEnabled = $this->settings?->is_git_shallow_clone_enabled ?? false;
$depthFlag = $isShallowCloneEnabled ? ' --depth=1' : '';
$git_clone_command = "git clone{$depthFlag} -b {$escapedBranch}";
$submoduleFlags = '';
if ($this->settings->is_git_submodules_enabled) {
$submoduleFlags = ' --recurse-submodules';
if ($isShallowCloneEnabled) {
$submoduleFlags .= ' --shallow-submodules';
}
}
$git_clone_command = "git clone{$depthFlag}{$submoduleFlags} -b {$escapedBranch}";
if ($only_checkout) {
$git_clone_command = "git clone{$depthFlag} --no-checkout -b {$escapedBranch}";
$git_clone_command = "git clone{$depthFlag}{$submoduleFlags} --no-checkout -b {$escapedBranch}";
}
if ($pull_request_id !== 0) {
$pr_branch_name = "pr-{$pull_request_id}-coolify";