Improve branch mismatch warnings

This commit is contained in:
justsomelegs committed 2026-05-01 22:30:04 +01:00
1 parent 7a3f21e7ca
commit d7cc9174ae
9 files changed
+434 -114

No files matched your search

+51 -31
View File
@@ -204,6 +204,37 @@ function resolvePullRequestHeadRepositoryNameWithOwner(
return `${ownerLogin}/${repositoryName}`;
}
interface PullRequestHeadIdentity {
readonly repositoryNameWithOwner: string | null;
readonly ownerLogin: string | null;
}
function resolveExpectedHeadIdentity(
headContext: Pick<BranchHeadContext, "headRepositoryNameWithOwner" | "headRepositoryOwnerLogin">,
): PullRequestHeadIdentity {
const repositoryNameWithOwner = normalizeOptionalRepositoryNameWithOwner(
headContext.headRepositoryNameWithOwner,
);
return {
repositoryNameWithOwner,
ownerLogin:
normalizeOptionalOwnerLogin(headContext.headRepositoryOwnerLogin) ??
parseRepositoryOwnerLogin(repositoryNameWithOwner),
};
}
function resolvePullRequestHeadIdentity(pr: PullRequestInfo): PullRequestHeadIdentity {
const repositoryNameWithOwner = normalizeOptionalRepositoryNameWithOwner(
resolvePullRequestHeadRepositoryNameWithOwner(pr),
);
return {
repositoryNameWithOwner,
ownerLogin:
normalizeOptionalOwnerLogin(pr.headRepositoryOwnerLogin) ??
parseRepositoryOwnerLogin(repositoryNameWithOwner),
};
}
function matchesBranchHeadContext(
pr: PullRequestInfo,
headContext: Pick<
@@ -215,44 +246,33 @@ function matchesBranchHeadContext(
return false;
}
const expectedHeadRepository = normalizeOptionalRepositoryNameWithOwner(
headContext.headRepositoryNameWithOwner,
);
const expectedHeadOwner =
normalizeOptionalOwnerLogin(headContext.headRepositoryOwnerLogin) ??
parseRepositoryOwnerLogin(expectedHeadRepository);
const prHeadRepository = normalizeOptionalRepositoryNameWithOwner(
resolvePullRequestHeadRepositoryNameWithOwner(pr),
);
const prHeadOwner =
normalizeOptionalOwnerLogin(pr.headRepositoryOwnerLogin) ??
parseRepositoryOwnerLogin(prHeadRepository);
const expectedHead = resolveExpectedHeadIdentity(headContext);
const pullRequestHead = resolvePullRequestHeadIdentity(pr);
if (expectedHead.repositoryNameWithOwner) {
if (pullRequestHead.repositoryNameWithOwner) {
return expectedHead.repositoryNameWithOwner === pullRequestHead.repositoryNameWithOwner;
}
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
return expectedHead.ownerLogin === pullRequestHead.ownerLogin;
}
if (pr.isCrossRepository === true) {
return false;
}
}
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
return expectedHead.ownerLogin === pullRequestHead.ownerLogin;
}
if (headContext.isCrossRepository) {
if (pr.isCrossRepository === false) {
return false;
}
if ((expectedHeadRepository || expectedHeadOwner) && !prHeadRepository && !prHeadOwner) {
return false;
}
if (expectedHeadRepository && prHeadRepository && expectedHeadRepository !== prHeadRepository) {
return false;
}
if (expectedHeadOwner && prHeadOwner && expectedHeadOwner !== prHeadOwner) {
return false;
}
return true;
return pr.isCrossRepository !== false;
}
if (pr.isCrossRepository === true) {
return false;
}
if (expectedHeadRepository && prHeadRepository && expectedHeadRepository !== prHeadRepository) {
return false;
}
if (expectedHeadOwner && prHeadOwner && expectedHeadOwner !== prHeadOwner) {
return false;
}
return true;
}
@@ -11,6 +11,7 @@ import {
resolveEnvModeLabel,
resolveBranchToolbarValue,
resolveLockedWorkspaceLabel,
resolveLocalCheckoutBranchMismatch,
shouldIncludeBranchPickerItem,
} from "./BranchToolbar.logic";
@@ -84,6 +85,55 @@ describe("resolveBranchToolbarValue", () => {
});
});
describe("resolveLocalCheckoutBranchMismatch", () => {
it("detects when a local thread is associated with a different branch than the checkout", () => {
expect(
resolveLocalCheckoutBranchMismatch({
effectiveEnvMode: "local",
activeWorktreePath: null,
activeThreadBranch: "feature/thread",
currentGitBranch: "feature/current",
}),
).toEqual({
threadBranch: "feature/thread",
currentBranch: "feature/current",
});
});
it("ignores matching local checkout state", () => {
expect(
resolveLocalCheckoutBranchMismatch({
effectiveEnvMode: "local",
activeWorktreePath: null,
activeThreadBranch: "feature/thread",
currentGitBranch: "feature/thread",
}),
).toBeNull();
});
it("ignores dedicated worktrees because their checkout is already thread-scoped", () => {
expect(
resolveLocalCheckoutBranchMismatch({
effectiveEnvMode: "worktree",
activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
activeThreadBranch: "feature/thread",
currentGitBranch: "feature/current",
}),
).toBeNull();
});
it("ignores new-worktree base selection before a worktree exists", () => {
expect(
resolveLocalCheckoutBranchMismatch({
effectiveEnvMode: "worktree",
activeWorktreePath: null,
activeThreadBranch: "feature/base",
currentGitBranch: "main",
}),
).toBeNull();
});
});
describe("resolveEnvironmentOptionLabel", () => {
it("prefers the primary environment's machine label", () => {
expect(
@@ -97,6 +97,22 @@ export function resolveBranchToolbarValue(input: {
return currentGitBranch ?? activeThreadBranch;
}
export function resolveLocalCheckoutBranchMismatch(input: {
effectiveEnvMode: EnvMode;
activeWorktreePath: string | null;
activeThreadBranch: string | null;
currentGitBranch: string | null;
}): { threadBranch: string; currentBranch: string } | null {
const { effectiveEnvMode, activeWorktreePath, activeThreadBranch, currentGitBranch } = input;
if (effectiveEnvMode !== "local" || activeWorktreePath !== null) {
return null;
}
if (!activeThreadBranch || !currentGitBranch || activeThreadBranch === currentGitBranch) {
return null;
}
return { threadBranch: activeThreadBranch, currentBranch: currentGitBranch };
}
export function resolveBranchSelectionTarget(input: {
activeProjectCwd: string;
activeWorktreePath: string | null;
@@ -2,7 +2,7 @@ import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime";
import type { EnvironmentId, GitBranch, ThreadId } from "@t3tools/contracts";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
import { LegendList, type LegendListRef } from "@legendapp/list/react";
import { ChevronDownIcon } from "lucide-react";
import { ChevronDownIcon, TriangleAlertIcon } from "lucide-react";
import {
useCallback,
useDeferredValue,
@@ -17,9 +17,8 @@ import {
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
import { readEnvironmentApi } from "../environmentApi";
import { gitBranchSearchInfiniteQueryOptions, gitQueryKeys } from "../lib/gitReactQuery";
import { useGitStatus } from "../lib/gitStatusState";
import { newCommandId } from "../lib/utils";
import { cn } from "../lib/utils";
import { refreshGitStatus, useGitStatus } from "../lib/gitStatusState";
import { cn, newCommandId } from "../lib/utils";
import { parsePullRequestReference } from "../pullRequestReference";
import { useStore } from "../store";
import { createProjectSelectorByRef, createThreadSelectorByRef } from "../storeSelectors";
@@ -29,6 +28,7 @@ import {
resolveBranchToolbarValue,
resolveDraftEnvModeAfterBranchChange,
resolveEffectiveEnvMode,
resolveLocalCheckoutBranchMismatch,
shouldIncludeBranchPickerItem,
} from "./BranchToolbar.logic";
import { Button } from "./ui/button";
@@ -43,6 +43,7 @@ import {
ComboboxStatus,
ComboboxTrigger,
} from "./ui/combobox";
import { Popover, PopoverPopup, PopoverTrigger } from "./ui/popover";
import { stackedThreadToast, toastManager } from "./ui/toast";
interface BranchToolbarBranchSelectorProps {
@@ -197,7 +198,9 @@ export function BranchToolbarBranchSelector({
// ---------------------------------------------------------------------------
const queryClient = useQueryClient();
const [isBranchMenuOpen, setIsBranchMenuOpen] = useState(false);
const [isMismatchPopoverOpen, setIsMismatchPopoverOpen] = useState(false);
const [branchQuery, setBranchQuery] = useState("");
const branchPickerAnchorRef = useRef<HTMLDivElement | null>(null);
const deferredBranchQuery = useDeferredValue(branchQuery);
const branchStatusQuery = useGitStatus({ environmentId, cwd: branchCwd });
@@ -236,6 +239,12 @@ export function BranchToolbarBranchSelector({
activeThreadBranch,
currentGitBranch,
});
const localCheckoutBranchMismatch = resolveLocalCheckoutBranchMismatch({
effectiveEnvMode,
activeWorktreePath,
activeThreadBranch,
currentGitBranch,
});
const branchNames = useMemo(() => branches.map((branch) => branch.name), [branches]);
const branchByName = useMemo(
() => new Map(branches.map((branch) => [branch.name, branch] as const)),
@@ -305,6 +314,7 @@ export function BranchToolbarBranchSelector({
await queryClient
.invalidateQueries({ queryKey: gitQueryKeys.branches(environmentId, branchCwd) })
.catch(() => undefined);
await refreshGitStatus({ environmentId, cwd: branchCwd }).catch(() => undefined);
});
};
@@ -397,6 +407,46 @@ export function BranchToolbarBranchSelector({
});
};
const switchCheckoutToThreadBranch = () => {
const api = readEnvironmentApi(environmentId);
if (!api || !activeProjectCwd || !localCheckoutBranchMismatch || isBranchActionPending) {
return;
}
runBranchAction(async () => {
const previousBranch = resolvedActiveBranch;
setOptimisticBranch(localCheckoutBranchMismatch.threadBranch);
try {
const checkoutResult = await api.git.checkout({
cwd: activeProjectCwd,
branch: localCheckoutBranchMismatch.threadBranch,
});
setOptimisticBranch(checkoutResult.branch ?? localCheckoutBranchMismatch.threadBranch);
setIsMismatchPopoverOpen(false);
onComposerFocusRequest?.();
} catch (error) {
setOptimisticBranch(previousBranch);
toastManager.add(
stackedThreadToast({
type: "error",
title: "Failed to switch checkout.",
description: toBranchActionErrorMessage(error),
}),
);
}
});
};
const useCurrentCheckoutForThread = () => {
if (!localCheckoutBranchMismatch || isBranchActionPending) {
return;
}
setThreadBranch(localCheckoutBranchMismatch.currentBranch, null);
setIsMismatchPopoverOpen(false);
onComposerFocusRequest?.();
};
useEffect(() => {
if (
effectiveEnvMode !== "worktree" ||
@@ -560,72 +610,146 @@ export function BranchToolbarBranchSelector({
}
return (
<Combobox
items={branchPickerItems}
filteredItems={filteredBranchPickerItems}
autoHighlight
virtualized={shouldVirtualizeBranchList}
onItemHighlighted={(_value, eventDetails) => {
if (!isBranchMenuOpen || eventDetails.index < 0 || eventDetails.reason !== "keyboard") {
return;
}
branchListRef.current?.scrollIndexIntoView?.({
index: eventDetails.index,
animated: false,
});
}}
onOpenChange={handleOpenChange}
open={isBranchMenuOpen}
value={resolvedActiveBranch}
>
<ComboboxTrigger
render={<Button variant="ghost" size="xs" />}
className={cn("min-w-0 text-muted-foreground/70 hover:text-foreground/80", className)}
disabled={(isBranchesSearchPending && branches.length === 0) || isBranchActionPending}
<div ref={branchPickerAnchorRef} className="relative flex min-w-0 items-center justify-end">
{localCheckoutBranchMismatch ? (
<Popover open={isMismatchPopoverOpen} onOpenChange={setIsMismatchPopoverOpen}>
<PopoverTrigger
openOnHover
delay={120}
closeDelay={100}
render={
<button
type="button"
className="absolute left-1.5 top-1/2 z-10 flex size-4.5 -translate-y-1/2 items-center justify-center rounded-sm text-warning outline-none transition-colors hover:bg-warning/10 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
aria-label="Thread branch does not match current checkout"
/>
}
>
<TriangleAlertIcon aria-hidden="true" className="size-3.5" />
</PopoverTrigger>
<PopoverPopup
tooltipStyle
side="top"
align="center"
sideOffset={8}
anchor={branchPickerAnchorRef}
className="w-[28rem] max-w-[calc(100vw-2rem)] px-2 py-2"
>
<div className="chat-markdown space-y-2.5 text-xs leading-snug">
<div className="grid grid-cols-[5.25rem_minmax(0,1fr)] gap-x-2.5 gap-y-1.5">
<span className="text-muted-foreground">Thread</span>
<code className="max-w-full justify-self-start">
{localCheckoutBranchMismatch.threadBranch}
</code>
<span className="text-muted-foreground">Checkout</span>
<code className="max-w-full justify-self-start">
{localCheckoutBranchMismatch.currentBranch}
</code>
</div>
<p className="!my-0 border-border/70 border-t pt-2 text-muted-foreground">
This thread was last associated with{" "}
<code>{localCheckoutBranchMismatch.threadBranch}</code>, but your checkout is on
another branch. Switch to keep working there, or use current to update the thread to
this checkout.
</p>
<div className="mt-2 flex justify-end gap-1.5">
<Button
variant="ghost"
size="xs"
className="h-6 px-1.5 text-[11px] text-muted-foreground hover:text-foreground"
disabled={isBranchActionPending}
title={`Associate this thread with ${localCheckoutBranchMismatch.currentBranch}`}
onClick={useCurrentCheckoutForThread}
>
Use current
</Button>
<Button
variant="outline"
size="xs"
className="h-6 px-1.5 text-[11px]"
disabled={isBranchActionPending}
title={`Checkout ${localCheckoutBranchMismatch.threadBranch}`}
onClick={switchCheckoutToThreadBranch}
>
Switch
</Button>
</div>
</div>
</PopoverPopup>
</Popover>
) : null}
<Combobox
items={branchPickerItems}
filteredItems={filteredBranchPickerItems}
autoHighlight
virtualized={shouldVirtualizeBranchList}
onItemHighlighted={(_value, eventDetails) => {
if (!isBranchMenuOpen || eventDetails.index < 0 || eventDetails.reason !== "keyboard") {
return;
}
branchListRef.current?.scrollIndexIntoView?.({
index: eventDetails.index,
animated: false,
});
}}
onOpenChange={handleOpenChange}
open={isBranchMenuOpen}
value={resolvedActiveBranch}
>
<span className="min-w-0 max-w-[240px] truncate">{triggerLabel}</span>
<ChevronDownIcon className="shrink-0" />
</ComboboxTrigger>
<ComboboxPopup align="end" side="top" className="w-80">
<div className="border-b p-1">
<ComboboxInput
className="[&_input]:font-sans rounded-md"
inputClassName="ring-0"
placeholder="Search branches..."
showTrigger={false}
size="sm"
value={branchQuery}
onChange={(event) => setBranchQuery(event.target.value)}
/>
</div>
<ComboboxEmpty>No branches found.</ComboboxEmpty>
{shouldVirtualizeBranchList ? (
<ComboboxListVirtualized>
<LegendList<string>
ref={branchListRef}
data={filteredBranchPickerItems}
keyExtractor={(item) => item}
renderItem={({ item, index }) => renderPickerItem(item, index)}
estimatedItemSize={28}
drawDistance={336}
onEndReached={() => {
if (hasNextPage && !isFetchingNextPage) {
void fetchNextPage().catch(() => undefined);
}
}}
style={{ maxHeight: "14rem" }}
<ComboboxTrigger
render={<Button variant="ghost" size="xs" />}
className={cn(
"min-w-0 text-muted-foreground/70 hover:text-foreground/80",
localCheckoutBranchMismatch &&
"border-warning/35 bg-warning/10 pl-7 text-warning hover:bg-warning/15 hover:text-warning",
className,
)}
disabled={(isBranchesSearchPending && branches.length === 0) || isBranchActionPending}
>
<span className="min-w-0 max-w-[240px] truncate">{triggerLabel}</span>
<ChevronDownIcon className="shrink-0" />
</ComboboxTrigger>
<ComboboxPopup align="end" side="top" className="w-80">
<div className="border-b p-1">
<ComboboxInput
className="[&_input]:font-sans rounded-md"
inputClassName="ring-0"
placeholder="Search branches..."
showTrigger={false}
size="sm"
value={branchQuery}
onChange={(event) => setBranchQuery(event.target.value)}
/>
</ComboboxListVirtualized>
) : (
<ComboboxList ref={setBranchListRef} className="max-h-56">
{filteredBranchPickerItems.map((itemValue, index) =>
renderPickerItem(itemValue, index),
)}
</ComboboxList>
)}
{branchStatusText ? <ComboboxStatus>{branchStatusText}</ComboboxStatus> : null}
</ComboboxPopup>
</Combobox>
</div>
<ComboboxEmpty>No branches found.</ComboboxEmpty>
{shouldVirtualizeBranchList ? (
<ComboboxListVirtualized>
<LegendList<string>
ref={branchListRef}
data={filteredBranchPickerItems}
keyExtractor={(item) => item}
renderItem={({ item, index }) => renderPickerItem(item, index)}
estimatedItemSize={28}
drawDistance={336}
onEndReached={() => {
if (hasNextPage && !isFetchingNextPage) {
void fetchNextPage().catch(() => undefined);
}
}}
style={{ maxHeight: "14rem" }}
/>
</ComboboxListVirtualized>
) : (
<ComboboxList ref={setBranchListRef} className="max-h-56">
{filteredBranchPickerItems.map((itemValue, index) =>
renderPickerItem(itemValue, index),
)}
</ComboboxList>
)}
{branchStatusText ? <ComboboxStatus>{branchStatusText}</ComboboxStatus> : null}
</ComboboxPopup>
</Combobox>
</div>
);
}
@@ -29,6 +29,7 @@ const {
invalidateGitQueriesSpy,
refreshGitStatusSpy,
runStackedActionMutateAsyncSpy,
serverThreadBranchRef,
setDraftThreadContextSpy,
setThreadBranchSpy,
toastAddSpy,
@@ -42,6 +43,7 @@ const {
invalidateGitQueriesSpy: vi.fn(() => Promise.resolve()),
refreshGitStatusSpy: vi.fn(() => Promise.resolve(null)),
runStackedActionMutateAsyncSpy: vi.fn(() => activeRunStackedActionDeferredRef.current.promise),
serverThreadBranchRef: { current: "feature/toast-scope" },
setDraftThreadContextSpy: vi.fn(),
setThreadBranchSpy: vi.fn(),
toastAddSpy: vi.fn(() => "toast-1"),
@@ -199,7 +201,7 @@ vi.mock("~/store", () => ({
? {
[SHARED_THREAD_ID]: {
id: SHARED_THREAD_ID,
branch: BRANCH_NAME,
branch: serverThreadBranchRef.current,
worktreePath: null,
},
}
@@ -220,7 +222,7 @@ vi.mock("~/store", () => ({
? {
[SHARED_THREAD_ID]: {
id: SHARED_THREAD_ID,
branch: BRANCH_NAME,
branch: serverThreadBranchRef.current,
worktreePath: null,
},
}
@@ -277,6 +279,7 @@ describe("GitActionsControl thread-scoped progress toast", () => {
activeRunStackedActionDeferredRef.current = createDeferredPromise<never>();
activeDraftThreadRef.current = null;
hasServerThreadRef.current = true;
serverThreadBranchRef.current = BRANCH_NAME;
document.body.innerHTML = "";
});
@@ -428,6 +431,32 @@ describe("GitActionsControl thread-scoped progress toast", () => {
}
});
it("does not overwrite an existing server thread branch when the shared checkout differs", async () => {
serverThreadBranchRef.current = "feature/thread-branch";
const host = document.createElement("div");
document.body.append(host);
const screen = await render(
<GitActionsControl
gitCwd={GIT_CWD}
activeThreadRef={scopeThreadRef(ENVIRONMENT_A, SHARED_THREAD_ID)}
/>,
{
container: host,
},
);
try {
await Promise.resolve();
expect(setThreadBranchSpy).not.toHaveBeenCalled();
expect(setDraftThreadContextSpy).not.toHaveBeenCalled();
} finally {
await screen.unmount();
host.remove();
}
});
it("does not overwrite a selected base branch while a new worktree draft is being configured", async () => {
hasServerThreadRef.current = false;
activeDraftThreadRef.current = {
@@ -360,12 +360,12 @@ export default function GitActionsControl({
activeDraftThread.worktreePath === null;
useEffect(() => {
if (isGitActionRunning || isSelectingWorktreeBase) {
if (isGitActionRunning || isSelectingWorktreeBase || activeServerThread) {
return;
}
const branchUpdate = resolveLiveThreadBranchUpdate({
threadBranch: activeServerThread?.branch ?? activeDraftThread?.branch ?? null,
threadBranch: activeDraftThread?.branch ?? null,
gitStatus: gitStatusForActions,
});
if (!branchUpdate) {
@@ -374,7 +374,7 @@ export default function GitActionsControl({
persistThreadBranchSync(branchUpdate.branch);
}, [
activeServerThread?.branch,
activeServerThread,
activeDraftThread?.branch,
gitStatusForActions,
isGitActionRunning,
+6 -2
View File
@@ -355,7 +355,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
const gitCwd = thread.worktreePath ?? threadProjectCwd ?? props.projectCwd;
const gitStatus = useGitStatus({
environmentId: thread.environmentId,
cwd: thread.branch != null ? gitCwd : null,
cwd: thread.branch != null || thread.worktreePath !== null ? gitCwd : null,
});
const isHighlighted = isActive || isSelected;
const isThreadRunning =
@@ -366,7 +366,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
lastVisitedAt,
},
});
const pr = resolveThreadPr(thread.branch, gitStatus.data);
const pr = resolveThreadPr({
threadBranch: thread.branch,
gitStatus: gitStatus.data,
hasDedicatedWorktree: thread.worktreePath !== null,
});
const prStatus = prStatusIndicator(pr);
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning;
@@ -0,0 +1,63 @@
import type { GitStatusResult } from "@t3tools/contracts";
import { describe, expect, it } from "vitest";
import { resolveThreadPr } from "./ThreadStatusIndicators";
function status(overrides: Partial<GitStatusResult> = {}): GitStatusResult {
return {
isRepo: true,
hasOriginRemote: true,
isDefaultBranch: false,
branch: "feature/current",
hasWorkingTreeChanges: false,
workingTree: { files: [], insertions: 0, deletions: 0 },
hasUpstream: true,
aheadCount: 0,
behindCount: 0,
pr: {
number: 42,
title: "PR branch",
url: "https://github.com/pingdotgg/t3code/pull/42",
baseBranch: "main",
headBranch: "feature/current",
state: "open",
},
...overrides,
};
}
describe("resolveThreadPr", () => {
it("keeps local-checkout PR indicators scoped to the stored thread branch", () => {
expect(
resolveThreadPr({
threadBranch: "feature/other",
gitStatus: status(),
hasDedicatedWorktree: false,
}),
).toBeNull();
});
it("shows PR indicators for dedicated worktree threads even when branch metadata is stale", () => {
const gitStatus = status();
expect(
resolveThreadPr({
threadBranch: "feature/old-name",
gitStatus,
hasDedicatedWorktree: true,
}),
).toBe(gitStatus.pr);
});
it("shows PR indicators for dedicated worktree threads even when branch metadata is missing", () => {
const gitStatus = status();
expect(
resolveThreadPr({
threadBranch: null,
gitStatus,
hasDedicatedWorktree: true,
}),
).toBe(gitStatus.pr);
});
});
@@ -60,11 +60,21 @@ export function prStatusIndicator(pr: ThreadPr): PrStatusIndicator | null {
return null;
}
export function resolveThreadPr(
threadBranch: string | null,
gitStatus: GitStatusResult | null,
): ThreadPr | null {
if (threadBranch === null || gitStatus === null || gitStatus.branch !== threadBranch) {
export function resolveThreadPr(input: {
threadBranch: string | null;
gitStatus: GitStatusResult | null;
hasDedicatedWorktree: boolean;
}): ThreadPr | null {
const { threadBranch, gitStatus, hasDedicatedWorktree } = input;
if (gitStatus === null) {
return null;
}
if (hasDedicatedWorktree) {
return gitStatus.pr ?? null;
}
if (threadBranch === null || gitStatus.branch !== threadBranch) {
return null;
}
@@ -143,9 +153,13 @@ export function ThreadRowLeadingStatus({ thread }: { thread: SidebarThreadSummar
const gitCwd = thread.worktreePath ?? threadProjectCwd;
const gitStatus = useGitStatus({
environmentId: thread.environmentId,
cwd: thread.branch != null ? gitCwd : null,
cwd: thread.branch != null || thread.worktreePath !== null ? gitCwd : null,
});
const pr = resolveThreadPr({
threadBranch: thread.branch,
gitStatus: gitStatus.data,
hasDedicatedWorktree: thread.worktreePath !== null,
});
const pr = resolveThreadPr(thread.branch, gitStatus.data);
const prStatus = prStatusIndicator(pr);
const threadStatus = resolveThreadStatusPill({
thread: {