fix: fall back to provider worktree for deploy sources

This commit is contained in:
Codex
2026-05-16 18:35:26 +00:00
parent 285580b614
commit cd2aebfe75
+33 -7
View File
@@ -437,6 +437,11 @@ function sourceWorkDir(service: UniDeskMicroserviceConfig): string {
return targetWorkDir(service);
}
function sourceFallbackWorktree(service: UniDeskMicroserviceConfig): string {
if (targetIsMain(service) || isUnideskRepo(service.repository.url)) return "";
return service.development.worktreePath;
}
function sourceRootSubdir(service: UniDeskMicroserviceConfig): string {
const claudeqqPrefix = "claudeqq/";
if (service.id === "claudeqq" && service.repository.url !== unideskRepoUrl && service.repository.dockerfile.startsWith(claudeqqPrefix)) {
@@ -597,6 +602,7 @@ function prepareSourceScript(service: UniDeskMicroserviceConfig, desired: Deploy
"printf 'resolved_commit=%s\\nexport_dir=%s\\nsource_repo=%s\\n' \"$resolved\" \"$export_dir\" \"$repo\"",
].join("\n");
}
const fallbackWorktree = sourceFallbackWorktree(service);
return [
"set -euo pipefail",
sourceProxyPrelude(service),
@@ -604,16 +610,36 @@ function prepareSourceScript(service: UniDeskMicroserviceConfig, desired: Deploy
`repo_url=${shellQuote(providerSourceRepoUrl(desired.repo))}`,
`commit=${shellQuote(desired.commitId)}`,
`export_dir=${shellQuote(exportDir)}`,
`fallback_worktree=${shellQuote(fallbackWorktree)}`,
"mkdir -p \"$(dirname \"$repo\")\" \"$(dirname \"$export_dir\")\"",
"if [ ! -d \"$repo/.git\" ]; then rm -rf \"$repo\"; git clone --no-checkout \"$repo_url\" \"$repo\"; fi",
"cd \"$repo\"",
"git remote set-url origin \"$repo_url\"",
"git fetch --no-tags origin \"$commit\" || git fetch --no-tags origin '+refs/heads/*:refs/remotes/origin/*'",
"resolved=$(git rev-parse --verify \"$commit^{commit}\")",
"source_repo=\"\"",
"source_mode=\"remote-fetch\"",
"source_log=$(mktemp /tmp/unidesk-deploy-source.XXXXXX.log)",
"if { [ -d \"$repo/.git\" ] || { rm -rf \"$repo\" && git clone --no-checkout \"$repo_url\" \"$repo\"; }; } >\"$source_log\" 2>&1; then",
" cd \"$repo\"",
" if { git remote set-url origin \"$repo_url\" && { git fetch --no-tags origin \"$commit\" || git fetch --no-tags origin '+refs/heads/*:refs/remotes/origin/*'; } && git rev-parse --verify \"$commit^{commit}\" > /tmp/unidesk-deploy-resolved-commit; } >>\"$source_log\" 2>&1; then",
" resolved=$(cat /tmp/unidesk-deploy-resolved-commit)",
" source_repo=\"$repo\"",
" fi",
"fi",
"if [ -z \"$source_repo\" ]; then",
" echo target_source_remote_prepare=failed",
" tail -80 \"$source_log\" || true",
" if [ -n \"$fallback_worktree\" ] && git -C \"$fallback_worktree\" rev-parse --is-inside-work-tree >/dev/null 2>&1 && git -C \"$fallback_worktree\" rev-parse --verify \"$commit^{commit}\" > /tmp/unidesk-deploy-resolved-commit 2>/dev/null; then",
" resolved=$(cat /tmp/unidesk-deploy-resolved-commit)",
" source_repo=\"$fallback_worktree\"",
" source_mode=\"provider-worktree\"",
" printf 'target_source_fallback_worktree=%s\\n' \"$fallback_worktree\"",
" else",
" cat \"$source_log\" >&2 || true",
" exit 128",
" fi",
"fi",
"rm -rf \"$export_dir\"",
"mkdir -p \"$export_dir\"",
"git archive --format=tar \"$resolved\" | tar -xf - -C \"$export_dir\"",
"printf 'resolved_commit=%s\\nexport_dir=%s\\n' \"$resolved\" \"$export_dir\"",
"git -C \"$source_repo\" archive --format=tar \"$resolved\" | tar -xf - -C \"$export_dir\"",
"rm -f \"$source_log\" /tmp/unidesk-deploy-resolved-commit",
"printf 'resolved_commit=%s\\nexport_dir=%s\\nsource_repo=%s\\nsource_mode=%s\\n' \"$resolved\" \"$export_dir\" \"$source_repo\" \"$source_mode\"",
].filter((line) => line.length > 0).join("\n");
}