opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(opencode): resolve git worktree .git files

Open rygwdn opened this issue 2 days ago • 3 comments

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

rygwdn avatar Jan 09 '26 19:01 rygwdn

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[bot] avatar Jan 09 '26 19:01 github-actions[bot]

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 #5647 - "fix: desktop app worktree collision - use separate ID per worktree"

    • https://github.com/anomalyco/opencode/pull/5647
    • Related: Also addresses worktree-specific issues
  2. PR #4817 - "fix: file changes visibility in worktree subdirs"

    • https://github.com/anomalyco/opencode/pull/4817
    • Related: Addresses worktree subdirectory handling
  3. 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.

github-actions[bot] avatar Jan 09 '26 19:01 github-actions[bot]

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.

github-actions[bot] avatar Jan 09 '26 19:01 github-actions[bot]