Skip to content

Feat/per project worktree location - #6427

Closed
MrSimmmons wants to merge 10 commits into
pingdotgg:mainfrom
MrSimmmons:feat/per-project-worktree-location
Closed

MrSimmmons wants to merge 10 commits into
pingdotgg:mainfrom
MrSimmmons:feat/per-project-worktree-location

Conversation

@MrSimmmons

@MrSimmmons MrSimmmons commented Aug 13, 2026 •

Copy link
Copy Markdown

What Changed

Added the ability to set a per-project worktree location to enable usecases where directory position matters, either for developer tooling (direnv, nix, mise, other monorepo tools) or personal preference

Why

Fixes #6413 which contains the full description, and also enables a pathway for #1878 and #523

TLDR;

  • Developer tooling exists which requires the repo to be in particular directories, and the automatic worktreese
  • Gives users an option to match any other Git client's worktree default (eg, VS Code with the sibling <repo>.worktrees location)

UI Changes

Before:
Screenshot 2026-08-13 at 3 43 15 PM

After:
Screenshot 2026-08-13 at 1 31 22 PM

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes

Note

Medium Risk
Changes where git worktrees are created and expands review cwd allowlisting; misconfiguration could block worktree/PR threads, though invalid roots fail loudly rather than silently.

Overview
Adds per-checkout worktree roots via a new worktreeDirectoryOverrides server setting (workspace root → absolute path, ~ allowed). Clearing an override removes the key because patches replace the whole map.

Worktree creation now consults that setting when no explicit path is passed: GitWorkflowService.createWorktree and PR worktree setup in GitManager.preparePullRequestThread resolve <root>/<sanitized-branch> through shared worktreeLocation helpers. Invalid configured roots fail early instead of falling back to the default layout; an explicit path still wins.

Review treats paths under any valid configured worktree root as in-bounds for diff preview/file contents (invalid roots are skipped for that check).

Settings UI adds a “Worktree location” field per checkout with client-side absolute-path validation aligned with the server.

Reviewed by Cursor Bugbot for commit afe635a. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add per-project worktree location configuration to checkout flow and settings UI

  • Introduces worktreeDirectoryOverrides in ServerSettings as a map of absolute workspace root to absolute worktree root, with whole-map replacement in ServerSettingsPatch and applyServerSettingsPatch
  • Adds worktreeLocation.ts utilities (sanitizeWorktreeBranch, resolveConfiguredWorktreeRoot, lookupWorktreeRoot, joinWorktreePath) and wires them into GitWorkflowService.createWorktree and GitManager.preparePullRequestThread so PR and manual worktree creation use the configured root when no explicit path is given
  • Extends ReviewService.assertWorkspaceBoundCwd to treat CWDs under a project's configured worktree root as in-bounds for getDiffPreview/getDiffFileContents, skipping invalid roots
  • Adds isAbsoluteWorktreeLocation client-side validation and a DraftInput-based field in ProjectSettingsPanel to set or clear the override per checkout
  • Behavioral Change: createWorktree and preparePullRequestThread now fail early with GitCommandError/GitManagerError when a configured worktree root is invalid (non-absolute or empty), instead of silently falling back; GitVcsDriverCore.createWorktree branch sanitization is consolidated into the shared sanitizeWorktreeBranch utility

Macroscope summarized afe635a.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7feddb4c-a0e1-4e30-8533-7e039dee6550

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 13, 2026
Comment on lines +18 to +20
export function sanitizeWorktreeBranch(branch: string): string {
return branch.replace(/\//g, "-");
}

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.

🟠 High git/worktreeLocation.ts:18

joinWorktreePath maps distinct valid branches such as feature/login and feature-login to the same <root>/feature-login directory, so creating the second worktree targets an occupied path and git worktree add fails. Escape the separator and the escape character (or append a stable hash) so sanitizeWorktreeBranch remains injective.

Suggested change
export function sanitizeWorktreeBranch(branch: string): string {
return branch.replace(/\//g, "-");
}
export function sanitizeWorktreeBranch(branch: string): string {
return branch.replace(/%/g, "%25").replace(/\//g, "%2F");
}
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/git/worktreeLocation.ts around lines 18-20:

`joinWorktreePath` maps distinct valid branches such as `feature/login` and `feature-login` to the same `<root>/feature-login` directory, so creating the second worktree targets an occupied path and `git worktree add` fails. Escape the separator and the escape character (or append a stable hash) so `sanitizeWorktreeBranch` remains injective.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't actually agree here. Other applications which create work trees such as VSCode handle sanitization this way https://github.com/microsoft/vscode/blob/main/extensions/git/src/repository.ts#L1953 . This feels like a pointless fix

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.

Sorry, I'm unable to act on this request because you do not have permissions within this repository.

@macroscopeapp

macroscopeapp Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR adds a cross-cutting per-project worktree-location capability that changes production worktree and review-path behavior across several components. An unresolved branch-name collision concern in the new path sanitization also warrants human review.

You can add or adjust custom eligibility rules. Learn more.

@MrSimmmons MrSimmmons mentioned this pull request Aug 13, 2026
3 tasks done

@macroscopeapp macroscopeapp Bot left a comment

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.

Two findings on the new "Worktree location" row in apps/web/src/components/settings/ProjectSettingsPanel.tsx: the invalid state never reaches the Input primitive, and a rejected value leaves a stale error under a field that no longer shows the offending text.

Posted via Macroscope — UI Consistency

…rktree-location

# Conflicts:
#	apps/web/src/components/settings/ProjectSettingsPanel.logic.test.ts
#	apps/web/src/components/settings/ProjectSettingsPanel.logic.ts
#	apps/web/src/components/settings/ProjectSettingsPanel.tsx
@MrSimmmons
MrSimmmons force-pushed the feat/per-project-worktree-location branch from 9969d46 to afe635a Compare August 27, 2026 23:44

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit afe635a. Configure here.

return null;
}
return resolveConfiguredWorktreeRoot(configured);
}

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.

Worktree override lookup misses path variants

Medium Severity

lookupWorktreeRoot indexes worktreeDirectoryOverrides with a trimmed cwd only. It never normalizes trailing slashes, Windows drive casing, or separators the way normalizeProjectPathForComparison does elsewhere. Settings are written under selectedCheckout.workspaceRoot, then resolved from RPC cwd. If those strings differ, the override is treated as unset and new worktrees silently land in the default T3 home layout.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit afe635a. Configure here.

@t3dotgg

t3dotgg commented Aug 28, 2026

Copy link
Copy Markdown
Member

Note

🤖 GPT-5.6 Sol responding on behalf of Theo

We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

This adds a per-project worktree location setting across server, contracts, web, and mobile. We are not adding this new worktree configuration path through the current backlog.

If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

@t3dotgg t3dotgg closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Per-project worktree location

2 participants