From cc051ea35cb7ae819bd97311ce83233e3b6fc4ff Mon Sep 17 00:00:00 2001 From: rjhallsted Date: Thu, 30 Jul 2026 16:16:29 -0600 Subject: [PATCH] shallow-clone the target branch only --- src/git.ts | 14 -------------- src/write.ts | 13 +++++++++++-- test/write.spec.ts | 30 +++++++++++++++++++----------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/git.ts b/src/git.ts index 1a228ac6d..63190ffbd 100644 --- a/src/git.ts +++ b/src/git.ts @@ -152,17 +152,3 @@ export async function clone( return cmd(additionalGitOptions, ...args); } -export async function checkout( - ghRef: string, - additionalGitOptions: string[] = [], - ...options: string[] -): Promise { - core.debug(`Executing 'git checkout' to ref '${ghRef}' with token and options '${options.join(' ')}'`); - - let args = ['checkout', ghRef]; - if (options.length > 0) { - args = args.concat(options); - } - - return cmd(additionalGitOptions, ...args); -} diff --git a/src/write.ts b/src/write.ts index 4e9ebad6c..ac7283e37 100644 --- a/src/write.ts +++ b/src/write.ts @@ -367,12 +367,21 @@ async function writeBenchmarkToGitHubPagesWithRetry( if (githubToken && !skipFetchGhPages && ghRepository) { benchmarkBaseDir = './benchmark-data-repository'; - await git.clone(githubToken, ghRepository, benchmarkBaseDir); + await git.clone( + githubToken, + ghRepository, + benchmarkBaseDir, + [], + '--branch', + ghPagesBranch, + '--single-branch', + '--depth', + '1', + ); rollbackActions.push(async () => { await io.rmRF(benchmarkBaseDir); }); extraGitArguments = [`--work-tree=${benchmarkBaseDir}`, `--git-dir=${benchmarkBaseDir}/.git`]; - await git.checkout(ghPagesBranch, extraGitArguments); } else if (!skipFetchGhPages && (!isPrivateRepo || githubToken)) { await git.pull(githubToken, ghPagesBranch); } else if (isPrivateRepo && !skipFetchGhPages) { diff --git a/test/write.spec.ts b/test/write.spec.ts index 1cf7ce729..f7be69acd 100644 --- a/test/write.spec.ts +++ b/test/write.spec.ts @@ -21,7 +21,7 @@ const ok: (x: any, msg?: string) => asserts x = (x, msg) => { } }; -type GitFunc = 'cmd' | 'push' | 'pull' | 'fetch' | 'clone' | 'checkout'; +type GitFunc = 'cmd' | 'push' | 'pull' | 'fetch' | 'clone'; class GitSpy { history: [GitFunc, unknown[]][]; pushFailure: null | string; @@ -110,10 +110,6 @@ jest.mock('../src/git', () => ({ gitSpy.call('clone', args); return ''; }, - async checkout(...args: unknown[]) { - gitSpy.call('checkout', args); - return ''; - }, })); describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBenchmark() - %s', function (serverUrl) { @@ -1088,12 +1084,18 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe }, gitServerUrl: serverUrl, gitHistory: [ - ['clone', ['dummy token', 'https://github.com/user/other-repo', './benchmark-data-repository']], [ - 'checkout', + 'clone', [ + 'dummy token', + 'https://github.com/user/other-repo', + './benchmark-data-repository', + [], + '--branch', 'gh-pages', - ['--work-tree=./benchmark-data-repository', '--git-dir=./benchmark-data-repository/.git'], + '--single-branch', + '--depth', + '1', ], ], [ @@ -1147,12 +1149,18 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe }, gitServerUrl: serverUrl, gitHistory: [ - ['clone', ['dummy token', 'https://github.com/user/other-repo', './benchmark-data-repository']], [ - 'checkout', + 'clone', [ + 'dummy token', + 'https://github.com/user/other-repo', + './benchmark-data-repository', + [], + '--branch', 'gh-pages', - ['--work-tree=./benchmark-data-repository', '--git-dir=./benchmark-data-repository/.git'], + '--single-branch', + '--depth', + '1', ], ], [