fix(opencode): resolve git worktree .git files
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
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:orfeat(scope):new featurefix:orfix(scope):bug fixdocs:ordocs(scope):documentation changeschore:orchore(scope):maintenance tasksrefactor:orrefactor(scope):code refactoringtest:ortest(scope):adding or updating tests
Where scope is the package name (e.g., app, desktop, opencode).
See CONTRIBUTING.md for details.
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)
-
PR #5647 - "fix: desktop app worktree collision - use separate ID per worktree"
- https://github.com/anomalyco/opencode/pull/5647
- Related: Also addresses worktree-specific issues
-
PR #4817 - "fix: file changes visibility in worktree subdirs"
- https://github.com/anomalyco/opencode/pull/4817
- Related: Addresses worktree subdirectory handling
-
PR #2862 - "Fix relative paths for getGitFiles"
- https://github.com/anomalyco/opencode/pull/2862
- Related: Deals with relative path resolution in git operations
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.
Thanks for your contribution!
This PR doesn't have a linked issue. All PRs must reference an existing issue.
Please:
- Open an issue describing the bug/feature (if one doesn't exist)
- Add
Fixes #<number>orCloses #<number>to this PR description
See CONTRIBUTING.md for details.