diff --git a/web/src/components/diff-view/DiffToolbar.tsx b/web/src/components/diff-view/DiffToolbar.tsx index 1eed1eb..9f7d825 100644 --- a/web/src/components/diff-view/DiffToolbar.tsx +++ b/web/src/components/diff-view/DiffToolbar.tsx @@ -73,22 +73,23 @@ function BranchChip({ label, title }: { label: string; title: string }) { ); } +// An empty head means the checked-out branch; dirty changes only apply there. function branchDiffHref(base: string, head: string, includeDirty: boolean) { const params = new URLSearchParams(); params.set("base", base); if (head) params.set("head", head); - if (includeDirty) params.set("dirty", "1"); + else if (includeDirty) params.set("dirty", "1"); return `/branch?${params.toString()}`; } -function BaseBranchSwitcher({ - baseRef, - headRef, - includeDirty, +function BranchSwitcher({ + role, + current, + hrefFor, }: { - baseRef: string; - headRef: string; - includeDirty: boolean; + role: "Base" | "Head"; + current: string; + hrefFor: (name: string) => string; }) { const [branches, setBranches] = useState(null); const [loading, setLoading] = useState(false); @@ -98,10 +99,10 @@ function BaseBranchSwitcher({ apiFetch<{ branches: string[] }>("/api/branches") .then((data) => { const names = [...(data.branches ?? [])]; - if (baseRef !== "" && !names.includes(baseRef)) names.unshift(baseRef); + if (current !== "" && !names.includes(current)) names.unshift(current); setBranches(names); }) - .catch(() => setBranches(baseRef !== "" ? [baseRef] : [])) + .catch(() => setBranches(current !== "" ? [current] : [])) .finally(() => setLoading(false)); }; @@ -116,10 +117,11 @@ function BaseBranchSwitcher({ } @@ -134,11 +136,11 @@ function BaseBranchSwitcher({
No branches found
) : ( branches?.map((name) => { - const selected = name === baseRef; + const selected = name === current; return ( } + render={} className={selected ? "font-medium" : undefined} aria-current={selected ? "true" : undefined} > @@ -283,21 +285,33 @@ export function DiffToolbar({ > {displayLocalPath(config.cwd)} - {baseRef && baseRef.trim() !== "" && ( + {baseRef && baseRef.trim() !== "" ? ( <> - branchDiffHref(name, headRef, includeDirty)} /> + + branchDiffHref( + baseRef.trim(), + name === config.gitBranch.trim() ? "" : name, + includeDirty, + ) + } + /> - )} - {branchLabel !== "" && ( - + ) : ( + branchLabel !== "" && ( + + ) )} ) : (