Skip to content

fix: collect git metadata in linked worktrees - #334

Merged
dividedmind merged 1 commit into
masterfrom
fix/git-worktree-metadata
Oct 27, 2026
Merged

dividedmind merged 1 commit into
masterfrom
fix/git-worktree-metadata

Conversation

@dividedmind

Copy link
Copy Markdown
Contributor

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

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
@dividedmind
dividedmind requested review from kgilpin and a balanced review from Copilot October 13, 2026 14:51
@dividedmind dividedmind self-assigned this Oct 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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.

@dividedmind
dividedmind merged commit 568ae9c into master Oct 27, 2026
7 checks passed
@dividedmind
dividedmind deleted the fix/git-worktree-metadata branch October 27, 2026 12:23
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.

Git metadata dropped in a git worktree (.git file with gitdir: pointer not followed)

2 participants