From 1ca247805d004995821026e2ff27e325d733d486 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 18:22:36 +0000 Subject: [PATCH 1/2] fix(git): resolve submodule confused with git worktree Both Git submodules and worktrees utilize a `.git` file with a `gitdir:` entry, but only worktrees point to the main repository's `.git/worktrees/...` administrative directory. Refines the `isWorktree` function to specifically verify that the `gitdir:` path references a `worktrees` administrative directory. Adds associated unit tests. Co-authored-by: athal7 <467872+athal7@users.noreply.github.com> --- plugin/core/git.js | 4 ++-- test/unit/git-worktree.test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin/core/git.js b/plugin/core/git.js index 7918bed..8301e8e 100644 --- a/plugin/core/git.js +++ b/plugin/core/git.js @@ -230,9 +230,9 @@ export async function isWorktree(dir) { return false } - // Verify it contains a gitdir reference + // Verify it contains a gitdir reference pointing to a worktree administrative directory const content = await readFile(gitPath, 'utf-8') - return content.startsWith('gitdir:') + return content.startsWith('gitdir:') && /[/\\]worktrees[/\\][^/\\]+\s*$/.test(content) } catch { return false } diff --git a/test/unit/git-worktree.test.js b/test/unit/git-worktree.test.js index 3501a5c..be1c6e5 100644 --- a/test/unit/git-worktree.test.js +++ b/test/unit/git-worktree.test.js @@ -63,6 +63,25 @@ describe('isWorktree', () => { const result = await isWorktree('/nonexistent/path') assert.strictEqual(result, false) }) + + test('returns false for a submodule directory', async () => { + const subRepo = join(testDir, 'sub-repo') + const submodulePath = join(mainRepo, 'sub') + + mkdirSync(subRepo, { recursive: true }) + execSync('git init -b main', { cwd: subRepo }) + writeFileSync(join(subRepo, 'sub.txt'), 'sub') + execSync('git add .', { cwd: subRepo }) + execSync('git commit -m "sub commit"', { cwd: subRepo }) + + // Add submodule to main repo + execSync('git config --global protocol.file.allow always', { cwd: mainRepo }) + execSync(`git submodule add ${subRepo} sub`, { cwd: mainRepo }) + execSync('git commit -m "add submodule"', { cwd: mainRepo }) + + const result = await isWorktree(submodulePath) + assert.strictEqual(result, false) + }) }) describe('getWorktreeMainRepo', () => { From 0898920fd746b6f05dd00dbbd21669f9143a7f26 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 16:14:16 +0000 Subject: [PATCH 2/2] fix(git): distinguish git submodules from worktrees Both submodules and worktrees use a `.git` file with `gitdir:`. However, worktrees point to the main repository's `.git/worktrees/...` administrative directory. We refine `isWorktree` to ensure the gitdir references a `worktrees` administrative directory path segment. Includes corresponding unit tests. Co-authored-by: athal7 <467872+athal7@users.noreply.github.com>