* fix: add git worktree support for local file:// scanning
Fixes#4553
The issue was introduced in v3.90.10 by PR #4502 which added local git
config sanitization. When scanning a local file:// repository, the code
copies the git index file to support staged changes scanning. However,
it assumed .git is always a directory.
In git worktrees, .git is a file containing a "gitdir: <path>" reference
to the actual git directory location. This caused the error:
"failed to read index file: open .../.git/index: not a directory"
This commit adds a resolveGitDir() helper function that:
- Checks if .git is a file or directory
- If it's a file (worktree), parses the gitdir reference
- Returns the resolved path to the actual git directory
The PrepareRepo() function now uses this helper to correctly locate
the index file in both regular repositories and worktrees.
* fix: handle errcheck lint warning in git test
Explicitly discard the error return value from os.RemoveAll in deferred
cleanup to satisfy the errcheck linter.
* fix(git): add object store alternates for staged change visibility
After copying the index file from the source repo (or worktree) into
the clone, staged blobs are unreachable because git clone with file://
only transfers objects reachable from references. Add the source
object store as a git alternates entry so staged objects can be read.
For git worktrees the actual object store lives in the main repo; the
worktree-specific git dir carries a commondir file pointing there, so
read that to locate the correct objects path.
Also tighten TestPrepareRepoWithWorktree to unconditionally assert that
git diff --cached succeeds and returns the expected staged content,
replacing the silent guard that allowed the assertion to be skipped
entirely when git failed. Add commit.gpgsign=false to setupTestRepo
so test commits work in environments with global GPG signing enabled.
---------
Co-authored-by: Shahzad Haider <[email protected]>