Skip to content

fix(paths): handle submodule gitdirs in worktree IDs#1359

Open
MuskanPaliwal wants to merge 4 commits into
entireio:mainfrom
MuskanPaliwal:fix-submodule-gitdir-worktree-id
Open

fix(paths): handle submodule gitdirs in worktree IDs#1359
MuskanPaliwal wants to merge 4 commits into
entireio:mainfrom
MuskanPaliwal:fix-submodule-gitdir-worktree-id

Conversation

@MuskanPaliwal
Copy link
Copy Markdown

@MuskanPaliwal MuskanPaliwal commented Jun 4, 2026

Fixes #640.

This fixes session initialization in repositories that contain Git submodules. GetWorktreeID previously treated any .git file whose gitdir: target did not contain .git/worktrees/<id> or .bare/worktrees/<id> as invalid. Ordinary submodules use a different valid Git layout: their checkout has a .git file pointing into the parent repository .git/modules/... directory. That caused Entire to fail before a session could initialize with unexpected gitdir format (no worktrees).

Core Changes:

  • Teach GetWorktreeID to recognize ordinary submodule gitdirs under .git/modules/<submodule> and return an empty worktree ID for them.
  • Keep linked-worktree behavior unchanged for regular worktrees under .git/worktrees/<id> and bare-worktree layouts under .bare/worktrees/<id>.
  • Add explicit parsing for submodule-owned linked worktrees, where the gitdir is shaped like .git/modules/<submodule>/worktrees/<id>.
  • Avoid misattributing a parent repository worktree ID to a submodule. A gitdir like .git/worktrees/<parent-worktree>/modules/<submodule> means the parent repo is a linked worktree, but the submodule itself is still an ordinary submodule checkout, so the returned submodule worktree ID should be empty.
  • Split the gitdir parsing into parseWorktreeID so the shape-specific logic is isolated and covered by focused tests.
  • Add regression coverage for relative submodule gitdirs, absolute submodule gitdirs, nested submodules, submodules inside linked superproject worktrees, and linked worktrees of submodules.

API Notes:

  • No public CLI command or flag changes.
  • No user-facing output changes except avoiding the erroneous session-initialization failure for valid submodule checkouts.
  • The GetWorktreeID contract remains: return an empty string for the main checkout namespace, return a non-empty ID for a real linked worktree namespace, and return an error for unrecognized .git file formats.

Compatibility / Release Notes:

  • Breaking changes: None.
  • Version impact: None.
  • Rollout notes: Existing repositories need no migration. The change only broadens accepted Git metadata layouts for session initialization.
  • E2E tests were not run; this PR is covered by focused paths package regression tests and a manual local submodule smoke check.

Validation:

  • GOCACHE=/private/tmp/entire-go-cache go test ./cmd/entire/cli/paths -run ^TestGetWorktreeID$ -count=1 passed.
  • git diff --check upstream/main...HEAD passed.
  • Manual local submodule smoke check confirmed Git writes gitdir: ../../.git/modules/deps/lib for a real submodule checkout, matching the issue layout.
Screenshot 2026-06-04 at 12 58 31 PM

@MuskanPaliwal
Copy link
Copy Markdown
Author

Hi @blackgirlbytes , can I get a review on this PR ?

@MuskanPaliwal MuskanPaliwal marked this pull request as ready for review June 4, 2026 08:00
@MuskanPaliwal MuskanPaliwal requested a review from a team as a code owner June 4, 2026 08:00
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Repository with submodules fails to initialize session (unexpected gitdir format)

1 participant