Skip to content

Fix: Enable HEAD resolution in git worktrees#741

Open
meekrosoft wants to merge 2 commits intomainfrom
fix-worktree-head-resolution
Open

Fix: Enable HEAD resolution in git worktrees#741
meekrosoft wants to merge 2 commits intomainfrom
fix-worktree-head-resolution

Conversation

@meekrosoft
Copy link
Copy Markdown
Contributor

Summary

Enable EnableDotGitCommonDir option in gitview.New() to properly resolve HEAD references in git worktrees.

Changes

  • Modified gitView.New() to use git.PlainOpenWithOptions() with EnableDotGitCommonDir: true
  • Added comprehensive test TestNewGitViewFromWorktree() that validates:
    • Creating GitView from a worktree path succeeds
    • BranchName() returns correct branch in worktree context
    • GetCommitInfoFromCommitSHA("HEAD", ...) resolves correctly in worktree
  • Updated TODO.md marking all items in the worktree fix slice as complete

Impact

Users can now use gitview operations from git worktree paths without errors when resolving HEAD references.

meekrosoft and others added 2 commits March 27, 2026 11:54
Enable EnableDotGitCommonDir in go-git's PlainOpenWithOptions so that
ref resolution follows the commondir chain. Without this, HEAD in a
linked worktree points to a branch whose ref lives in the main repo's
.git/refs, and go-git fails with "reference not found".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 27, 2026

Claude finished @meekrosoft's task in 1m 27s —— View job


PR Review: Fix HEAD resolution in git worktrees

  • Run static analysis (build, vet, mod tidy)
  • Review changed files
  • Post review feedback

Static Analysis

All checks pass: go build, go vet, and go mod tidy report no issues.

Review

This is a clean, well-scoped fix. The change is minimal (swapping PlainOpenPlainOpenWithOptions with EnableDotGitCommonDir: true) and directly addresses the problem. The test is thorough — it validates New(), BranchName(), and GetCommitInfoFromCommitSHA("HEAD", ...) all work from a worktree context.

A few observations:

Code change — No concerns. EnableDotGitCommonDir: true is the correct go-git option for worktree support, and it's backward-compatible (regular repos work the same way).

Test quality — Good coverage of the three key operations. The test creates a real git worktree via exec.Command, which is the right approach for testing this behavior. Cleanup is handled by AfterTest() removing the entire tmpDir, which covers both the main repo and worktree directories.

TODO.md — Follows the repo's slice tracking convention correctly.

No issues found. This is a solid single-slice fix — small, focused, well-tested. LGTM. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant