@@ -53,13 +53,8 @@ import type {
5353 RollbackInput ,
5454 MakeActiveResult ,
5555} from "./types" ;
56- import {
57- BuildLogger ,
58- injectGitToken ,
59- runBuildPipeline ,
60- sq ,
61- type BuildEnvironment ,
62- } from "./build-pipeline" ;
56+ import { BuildLogger , runBuildPipeline , sq , type BuildEnvironment } from "./build-pipeline" ;
57+ import { assembleGitClone , gitShellCommand , GIT_SUBMODULE_UPDATE_ARGS } from "./git-clone" ;
6358import {
6459 CloudComposeSupport ,
6560 resolveCloudWorkloadCmd ,
@@ -1220,7 +1215,8 @@ export class CloudRuntime implements MultiServiceRuntimeAdapter {
12201215 await this . ensureWorkspaceGit ( provisioned . runtime , logger , "Dockerfile source workspace" ) ;
12211216
12221217 const executor = this . workspaceExecutor ( provisioned . runtime ) ;
1223- const cloneUrl = injectGitToken ( config . repoUrl , config . gitToken ) ;
1218+ const gitInvocation = assembleGitClone ( { repoUrl : config . repoUrl , gitToken : config . gitToken } ) ;
1219+ const cloneUrl = gitInvocation . cloneUrl ;
12241220 const fetchCommand = [
12251221 "set -e" ,
12261222 `rm -rf ${ sq ( sourceDir ) } ` ,
@@ -1234,6 +1230,7 @@ export class CloudRuntime implements MultiServiceRuntimeAdapter {
12341230 // progress lines to stderr so they reach the build log stream.
12351231 `GIT_TERMINAL_PROMPT=0 GIT_ASKPASS=/bin/echo git -c credential.helper= fetch --progress --depth ${ config . commitSha ? "50" : "1" } origin ${ sq ( config . branch ) } ` ,
12361232 `git -c credential.helper= -c advice.detachedHead=false checkout -q ${ sq ( checkoutRef ) } ` ,
1233+ gitShellCommand ( gitInvocation , GIT_SUBMODULE_UPDATE_ARGS . join ( " " ) ) ,
12371234 'echo "Dockerfile source fetch ready."' ,
12381235 ] . join ( "\n" ) ;
12391236 const fetchResult = await executor . streamExec ( fetchCommand , logger . callback ) ;
@@ -1488,7 +1485,8 @@ export class CloudRuntime implements MultiServiceRuntimeAdapter {
14881485 throw new Error ( "Dockerfile build context escapes the repository source." ) ;
14891486 }
14901487
1491- const cloneUrl = injectGitToken ( config . repoUrl , config . gitToken ) ;
1488+ const gitInvocation = assembleGitClone ( { repoUrl : config . repoUrl , gitToken : config . gitToken } ) ;
1489+ const cloneUrl = gitInvocation . cloneUrl ;
14921490 const depthArgs = config . commitSha ? "--depth 50 " : "--depth 1 " ;
14931491 const cloneTarget = contextRelativePath ? repoRoot : contextRoot ;
14941492 const contextSource = contextRelativePath
@@ -1527,18 +1525,26 @@ export class CloudRuntime implements MultiServiceRuntimeAdapter {
15271525 // See fetchCommand above for env-var rationale; --progress keeps
15281526 // the clone visible in the streamed log even though stdout/stderr
15291527 // are pipes, not a tty.
1530- `GIT_TERMINAL_PROMPT=0 GIT_ASKPASS=/bin/echo git -c credential.helper= clone --progress ${ depthArgs } --branch ${ sq ( config . branch ) } ${ sq ( cloneUrl ) } ${ sq ( cloneTarget ) } ` ,
1528+ gitShellCommand (
1529+ gitInvocation ,
1530+ `clone --progress ${ depthArgs } --branch ${ sq ( config . branch ) } ${ sq ( cloneUrl ) } ${ sq ( cloneTarget ) } ` ,
1531+ ) ,
1532+ ] . join ( "\n" ) ;
1533+ const checkoutCommand = [
1534+ "set -e" ,
1535+ `cd ${ sq ( cloneTarget ) } ` ,
1536+ ...( config . commitSha
1537+ ? [ `git -c credential.helper= -c advice.detachedHead=false checkout ${ sq ( config . commitSha ) } ` ]
1538+ : [ ] ) ,
1539+ gitShellCommand ( gitInvocation , GIT_SUBMODULE_UPDATE_ARGS . join ( " " ) ) ,
15311540 ] . join ( "\n" ) ;
1532- const checkoutCommand = config . commitSha
1533- ? `cd ${ sq ( cloneTarget ) } && git -c credential.helper= -c advice.detachedHead=false checkout ${ sq ( config . commitSha ) } `
1534- : "" ;
15351541 // No name-based pruning: a fresh clone already contains only git-tracked
15361542 // files (gitignored output was never committed), so pruning by name here
15371543 // would only risk deleting tracked source (e.g. a top-level `data/` dir).
15381544 // A tracked `.dockerignore` still applies at `docker build` on the worker.
15391545 const prepareCommand = [
15401546 "set -e" ,
1541- `rm -rf ${ sq ( joinWorkspacePath ( cloneTarget , " .git" ) ) } ` ,
1547+ `find ${ sq ( cloneTarget ) } -name .git -prune -exec rm -rf {} + ` ,
15421548 ...prepareContextCommands ,
15431549 'echo "Dockerfile context prepared."' ,
15441550 ] . join ( "\n" ) ;
@@ -1549,9 +1555,7 @@ export class CloudRuntime implements MultiServiceRuntimeAdapter {
15491555 await this . ensureWorkspaceGit ( targetRuntime , logger , "Dockerfile build workspace" ) ;
15501556 logger . log ( `Cloning Dockerfile context in build workspace (branch: ${ config . branch } )...\n` ) ;
15511557 await this . execAndStream ( targetRuntime , [ "sh" , "-c" , cloneCommand ] , logger . callback , 900 ) ;
1552- if ( checkoutCommand ) {
1553- await this . execAndStream ( targetRuntime , [ "sh" , "-c" , checkoutCommand ] , logger . callback , 300 ) ;
1554- }
1558+ await this . execAndStream ( targetRuntime , [ "sh" , "-c" , checkoutCommand ] , logger . callback , 900 ) ;
15551559 await this . execAndStream ( targetRuntime , [ "sh" , "-c" , prepareCommand ] , logger . callback , 300 ) ;
15561560 logger . log ( "Dockerfile context ready.\n" ) ;
15571561 }
0 commit comments