Skip to content

Commit 10bb198

Browse files
authored
Add shallow clone (--depth Improve native build clone step (#123)
Add shallow clone (--depth 1), --single-branch, and --progress to native build git clone steps. Refactor container clone functions to use git init + git fetch --depth 1 for fetching specific revisions instead of full clone + checkout.
1 parent 8ef6df5 commit 10bb198

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/server/lib/nativeBuild/__tests__/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ describe('nativeBuild/utils', () => {
2424
expect(container.name).toBe('git-clone');
2525
expect(container.image).toBe('alpine/git:latest');
2626
expect(container.command).toEqual(['sh', '-c']);
27-
expect(container.args[0]).toContain('git clone');
27+
expect(container.args[0]).toContain('git fetch --depth 1 --progress origin abc123def456');
2828
expect(container.args[0]).toContain('owner/repo');
29-
expect(container.args[0]).toContain('abc123def456');
29+
expect(container.args[0]).toContain('git checkout FETCH_HEAD');
3030

3131
expect(container.env).toEqual([
3232
{ name: 'GIT_USERNAME', value: 'x-access-token' },

src/server/lib/nativeBuild/utils.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ export const GIT_USERNAME = 'x-access-token';
222222
export const MANIFEST_PATH = '/tmp/manifests';
223223

224224
export function createCloneScript(repo: string, branch: string, sha?: string): string {
225-
const cloneCmd = `git clone -b ${branch} https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace`;
226-
const checkoutCmd = sha ? ` && cd /workspace && git checkout ${sha}` : '';
225+
const cloneCmd = `git clone --depth 1 --single-branch --progress -b ${branch} https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace`;
226+
const checkoutCmd = sha
227+
? ` && cd /workspace && git fetch --depth 1 --progress origin ${sha} && git checkout ${sha}`
228+
: '';
227229
return `${cloneCmd}${checkoutCmd}`;
228230
}
229231

@@ -234,9 +236,10 @@ export function createGitCloneContainer(repo: string, revision: string, gitUsern
234236
command: ['sh', '-c'],
235237
args: [
236238
`git config --global --add safe.directory /workspace && \
237-
git clone https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git /workspace && \
238-
cd /workspace && \
239-
git checkout ${revision}`,
239+
git init /workspace && cd /workspace && \
240+
git remote add origin https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git && \
241+
git fetch --depth 1 --progress origin ${revision} && \
242+
git checkout FETCH_HEAD`,
240243
],
241244
env: [
242245
{
@@ -270,9 +273,10 @@ export function createRepoSpecificGitCloneContainer(
270273
command: ['sh', '-c'],
271274
args: [
272275
`git config --global --add safe.directory ${targetDir} && \
273-
git clone https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git ${targetDir} && \
274-
cd ${targetDir} && \
275-
git checkout ${revision}`,
276+
git init ${targetDir} && cd ${targetDir} && \
277+
git remote add origin https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/${repo}.git && \
278+
git fetch --depth 1 --progress origin ${revision} && \
279+
git checkout FETCH_HEAD`,
276280
],
277281
env: [
278282
{

0 commit comments

Comments
 (0)