Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/server/lib/nativeBuild/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
20 changes: 12 additions & 8 deletions src/server/lib/nativeBuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

Expand All @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down