Skip to content

feat(config): auto-detect jj checkouts#264

Merged
benvinegar merged 3 commits into
mainfrom
feat/auto-detect-jj-vcs
May 9, 2026
Merged

feat(config): auto-detect jj checkouts#264
benvinegar merged 3 commits into
mainfrom
feat/auto-detect-jj-vcs

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • Auto-detect .jj checkouts as Jujutsu-backed reviews by default
  • Prefer jj mode for colocated jj/git workspaces unless explicit config overrides it
  • Add config-resolution coverage for jj-only, colocated jj/git, git-only, and override cases

Testing

  • bun test src/core/config.test.ts
  • bun run typecheck
  • bun run format:check

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

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 9, 2026

Greptile Summary

This PR wires up automatic Jujutsu-checkout detection into resolveConfiguredCliInput. A new detectRepoVcsMode helper checks for a .jj directory at the repo root and uses it as the initial vcs default, with global config → repo config → CLI flags still able to override it in the expected priority order.

  • src/core/config.ts: detectRepoVcsMode replaces the hardcoded "git" baseline; for colocated jj/git workspaces .jj is preferred, consistent with the existing findRepoRoot heuristic that already recognises both markers.
  • src/core/config.test.ts: Two new tests cover jj-only, colocated, git-only, and repo-config-override paths; the "no repo root" path is tested only indirectly.
  • CHANGELOG.md: Entry added to the unreleased ### Changed section.

Confidence Score: 4/5

Safe to merge — the auto-detection logic is straightforward and the merge order keeps all existing config overrides intact.

The change is small and well-contained. detectRepoVcsMode delegates to the same fs.existsSync pattern already used throughout the file, and the merge-order guarantees that global, repo, and CLI overrides all still win. The only gap is a missing explicit test for the outside-any-repo path, which is currently covered only indirectly.

No files require special attention; config.test.ts could add an explicit no-repo-root assertion but is otherwise solid.

Important Files Changed

Filename Overview
src/core/config.ts Adds detectRepoVcsMode helper that inspects the repo root for a .jj directory and uses it as the initial vcs default; merge order (auto-detect → global config → repo config → CLI flags) is correct.
src/core/config.test.ts Two new tests cover jj-only, colocated jj/git, git-only, and repo-config-override cases; the "no repo root" path (cwd outside any checkout) is exercised only indirectly through the pre-existing "defaults to git VCS mode" test rather than explicitly in the new suite.
CHANGELOG.md Entry correctly placed in the unreleased ### Changed block; wording accurately describes the new auto-detection behavior.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/core/config.test.ts:191-238
**Missing "no repo root" auto-detection case**

The new auto-detection tests cover jj-only, colocated, git-only, and config-override scenarios, but not the case where `cwd` is outside any checkout entirely (`findRepoRoot` returns `undefined`). In that case `detectRepoVcsMode(undefined)` falls through to `"git"`, which is the desired behaviour. The existing pre-PR test exercises this path only incidentally (its `cwd` is a plain temp dir), so a targeted assertion here — e.g., `createTempDir` with no `.git`/`.jj` and asserting `vcs === "git"` — would make the intended no-repo default explicit and guard against future regressions in that branch.

Reviews (1): Last reviewed commit: "feat(config): auto-detect jj checkouts" | Re-trigger Greptile

Comment thread src/core/config.test.ts
Comment on lines +191 to +238
test("auto-detects jj checkouts before falling back to git mode", () => {
const home = createTempDir("hunk-config-home-");
const jjRepo = createTempDir("hunk-config-jj-repo-");
const colocatedRepo = createTempDir("hunk-config-colocated-repo-");
const gitRepo = createTempDir("hunk-config-git-repo-");

createJjRepo(jjRepo);
createRepo(colocatedRepo);
createJjRepo(colocatedRepo);
createRepo(gitRepo);

const input = {
kind: "vcs",
staged: false,
options: {},
} satisfies CliInput;

expect(
resolveConfiguredCliInput(input, { cwd: jjRepo, env: { HOME: home } }).input.options.vcs,
).toBe("jj");
expect(
resolveConfiguredCliInput(input, { cwd: colocatedRepo, env: { HOME: home } }).input.options
.vcs,
).toBe("jj");
expect(
resolveConfiguredCliInput(input, { cwd: gitRepo, env: { HOME: home } }).input.options.vcs,
).toBe("git");
});

test("explicit config overrides auto-detected jj mode", () => {
const home = createTempDir("hunk-config-home-");
const repo = createTempDir("hunk-config-jj-repo-");
createJjRepo(repo);

mkdirSync(join(repo, ".hunk"), { recursive: true });
writeFileSync(join(repo, ".hunk", "config.toml"), 'vcs = "git"\n');

const resolved = resolveConfiguredCliInput(
{
kind: "vcs",
staged: false,
options: {},
},
{ cwd: repo, env: { HOME: home } },
);

expect(resolved.input.options.vcs).toBe("git");
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing "no repo root" auto-detection case

The new auto-detection tests cover jj-only, colocated, git-only, and config-override scenarios, but not the case where cwd is outside any checkout entirely (findRepoRoot returns undefined). In that case detectRepoVcsMode(undefined) falls through to "git", which is the desired behaviour. The existing pre-PR test exercises this path only incidentally (its cwd is a plain temp dir), so a targeted assertion here — e.g., createTempDir with no .git/.jj and asserting vcs === "git" — would make the intended no-repo default explicit and guard against future regressions in that branch.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/core/config.test.ts
Line: 191-238

Comment:
**Missing "no repo root" auto-detection case**

The new auto-detection tests cover jj-only, colocated, git-only, and config-override scenarios, but not the case where `cwd` is outside any checkout entirely (`findRepoRoot` returns `undefined`). In that case `detectRepoVcsMode(undefined)` falls through to `"git"`, which is the desired behaviour. The existing pre-PR test exercises this path only incidentally (its `cwd` is a plain temp dir), so a targeted assertion here — e.g., `createTempDir` with no `.git`/`.jj` and asserting `vcs === "git"` — would make the intended no-repo default explicit and guard against future regressions in that branch.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explicit no-repo assertion to the auto-detection coverage. The test now checks jj-only, colocated jj/git, git-only, and plain-directory fallback cases.

Responded by Pi using OpenAI GPT-5.

This comment was generated by Pi using OpenAI GPT-5

@benvinegar benvinegar force-pushed the feat/auto-detect-jj-vcs branch from 802b499 to 1b63d03 Compare May 9, 2026 22:15
@benvinegar benvinegar force-pushed the feat/auto-detect-jj-vcs branch from 1b63d03 to f75addd Compare May 9, 2026 22:18
@benvinegar benvinegar merged commit 83ef596 into main May 9, 2026
3 checks passed
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.

1 participant