Repository navigation
fix: collect git metadata in linked worktrees - #334
Merged
Merged
Conversation
JGit 5.13, the last release that supports Java 8, doesn't know anything about linked worktrees. Pointed at one, it finds a git directory that isn't named ".git" and has no config of its own, so it concludes that the repository is bare. The agent then dropped all git metadata and warned about an unsupported configuration on every recording. Detect a worktree's git directory by its commondir file, and point JGit at the main repository's git directory, which holds the config, refs, and objects that all the worktrees share, and at the worktree's checkout. HEAD still belongs to the worktree, so read it ourselves to get the branch and commit. While here, close the repository on the paths where open() gives up, and make close() actually close it. Git.close() is a no-op for a Git built with new Git(repo), so every recording leaked a FileRepository. Assisted-by: Claude:claude-opus-5
There was a problem hiding this comment.
🟢 Approval recommended
The implementation handles linked and detached worktrees with focused integration coverage and correct resource cleanup.
0 open findings
What changed in this PR
Adds linked Git worktree metadata support while fixing repository resource leaks.
Changes:
- Resolves worktree-specific HEAD, index, checkout, and common Git directory.
- Closes repositories on failure and shutdown paths.
- Adds Bats coverage for normal, linked, and detached worktrees.
| File | Description |
|---|---|
agent/src/main/java/com/appland/appmap/util/GitUtil.java |
Implements worktree detection and repository cleanup. |
agent/test/git/git.bats |
Tests Git metadata and source paths. |
agent/test/git/appmap.yml |
Configures the Git test fixture. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JGit 5.13, the last release that supports Java 8, doesn't know anything about linked worktrees. Pointed at one, it finds a git directory that isn't named ".git" and has no config of its own, so it concludes that the repository is bare. The agent then dropped all git metadata and warned about an unsupported configuration on every recording.
Detect a worktree's git directory by its commondir file, and point JGit at the main repository's git directory, which holds the config, refs, and objects that all the worktrees share, and at the worktree's checkout. HEAD still belongs to the worktree, so read it ourselves to get the branch and commit.
While here, close the repository on the paths where open() gives up, and make close() actually close it. Git.close() is a no-op for a Git built with new Git(repo), so every recording leaked a FileRepository.
Assisted-by: Claude:claude-opus-5
Fixes #331