Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions apps/web/src/components/BranchToolbar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,27 @@ describe("resolveBranchSelectionTarget", () => {
});

it("switches back to the main repo when the ref already lives there", () => {
expect(
resolveBranchSelectionTarget({
activeProjectCwd: "/repo",
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
refName: {
isDefault: true,
worktreePath: "/repo",
},
}),
).toEqual({
checkoutCwd: "/repo",
nextWorktreePath: null,
reuseExistingWorktree: true,
});
// A subdirectory project's own checkout is reported at the repository root.
for (const [activeProjectCwd, activeWorktreePath] of [
["/repo", "/repo/.t3/worktrees/feature-a"],
["/repo/packages/app", "/repo/.t3/worktrees/feature-a"],
["/repo/packages/app", null],
] as const) {
expect(
resolveBranchSelectionTarget({
activeProjectCwd,
activeWorktreePath,
refName: {
isDefault: true,
worktreePath: "/repo",
},
}),
).toEqual({
checkoutCwd: "/repo",
nextWorktreePath: null,
reuseExistingWorktree: true,
});
}
});

it("keeps checkout in the current worktree for non-default refs", () => {
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/BranchToolbar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { sanitizeNewRefName } from "@t3tools/shared/git";
import { workspaceRelativeFilePath } from "@t3tools/shared/path";
import { toSortableTimestamp } from "@t3tools/client-runtime/state/thread-sort";
export { deriveLocalBranchNameFromRemoteRef, sanitizeNewRefName } from "@t3tools/shared/git";

Expand Down Expand Up @@ -257,9 +258,12 @@ export function resolveBranchSelectionTarget(input: {
const { activeProjectCwd, activeWorktreePath, refName } = input;

if (refName.worktreePath) {
// A project in a repository subdirectory sits inside its checkout's root.
const isProjectCheckout =
workspaceRelativeFilePath(activeProjectCwd, refName.worktreePath) !== null;
Comment thread
saphid marked this conversation as resolved.
Resolved
return {
checkoutCwd: refName.worktreePath,
nextWorktreePath: refName.worktreePath === activeProjectCwd ? null : refName.worktreePath,
nextWorktreePath: isProjectCheckout ? null : refName.worktreePath,
reuseExistingWorktree: true,
};
}
Expand Down
Loading