feat(projects): configurable per-project worktree location #9681
Closedmurbanowicz(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/9681/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts line 554Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -457,3 +459,11 @@457459 `,458460 });459461462+ const listActiveProjectWorktreeRootRows = SqlSchema.findAll({463+ Request: Schema.Void,464+ Result: Schema.Struct({ worktreeRoot: Schema.String }),465+ execute: () =>466+ sql`467+ SELECT DISTINCT worktree_root AS "worktreeRoot"468+ FROM projection_projects469+ WHERE deleted_at IS NULLapps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts lines 470 to 470OutdatedResolvedby murbanowicz(GitHub profile, opens in a new tab)@@ -457,3 +459,12 @@457459 `,458460 });459461462+ const listActiveProjectWorktreeRootRows = SqlSchema.findAll({463+ Request: Schema.Void,464+ Result: Schema.Struct({ worktreeRoot: Schema.String }),465+ execute: () =>466+ sql`467+ SELECT DISTINCT worktree_root AS "worktreeRoot"468+ FROM projection_projects469+ WHERE deleted_at IS NULL470+ AND worktree_root IS NOT NULLpackages/contracts/src/orchestration.ts line 427Resolvedby murbanowicz(GitHub profile, opens in a new tab)@@ -284,3 +284,12 @@284284 );285285 export type ProjectFaviconPath = typeof ProjectFaviconPath.Type;286286287+/**288+ * Directory a project's new worktrees are created under, as `<root>/<branch>`.289+ * Absolute only — POSIX, Windows drive or UNC, or `~`-relative and expanded on290+ * the server that owns the project, since a relative root would resolve against291+ * whatever cwd that server happens to have.292+ */293+export const ProjectWorktreeRoot = TrimmedNonEmptyString.check(294+ Schema.isMaxLength(1024),295+ Schema.isPattern(/^(?:~(?:$|[/\\])|\/|\\\\|[A-Za-z]:[/\\])/),apps/web/src/components/settings/ProjectSettingsPanel.tsx line 496OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -478,3 +479,18 @@478479 [updateAllMembers],479480 );480481482+ const worktreeRoot = representative.worktreeRoot ?? null;483+ const setWorktreeRoot = useCallback(484+ (nextRoot: string) => {485+ const trimmed = nextRoot.trim();486+ if (trimmed === (worktreeRoot ?? "")) return;487+ // Caught here so a relative path reports itself instead of failing the write.488+ if (trimmed !== "" && !/^(?:~(?:$|[/\\])|\/|\\\\|[A-Za-z]:[/\\])/.test(trimmed)) {489+ toastManager.add({490+ type: "warning",491+ title: "Worktree location must be an absolute path",492+ description: "Start it with / or ~/ so it does not depend on where the server runs.",493+ });494+ return;495+ }496+ void updateAllMembers(@@ -1128,9 +1134,13 @@11281134 worktreeBaseRef = resolvedRemoteBase.commitSha;11291135 }11301136 }1137+ const worktreeRootDir = yield* resolveProjectWorktreeRoot(1138+ bootstrap.prepareWorktree.projectCwd,1139+ );11311140 const worktree = yield* gitWorkflow.createWorktree({11321141 cwd: bootstrap.prepareWorktree.projectCwd,11331142 refName: worktreeBaseRef,11341143 newRefName: bootstrap.prepareWorktree.branch,11351144 baseRefName: bootstrap.prepareWorktree.baseBranch,11361145 path: null,1146+ ...(worktreeRootDir === undefined ? {} : { rootDir: worktreeRootDir }),
- apps/server/src/review/ReviewService.ts line 98Resolvedby murbanowicz(GitHub profile, opens in a new tab)@@ -76,3 +79,17 @@7679 return;7780 }788182+ // Any configured root counts, matching the shared default worktrees83+ // directory this already accepts. A failed read honors only the defaults,84+ // denying rather than over-permitting.85+ const configuredRoots = yield* projectionSnapshotQuery86+ .listActiveProjectWorktreeRoots()87+ .pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));88+ for (const configuredRoot of configuredRoots) {89+ const resolvedRoot = yield* canonicalizePath(expandHomePathWith(configuredRoot, path)).pipe(90+ Effect.orElseSucceed(() => null),91+ );92+ if (resolvedRoot !== null && isWithinRoot(candidate, resolvedRoot)) {93+ return;94+ }95+ }
- apps/server/src/vcs/GitVcsDriverCore.ts line 2878Resolvedby murbanowicz(GitHub profile, opens in a new tab)@@ -2837,4 +2837,6 @@28372837 const targetBranch = input.newRefName ?? input.refName;28382838 const sanitizedBranch = targetBranch.replace(/\//g, "-");28392839 const repoName = path.basename(input.cwd);2840- const worktreePath = input.path ?? path.join(worktreesDir, repoName, sanitizedBranch);2840+ // A configured root belongs to one checkout, so it needs no repository2841+ // segment; the shared default is one directory for every repo, so it does.2842+ const rootDir = input.rootDir ?? path.join(worktreesDir, repoName);
- apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts line 554Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -457,3 +459,11 @@457459 `,458460 });459461462+ const listActiveThreadWorktreePathRows = SqlSchema.findAll({463+ Request: Schema.Void,464+ Result: Schema.Struct({ worktreePath: Schema.String }),465+ execute: () =>466+ sql`467+ SELECT DISTINCT worktree_path AS "worktreePath"468+ FROM projection_threads469+ WHERE deleted_at IS NULLapps/web/src/components/settings/ProjectSettingsPanel.tsx line 525OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -510,3 +510,16 @@510510 const selectedCheckout =511511 group.memberProjects.find((member) => member.physicalProjectKey === selectedCheckoutKey) ??512512 representative;513+ // Per checkout rather than per group: the root is a filesystem path, so it is514+ // only meaningful on the machine that owns this checkout.515+ const checkoutWorktreeRoot = selectedCheckout.worktreeRoot ?? null;516+ const setCheckoutWorktreeRoot = useCallback(517+ async (nextRoot: string) => {518+ const trimmed = nextRoot.trim();519+ if (trimmed === (checkoutWorktreeRoot ?? "")) return;520+ // Caught here so a relative path reports itself instead of failing the write.521+ if (trimmed !== "" && !/^(?:~(?:$|[/\\])|\/|\\\\|[A-Za-z]:[/\\])/.test(trimmed)) {522+ toastManager.add({523+ type: "warning",524+ title: "Worktree location must be an absolute path",525+ description: "Start it with / or ~/ so it does not depend on where the server runs.",packages/contracts/src/git.ts lines 155 to 160Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -141,3 +141,16 @@141141 newRefName: Schema.optional(TrimmedNonEmptyStringSchema),142142 baseRefName: Schema.optional(TrimmedNonEmptyStringSchema),143143 path: Schema.NullOr(TrimmedNonEmptyStringSchema),144+ /**145+ * Creates the worktree at `<rootDir>/<branch>`. Ignored when `path` is set.146+ * Absolute only — POSIX, Windows drive or UNC — because a relative root is147+ * joined and handed to Git, which would resolve it against the repository148+ * being branched from and place the worktree outside any managed location.149+ * Already `~`-expanded: a project's root is resolved before it gets here.150+ */151+ rootDir: Schema.optional(152+ TrimmedNonEmptyStringSchema.check(153+ Schema.isMaxLength(1024),154+ Schema.isPattern(/^(?:\/|\\\\|[A-Za-z]:[/\\])/),155+ ),156+ ),
juliusmarminge closed this
Sign in to join this conversation.






macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed