From 43045ae669be728bd34ed56fcd1a230c0dc4d8e2 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:07:43 +0200 Subject: [PATCH] Disable `extensions.worktreeConfig` when disabling `sparse-checkout` (#1692) --- .github/workflows/test.yml | 6 +++--- __test__/verify-basic.sh | 14 ++++++++++++++ dist/index.js | 2 ++ src/git-command-manager.ts | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8c83acf4..cbd29917e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: - releases/* -# Note that when you see patterns like "ref: test-data/v2/basic" within this workflow, +# Note that when you see patterns like "ref: test-data/v2/basic" within this workflow, # these refer to "test-data" branches on this actions/checkout repo. # (For example, test-data/v2/basic -> https://github.com/actions/checkout/tree/test-data/v2/basic) @@ -37,7 +37,7 @@ jobs: steps: # Clone this repo - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4.1.1 # Basic checkout - name: Checkout basic @@ -257,7 +257,7 @@ jobs: path: basic - name: Verify basic run: __test__/verify-basic.sh --archive - + test-git-container: runs-on: ubuntu-latest container: bitnami/git:latest diff --git a/__test__/verify-basic.sh b/__test__/verify-basic.sh index 5aaa309b8..d084617f0 100755 --- a/__test__/verify-basic.sh +++ b/__test__/verify-basic.sh @@ -18,6 +18,20 @@ else exit 1 fi + # Verify that sparse-checkout is disabled. + SPARSE_CHECKOUT_ENABLED=$(git -C ./basic config --local --get-all core.sparseCheckout) + if [ "$SPARSE_CHECKOUT_ENABLED" != "" ]; then + echo "Expected sparse-checkout to be disabled (discovered: $SPARSE_CHECKOUT_ENABLED)" + exit 1 + fi + + # Verify git configuration shows worktreeConfig is effectively disabled + WORKTREE_CONFIG_ENABLED=$(git -C ./basic config --local --get-all extensions.worktreeConfig) + if [[ "$WORKTREE_CONFIG_ENABLED" != "" ]]; then + echo "Expected extensions.worktreeConfig (boolean) to be disabled in git config. This could be an artifact of sparse checkout functionality." + exit 1 + fi + # Verify auth token cd basic git fetch --no-tags --depth=1 origin +refs/heads/main:refs/remotes/origin/main diff --git a/dist/index.js b/dist/index.js index b21024745..5ff87e42a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -582,6 +582,8 @@ class GitCommandManager { disableSparseCheckout() { return __awaiter(this, void 0, void 0, function* () { yield this.execGit(['sparse-checkout', 'disable']); + // Disabling 'sparse-checkout` leaves behind an undesirable side-effect in config (even in a pristine environment). + yield this.tryConfigUnset('extensions.worktreeConfig', false); }); } sparseCheckout(sparseCheckout) { diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index fa50321f8..8e42a387f 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -178,6 +178,8 @@ class GitCommandManager { async disableSparseCheckout(): Promise { await this.execGit(['sparse-checkout', 'disable']) + // Disabling 'sparse-checkout` leaves behind an undesirable side-effect in config (even in a pristine environment). + await this.tryConfigUnset('extensions.worktreeConfig', false) } async sparseCheckout(sparseCheckout: string[]): Promise {