Repository navigation
Conversation
…ctory Opening a subdirectory of a git repository made worktree creation stat a missing .git path. Git now supplies the shared git directory.
| // gitdir points to e.g. /repo/.git/worktrees/foo — go up two levels to /repo/.git | ||
| return path.resolve(path.dirname(gitPath), match[1].trim(), "..", "..") | ||
| export async function resolveGitDir(root: string, binary = "git"): Promise<string> { | ||
| const { stdout } = await exec(binary, ["rev-parse", "--git-common-dir"], { cwd: root }) |
There was a problem hiding this comment.
WARNING: This spawns git with plain exec, which does no PATH recovery and has no timeout.
ensureGitAvailable()/checkLfsAvailable() and the other git calls in WorktreeManager go through execWithShellEnv (src/agent-manager/shell-env.ts) because a VS Code window launched from Finder/Dock inherits a minimal PATH that can miss Homebrew/nvm git. The create path is currently shielded only because ensureGitAvailable() runs before preflight(), but resolveGitDir is also reached from migrateAgentManagerData -> fixGitWorktreeRefs before any shell-env resolution, where a missing git makes the ref repair silently no-op (resolveGitDir(root).catch(() => undefined)). fixGitWorktreeRefs also still calls resolveGitDir(root) without binary, so a custom-configured git binary is ignored on that path.
Suggestion: route this through execWithShellEnv with a bounded timeout (e.g. BUDGET.probe) and thread this.binary into the fixGitWorktreeRefs caller. Note the current exec import is still the correct Windows-safe wrapper, just not PATH-resilient.
There was a problem hiding this comment.
Fixed in cd0efaa. resolveGitDir now runs through execWithShellEnv with the BUDGET.probe timeout, like the other git calls in WorktreeManager. The migration path keeps the default git binary, the same as the other callers that have no configured binary.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The previous warning about Files Reviewed (1 file)
Previous Review Summary (commit ec4bb85)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit ec4bb85)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (4 files)
Reviewed by deepseek-flash-latest · Input: 45.3K · Output: 5.9K · Cached: 354.4K Review guidance: REVIEW.md from base branch |
Issue
Fixes #15448
Context
Agent Manager worktree creation failed when the VS Code window was opened on a subdirectory of a git repository. The LFS check called stat on
<folder>/.gitand threwENOENT. Pull request #14274 already asks git for the exclude file in this layout. The LFS check and the gitdir repair helper still used the direct stat.I now resolve the shared git directory with
git rev-parse --git-common-dir, from the opened folder. The project root is still that folder.Changed files:
packages/kilo-vscode/src/agent-manager/constants.tspackages/kilo-vscode/src/agent-manager/WorktreeManager.tspackages/kilo-vscode/tests/unit/worktree-manager.test.ts.changeset/agent-manager-subdir-worktree.mdImplementation
resolveGitDirrunsgit rev-parse --git-common-dirwith the workspace as its cwd. The result can be relative, so it is resolved against that folder.repoUsesLfspasses the configured git binary.I used
--git-common-dirbecause Git LFS keeps its files in the shared git directory.--git-path lfsfollows the per-worktree git directory, so a linked worktree would miss.git/lfs.Screenshots / Video
N/A. No visual change.
How to Test
Manual/local verification
I ran
bun test tests/unit/worktree-manager.test.ts -t "creates a worktree from a subdirectory of the repository"frompackages/kilo-vscodebefore the fix. Result: 0 pass, 1 fail. The failure wasENOENTfromfs.statof<subfolder>/.git, inresolveGitDirviarepoUsesLfs.I ran the same command after the fix. Result: 1 pass.
I ran the full unit suite,
bun test tests/unit/: 6968 tests, 0 fail, 2 skip.bunx eslintonconstants.tsandWorktreeManager.tsexited 0.bun run check-typesandbun run check-types:webviewinpackages/kilo-vscodeboth exited 0.I also drove
resolveGitDirandWorktreeManageragainst temporary git repositories. A nested subdirectory resolved to the real.git.info/attributeswithfilter=lfswas detected from that subdirectory. A linked worktree and a subdirectory of that worktree both saw.git/lfsin the shared git directory, and worktree creation from the worktree subdirectory succeeded. A stale.kilocodegitdir path was rewritten when the manager root was a subdirectory. A separate git directory was resolved, and itslfsdirectory was detected.Reviewer test steps
packages/kilo-vscode, runbun test tests/unit/worktree-manager.test.ts -t "creates a worktree from a subdirectory of the repository".ENOENT, the worktree is under that subfolder's.kilo/worktreesdirectory, andgit statusin the repository does not list it.Blocked checks and substitute verification
None. The checks above completed.
Checklist
Get in Touch