Fix #150: Support git worktrees in JGit property source by gnodet · Pull Request #151 · maveniverse/nisse (original) (raw)
JGit 5.x does not natively support git worktrees. When .git is a file (containing a gitdir: pointer) rather than a directory, FileRepositoryBuilder fails with RepositoryNotFoundException.
This fix detects worktrees by checking for the commondir file in the resolved git directory, redirects to the common (shared) git directory for access to objects/refs/tags, and reads HEAD from the worktree-specific directory to resolve the correct branch.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
[](/apps/coderabbitai)
When resolveHead() returns null (empty repo with no commits), fall back to the default HEAD resolution which naturally throws NoHeadException, preserving the existing behavior for the 0-commits-0-tags integration test.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
[](/apps/coderabbitai)
- Set workTree to CWD in worktree mode so isClean() checks the correct working directory instead of the main repo
- Set indexFile to the worktree-specific index so JGit uses the correct staging area
- Eliminate redundant FileRepositoryBuilder in resolveHead() by detecting the worktree gitDir once in getProperties() and passing it directly
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
[](/apps/coderabbitai)
[](/apps/coderabbitai)
Fixed 1 file(s) based on 1 unresolved review comment.
Co-authored-by: CodeRabbit noreply@coderabbit.ai
[](/apps/coderabbitai)
gnodet marked this pull request as draft
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
gnodet marked this pull request as ready for review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})