Skip to content

fix(vcs): prefer nearest detected repository#342

Open
benvinegar wants to merge 1 commit into
mainfrom
fix/nested-git-parent-jj
Open

fix(vcs): prefer nearest detected repository#342
benvinegar wants to merge 1 commit into
mainfrom
fix/nested-git-parent-jj

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • Prefer the nearest detected VCS checkout when auto-selecting Git vs Jujutsu.
  • Keep adapter priority as the tie-breaker for colocated .jj + .git repositories.
  • Add regression coverage for a Git repository nested under a parent Jujutsu workspace.

Fixes #340.

Tests

  • bun test src/core/vcs/index.test.ts src/core/config.test.ts
  • bun run typecheck
  • bun test

This PR description was generated by Pi using OpenAI GPT-5

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR fixes VCS auto-detection so that when a Git repository is nested inside a parent Jujutsu workspace, the tool correctly selects the nearer Git adapter rather than defaulting to Jujutsu due to adapter priority order.

  • detectVcs now iterates all adapters, computes the path-depth distance from cwd to each detected repoRoot, and selects the nearest one — falling back to adapter order only when two roots are equidistant (e.g. colocated .jj + .git).
  • Two new regression tests are added: a unit test in vcs/index.test.ts verifying the nested-Git-under-Jujutsu scenario, and an integration test in config.test.ts confirming the config layer resolves to \"git\" in the same scenario.

Confidence Score: 5/5

Safe to merge — the change is a well-scoped fix with correct logic and good test coverage at both the unit and integration levels.

The distance calculation using relative(repoRoot, start) is sound: both adapters' detect functions always return a proper ancestor of start, so the relative path never contains .. segments and the length correctly measures depth. The strict < comparison naturally preserves adapter order as a tie-breaker for colocated repos. Existing behavior (only-jj, only-git, colocated) is unaffected. The new nested-git-under-jj regression test and the config integration test validate the fixed scenario end-to-end.

No files require special attention.

Important Files Changed

Filename Overview
src/core/vcs/index.ts Rewrites detectVcs to scan all adapters and pick the one whose repoRoot is nearest to cwd, using adapter order only as a tie-breaker for colocated repos.
src/core/vcs/index.test.ts Adds regression test: Git repo nested inside a parent Jujutsu workspace correctly resolves to git for both detectVcs and findVcsRepoRootCandidate.
src/core/config.test.ts Adds integration-level config test verifying that resolveConfiguredCliInput selects "git" when cwd is a Git repo nested inside a Jujutsu workspace.
CHANGELOG.md Adds a changelog entry in the Unreleased/Fixed section documenting the VCS auto-detection fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["detectVcs(cwd)"] --> B["resolve(cwd) → start"]
    B --> C["For each adapter in vcsAdapters\n(jjAdapter, gitAdapter)"]
    C --> D["adapter.detect(start)"]
    D -->|null| C
    D -->|detected| E["Compute distance:\nrelative(repoRoot, start)\n.split(/[\\\/]+/).filter(Boolean).length"]
    E --> F{"distance < bestDistance?"}
    F -->|yes| G["bestDetection = detected\nbestDistance = distance"]
    F -->|no| H["keep existing bestDetection"]
    G --> C
    H --> C
    C -->|all adapters exhausted| I["return bestDetection"]
Loading

Reviews (1): Last reviewed commit: "fix(vcs): prefer nearest detected reposi..." | Re-trigger Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uses parent jj even if current repo only uses git.

1 participant