diff --git a/src/server/lib/nativeBuild/__tests__/utils.test.ts b/src/server/lib/nativeBuild/__tests__/utils.test.ts index 7a6a99b1..293c2ccd 100644 --- a/src/server/lib/nativeBuild/__tests__/utils.test.ts +++ b/src/server/lib/nativeBuild/__tests__/utils.test.ts @@ -24,9 +24,9 @@ describe('nativeBuild/utils', () => { expect(container.name).toBe('git-clone'); expect(container.image).toBe('alpine/git:latest'); expect(container.command).toEqual(['sh', '-c']); - expect(container.args[0]).toContain('git clone'); + expect(container.args[0]).toContain('git fetch --depth 1 --progress origin abc123def456'); expect(container.args[0]).toContain('owner/repo'); - expect(container.args[0]).toContain('abc123def456'); + expect(container.args[0]).toContain('git checkout FETCH_HEAD'); expect(container.env).toEqual([ { name: 'GIT_USERNAME', value: 'x-access-token' }, diff --git a/src/server/lib/nativeBuild/utils.ts b/src/server/lib/nativeBuild/utils.ts index f94c6067..42d5b785 100644 --- a/src/server/lib/nativeBuild/utils.ts +++ b/src/server/lib/nativeBuild/utils.ts @@ -222,8 +222,10 @@ export const GIT_USERNAME = 'x-access-token'; export const MANIFEST_PATH = '/tmp/manifests'; export function createCloneScript(repo: string, branch: string, sha?: string): string { - const cloneCmd = `git clone -b ${branch} https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace`; - const checkoutCmd = sha ? ` && cd /workspace && git checkout ${sha}` : ''; + const cloneCmd = `git clone --depth 1 --single-branch --progress -b ${branch} https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace`; + const checkoutCmd = sha + ? ` && cd /workspace && git fetch --depth 1 --progress origin ${sha} && git checkout ${sha}` + : ''; return `${cloneCmd}${checkoutCmd}`; } @@ -234,9 +236,10 @@ export function createGitCloneContainer(repo: string, revision: string, gitUsern command: ['sh', '-c'], args: [ `git config --global --add safe.directory /workspace && \ - git clone https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace && \ - cd /workspace && \ - git checkout ${revision}`, + git init /workspace && cd /workspace && \ + git remote add origin https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git && \ + git fetch --depth 1 --progress origin ${revision} && \ + git checkout FETCH_HEAD`, ], env: [ { @@ -270,9 +273,10 @@ export function createRepoSpecificGitCloneContainer( command: ['sh', '-c'], args: [ `git config --global --add safe.directory ${targetDir} && \ - git clone https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git ${targetDir} && \ - cd ${targetDir} && \ - git checkout ${revision}`, + git init ${targetDir} && cd ${targetDir} && \ + git remote add origin https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git && \ + git fetch --depth 1 --progress origin ${revision} && \ + git checkout FETCH_HEAD`, ], env: [ {