From 10eecaf14b72c4cc7d68b84d8b7b632247e3f517 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 16 Jul 2024 18:55:57 -0600 Subject: [PATCH] resolves #21 ensure new worktree is created in clean state by clearing any previous git index cache --- CHANGELOG.adoc | 6 ++++++ packages/collector-extension/lib/index.js | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1edd5b8..d192384 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -4,6 +4,12 @@ This is a summary of all notable changes to the Antora Collector Extension by release. For a detailed view of what's changed, refer to the {url-repo}/commits[commit history] of this project. +== Unreleased + +=== Fixed + +* ensure new worktree is created in clean state by clearing any previous git index cache (#21) + == 1.0.0-alpha.5 (2024-07-16) === Added diff --git a/packages/collector-extension/lib/index.js b/packages/collector-extension/lib/index.js index 48877ae..b226e5f 100644 --- a/packages/collector-extension/lib/index.js +++ b/packages/collector-extension/lib/index.js @@ -161,7 +161,7 @@ module.exports.register = function ({ config: { keepWorktrees = false } }) { * prepare the worktree and later restored before the function returns. */ async function prepareWorktree (repo) { - const { dir, gitdir, ref, remote = 'origin', bare } = repo + const { dir, gitdir, ref, remote = 'origin', bare, cache } = repo delete repo.remote const currentIndexPath = ospath.join(gitdir, 'index') const currentIndexPathBak = currentIndexPath + '~' @@ -178,6 +178,7 @@ async function prepareWorktree (repo) { await fsp.unlink(currentIndexPath).catch(invariably.void) // index file not needed in this case await fsp.rm(dir, { recursive: true, force: true }) await fsp.mkdir(worktreeGitdir, { recursive: true }) + Reflect.ownKeys(cache).forEach((it) => it.toString() === 'Symbol(PackfileCache)' || delete cache[it]) } let head if (ref.startsWith('refs/heads/')) { -- GitLab