From 5adf77fbfcbd3fe8aa62365fd9f33f673e034eaf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 31 Jan 2024 14:52:28 +0100 Subject: [PATCH] If no `sparse-checkout` parameter is specified, disable it This should allow users to reuse existing folders when running `actions/checkout` where a previous run asked for a sparse checkout but the current run does not ask for a sparse checkout. This fixes https://github.com/actions/checkout/issues/1475 Signed-off-by: Johannes Schindelin --- __test__/git-auth-helper.test.ts | 1 + __test__/git-directory-helper.test.ts | 1 + src/git-command-manager.ts | 5 +++++ src/git-source-provider.ts | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 411faed..a75b79d 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -727,6 +727,7 @@ async function setup(testName: string): Promise { branchDelete: jest.fn(), branchExists: jest.fn(), branchList: jest.fn(), + disableSparseCheckout: jest.fn(), sparseCheckout: jest.fn(), sparseCheckoutNonConeMode: jest.fn(), checkout: jest.fn(), diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index 362133f..79e0538 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -462,6 +462,7 @@ async function setup(testName: string): Promise { branchList: jest.fn(async () => { return [] }), + disableSparseCheckout: jest.fn(), sparseCheckout: jest.fn(), sparseCheckoutNonConeMode: jest.fn(), checkout: jest.fn(), diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 7752cfa..0f3fd25 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -17,6 +17,7 @@ export interface IGitCommandManager { branchDelete(remote: boolean, branch: string): Promise branchExists(remote: boolean, pattern: string): Promise branchList(remote: boolean): Promise + disableSparseCheckout(): Promise sparseCheckout(sparseCheckout: string[]): Promise sparseCheckoutNonConeMode(sparseCheckout: string[]): Promise checkout(ref: string, startPoint: string): Promise @@ -171,6 +172,10 @@ class GitCommandManager { return result } + async disableSparseCheckout(): Promise { + await this.execGit(['sparse-checkout', 'disable']) + } + async sparseCheckout(sparseCheckout: string[]): Promise { await this.execGit(['sparse-checkout', 'set', ...sparseCheckout]) } diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 5c98e9f..0589722 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -208,7 +208,9 @@ export async function getSource(settings: IGitSourceSettings): Promise { } // Sparse checkout - if (settings.sparseCheckout) { + if (!settings.sparseCheckout) { + await git.disableSparseCheckout() + } else { core.startGroup('Setting up sparse checkout') if (settings.sparseCheckoutConeMode) { await git.sparseCheckout(settings.sparseCheckout)