Skip to content

fix(opencode): resolve git worktree .git files#7517

Open
rygwdn wants to merge 1 commit intoanomalyco:devfrom
rygwdn:perf/worktree-gitfile
Open

fix(opencode): resolve git worktree .git files#7517
rygwdn wants to merge 1 commit intoanomalyco:devfrom
rygwdn:perf/worktree-gitfile

Conversation

@rygwdn
Copy link

@rygwdn rygwdn commented Jan 9, 2026

What does this PR do?

  • Read .git files and follow gitdir: references to actual git directory
  • Handles both absolute and relative paths
  • Falls back gracefully when target doesn't exist

Why?

Git worktrees create a .git file (not directory) containing a path to the actual git directory. Without following this reference, the code fails to store the cached ID, which slows down subsequent startups.

How did you verify your code works?

  • Added test for absolute gitdir path resolution
  • Added test for relative gitdir path resolution
  • Added test for non-existent target fallback
  • Tested opening in a worktree, a normal git checkout, and outside of git

## Summary
- Read .git files and follow `gitdir:` references to actual git directory
- Handles both absolute and relative paths
- Falls back gracefully when target doesn't exist

## Why
Git worktrees create a `.git` file (not directory) containing a path to
the actual git directory. Without following this reference, project
resolution could fail or be slower in worktree scenarios.

## Testing
- Added test for absolute gitdir path resolution
- Added test for relative gitdir path resolution
- Added test for non-existent target fallback
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Hey! Your PR title perf: resolve git worktree .git files doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several potentially related PRs that might be addressing similar git-related issues:

Related PRs (Not Direct Duplicates)

  1. PR fix: desktop app worktree collision - use separate ID per worktree #5647 - "fix: desktop app worktree collision - use separate ID per worktree"

  2. PR fix: file changes visibility in worktree subdirs (#4752) #4817 - "fix: file changes visibility in worktree subdirs"

  3. PR Fix relative paths for getGitFiles #2862 - "Fix relative paths for getGitFiles"

These PRs touch on worktree and git path handling, but none appear to be direct duplicates of PR #7517. Your PR (#7517) specifically addresses the performance issue of resolving .git files that reference git directories via gitdir: paths, which is distinct from the other issues handled in these related PRs.

@rygwdn rygwdn changed the title perf: resolve git worktree .git files fix(opencode): resolve git worktree .git files Jan 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments