setDiffCommentsExpanded(true)}
branchSummary={branchSummary}
compareBaseRef={compareBaseRef}
+ headDisplay={gitIdentityDisplay}
upstreamStatus={remoteStatus}
manualReviewUrl={manualReviewUrl}
/>
diff --git a/src/renderer/src/components/right-sidebar/source-control-branch-context-row.test.tsx b/src/renderer/src/components/right-sidebar/source-control-branch-context-row.test.tsx
index 8deb9aeae..4a4542249 100644
--- a/src/renderer/src/components/right-sidebar/source-control-branch-context-row.test.tsx
+++ b/src/renderer/src/components/right-sidebar/source-control-branch-context-row.test.tsx
@@ -32,10 +32,173 @@ describe('SourceControlBranchContextRow', () => {
/>
)
+ // Display drops refs/remotes/; full ref stays in the title attribute.
+ expect(markup).toContain('origin/FRONT-192-ZisVoucherStrip')
expect(markup).toContain('refs/remotes/origin/FRONT-192-ZisVoucherStrip')
expect(markup).toContain('max-w-full')
expect(markup).toContain('min-w-0 flex-1')
- expect(markup).not.toContain('max-w-[9rem]')
+ })
+
+ it('stacks head above → base so both keep full row width', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ const headIndex = markup.indexOf('fix-fork-pr-fetch-head-race')
+ const arrowIndex = markup.indexOf('→')
+ const baseIndex = markup.indexOf('origin/FRONT-192-ZisVoucherStrip')
+ expect(headIndex).toBeGreaterThan(-1)
+ expect(arrowIndex).toBeGreaterThan(headIndex)
+ expect(baseIndex).toBeGreaterThan(arrowIndex)
+ // Stacked column, not a single-line head→base pair.
+ expect(markup).toContain('flex-col')
+ expect(markup).not.toContain('>vs<')
+ expect(markup).toContain(
+ 'aria-label="fix-fork-pr-fetch-head-race → origin/FRONT-192-ZisVoucherStrip"'
+ )
+ })
+
+ it('falls back to "vs base" when head identity is missing', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toContain('>vs<')
+ expect(markup).toContain('origin/FRONT-192-ZisVoucherStrip')
+ expect(markup).not.toContain('→')
+ })
+
+ it('shows head-only identity when there is no compare base', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toContain('data-testid="source-control-head-identity"')
+ expect(markup).toContain('local-only-branch')
+ expect(markup).toContain('aria-label="Current branch: local-only-branch"')
+ expect(markup).toContain('tabindex="0"')
+ expect(markup).not.toContain('→')
+ expect(markup).not.toContain('>vs<')
+ })
+
+ it('marks the loading path busy and announces comparing', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toContain('aria-busy="true"')
+ expect(markup).toContain('Comparing against')
+ expect(markup).toContain('aria-label="loading-branch → origin/FRONT-192-ZisVoucherStrip"')
+ })
+
+ it('shows detached head-only identity when there is no compare base', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toContain('Detached HEAD · 8cec248')
+ expect(markup).toContain('tabindex="0"')
+ expect(markup).not.toContain('→')
+ expect(markup).not.toContain('>vs<')
+ })
+
+ it('renders nothing when neither base nor head identity is available', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toBe('')
+ })
+
+ it('renders detached HEAD identity above the base with keyboard-reachable badge', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ const headIndex = markup.indexOf('Detached HEAD · 8cec248')
+ const baseIndex = markup.indexOf('origin/FRONT-192-ZisVoucherStrip')
+ expect(headIndex).toBeGreaterThan(-1)
+ expect(baseIndex).toBeGreaterThan(headIndex)
+ expect(markup).toContain(
+ 'aria-label="Detached HEAD at 8cec248. You are viewing a commit, not a branch."'
+ )
+ expect(markup).toContain('tabindex="0"')
+ expect(markup).toContain(
+ 'aria-label="Detached HEAD · 8cec248 → origin/FRONT-192-ZisVoucherStrip"'
+ )
+ })
+
+ it('keeps the head→base label on the error path', () => {
+ const markup = renderToStaticMarkup(
+
+ )
+
+ expect(markup).toContain('role="group"')
+ expect(markup).toContain('aria-label="feature/retry-me → origin/FRONT-192-ZisVoucherStrip"')
+ expect(markup).toContain('Could not compare against base')
+ expect(markup).toContain('Retry')
})
it('renders a compact external review link when a manual URL is available', () => {
diff --git a/src/renderer/src/components/right-sidebar/source-control-branch-context-row.tsx b/src/renderer/src/components/right-sidebar/source-control-branch-context-row.tsx
index 8cd5f078e..2765d6533 100644
--- a/src/renderer/src/components/right-sidebar/source-control-branch-context-row.tsx
+++ b/src/renderer/src/components/right-sidebar/source-control-branch-context-row.tsx
@@ -4,32 +4,40 @@ import type { GitBranchCompareSummary, GitUpstreamStatus } from '../../../../sha
import { cn } from '@/lib/utils'
import { translate } from '@/i18n/i18n'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
+import { DetachedHeadBadge } from '@/components/DetachedHeadBadge'
+import type { WorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import { SourceControlHeaderIconButton } from './source-control-header-icon-button'
import {
buildSourceControlBranchContextStats,
- resolveSourceControlDisplayedBaseRef,
- shouldShowSourceControlBranchContextRow
+ formatSourceControlRefLabel,
+ resolveSourceControlDisplayedBaseRef
} from './source-control-branch-context-stats'
-export { shouldShowSourceControlBranchContextRow } from './source-control-branch-context-stats'
-
function BaseRefButton({
baseRef,
+ displayLabel,
onClick,
title
}: {
baseRef: string
+ displayLabel: string
onClick: () => void
title: string
}): React.JSX.Element {
+ const accessibleName = translate(
+ 'auto.components.right.sidebar.SourceControl.c7d4e2f801',
+ 'Change base ref: {{value0}}',
+ { value0: displayLabel }
+ )
return (
- {baseRef}
+ {displayLabel}
)
}
@@ -41,7 +49,9 @@ function ContextStat({
}): React.JSX.Element {
const className = cn(
'shrink-0 tabular-nums text-muted-foreground',
- stat.tone === 'muted' && 'text-muted-foreground/70'
+ stat.tone === 'muted' && 'text-muted-foreground/70',
+ stat.tone === 'ahead' && 'text-[color:var(--git-decoration-added)]',
+ stat.tone === 'behind' && 'text-[color:var(--git-decoration-deleted)]'
)
if (!stat.title) {
@@ -82,9 +92,179 @@ function ManualReviewLinkButton({
)
}
+function resolveHeadFlowLabel(
+ display: WorktreeGitIdentityDisplay | null | undefined
+): string | null {
+ if (display?.kind === 'branch') {
+ return display.branchName
+ }
+ if (display?.kind === 'detached') {
+ return display.sourceControlLabel
+ }
+ return null
+}
+
+function HeadIdentity({ display }: { display: WorktreeGitIdentityDisplay }): React.JSX.Element {
+ if (display.kind === 'detached') {
+ return (
+
+ )
+ }
+
+ const branchAriaLabel = translate(
+ 'auto.components.right.sidebar.SourceControl.a4e93c21d7',
+ 'Current branch: {{value0}}',
+ { value0: display.branchName }
+ )
+
+ // Why: focusable + tooltip so truncated long branch names stay discoverable.
+ // Native title omitted — Radix Tooltip already surfaces the full name on hover.
+ return (
+
+
+
+ {display.branchName}
+
+
+
+ {display.branchName}
+
+
+ )
+}
+
+function CompareFlowGroup({
+ flowLabel,
+ busy,
+ className,
+ children
+}: {
+ flowLabel: string | undefined
+ busy?: boolean
+ className: string
+ children: React.ReactNode
+}): React.JSX.Element {
+ return (
+
+ {children}
+
+ )
+}
+
+function BaseLine({
+ baseRef,
+ baseLabel,
+ onChangeBaseRef,
+ changeBaseTitle,
+ showArrow,
+ leading,
+ trailing
+}: {
+ baseRef: string
+ baseLabel: string
+ onChangeBaseRef: () => void
+ changeBaseTitle: string
+ showArrow: boolean
+ leading?: React.ReactNode
+ trailing?: React.ReactNode
+}): React.JSX.Element {
+ return (
+
+ {leading}
+ {showArrow ? (
+
+ →
+
+ ) : (
+
+ {translate('auto.components.right.sidebar.SourceControl.e8a1c4b203', 'vs')}
+
+ )}
+
+
+
+ {trailing}
+
+ )
+}
+
+// Why: stacked head / → base (option B) so long branch names fit narrow sidebars
+// without truncating both sides of a single-line head→base pair.
+function StackedCompareFlow({
+ headDisplay,
+ baseRef,
+ baseLabel,
+ onChangeBaseRef,
+ changeBaseTitle,
+ leading,
+ trailing
+}: {
+ headDisplay: WorktreeGitIdentityDisplay | null
+ baseRef: string
+ baseLabel: string
+ onChangeBaseRef: () => void
+ changeBaseTitle: string
+ leading?: React.ReactNode
+ trailing?: React.ReactNode
+}): React.JSX.Element {
+ if (!headDisplay) {
+ return (
+
+ )
+ }
+
+ return (
+
+
+
+
+ {/* Why: spinner/actions sit on the base line — they describe compare state, not HEAD. */}
+
+
+ )
+}
+
export function SourceControlBranchContextRow({
summary,
compareBaseRef,
+ headDisplay = null,
upstreamStatus,
manualReviewUrl,
onChangeBaseRef,
@@ -92,64 +272,100 @@ export function SourceControlBranchContextRow({
}: {
summary: GitBranchCompareSummary | null
compareBaseRef: string | null
+ headDisplay?: WorktreeGitIdentityDisplay | null
upstreamStatus?: GitUpstreamStatus
manualReviewUrl?: string | null
onChangeBaseRef: () => void
onRetry: () => void
}): React.JSX.Element | null {
const displayedBaseRef = resolveSourceControlDisplayedBaseRef(summary, compareBaseRef)
- if (!shouldShowSourceControlBranchContextRow(summary, compareBaseRef) || !displayedBaseRef) {
- return null
+
+ // Why: no base → still show HEAD identity so branch/detached never vanish when
+ // compare isn't configured (replaces the separate identity row from #10215).
+ if (!displayedBaseRef) {
+ if (!headDisplay) {
+ return null
+ }
+ return (
+
+
+
+ )
}
+ const baseLabel = formatSourceControlRefLabel(displayedBaseRef)
const changeBaseTitle = translate(
'auto.components.right.sidebar.SourceControl.493f963029',
'Change base ref'
)
+ const headLabel = resolveHeadFlowLabel(headDisplay)
+ const flowLabel =
+ headLabel != null
+ ? translate(
+ 'auto.components.right.sidebar.SourceControl.b8c2e1a904',
+ '{{value0}} → {{value1}}',
+ { value0: headLabel, value1: baseLabel }
+ )
+ : undefined
if (!summary || summary.status === 'loading') {
return (
-
-
-
- {translate('auto.components.right.sidebar.SourceControl.e8a1c4b203', 'vs')}
+
+ }
+ trailing={ }
+ />
+
+ {translate('auto.components.right.sidebar.SourceControl.11b5dd8e41', 'Comparing against')}
-
-
-
-
-
+
)
}
if (summary.status !== 'ready') {
return (
-
-
-
-
-
+
+
+
+
+ >
+ }
+ />
+ {/* Why: pl-4 under the base line so the error reads as compare state, not HEAD. */}
+
{summary.errorMessage ??
translate(
'auto.components.right.sidebar.SourceControl.715d229c86',
'Branch compare unavailable'
)}
-
-
-
+
)
}
@@ -159,20 +375,8 @@ export function SourceControlBranchContextRow({
upstreamStatus
})
- return (
-
-
-
- {translate('auto.components.right.sidebar.SourceControl.e8a1c4b203', 'vs')}
-
-
-
-
-
+ const trailing = (
+ <>
{stats.length > 0 ? (
{stats.map((stat) => (
@@ -181,6 +385,19 @@ export function SourceControlBranchContextRow({
) : null}
-
+ >
+ )
+
+ return (
+
+
+
)
}
diff --git a/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.test.ts b/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.test.ts
index 77c8cb9ce..be3823e6c 100644
--- a/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.test.ts
+++ b/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.test.ts
@@ -1,7 +1,9 @@
import { describe, expect, it } from 'vitest'
import {
buildSourceControlBranchContextStats,
+ formatSourceControlRefLabel,
resolveSourceControlDisplayedBaseRef,
+ shouldShowSourceControlBranchContextChrome,
shouldShowSourceControlBranchContextRow
} from './source-control-branch-context-stats'
import type { GitBranchCompareSummary } from '../../../../shared/types'
@@ -26,44 +28,110 @@ describe('source-control branch context stats', () => {
expect(resolveSourceControlDisplayedBaseRef(null, null)).toBeNull()
})
- it('shows the row when compare summary or configured base ref exists', () => {
+ it('formats refs for scannable labels without dropping remote qualification', () => {
+ expect(formatSourceControlRefLabel('refs/remotes/origin/main')).toBe('origin/main')
+ expect(formatSourceControlRefLabel('refs/heads/feature/foo')).toBe('feature/foo')
+ expect(formatSourceControlRefLabel('origin/main')).toBe('origin/main')
+ expect(formatSourceControlRefLabel('refs/tags/v1.2.3')).toBe('v1.2.3')
+ })
+
+ it('shows the row only when a displayable base ref exists', () => {
expect(shouldShowSourceControlBranchContextRow(null, null)).toBe(false)
expect(shouldShowSourceControlBranchContextRow(null, 'origin/main')).toBe(true)
expect(
shouldShowSourceControlBranchContextRow({ ...readySummary, status: 'loading' }, null)
).toBe(true)
expect(shouldShowSourceControlBranchContextRow(readySummary, null)).toBe(true)
+ // Summary without a usable base must not claim the row is visible.
+ expect(shouldShowSourceControlBranchContextRow({ ...readySummary, baseRef: ' ' }, null)).toBe(
+ false
+ )
+ expect(shouldShowSourceControlBranchContextRow({ ...readySummary, baseRef: '' }, null)).toBe(
+ false
+ )
})
- it('renders upstream ahead and behind counts', () => {
+ it('shows toolbar chrome when head identity exists even without a base', () => {
+ expect(shouldShowSourceControlBranchContextChrome(null, null, null)).toBe(false)
+ expect(
+ shouldShowSourceControlBranchContextChrome(null, null, {
+ kind: 'branch',
+ branchName: 'local-only'
+ })
+ ).toBe(true)
+ expect(shouldShowSourceControlBranchContextChrome(readySummary, null, null)).toBe(true)
+ })
+
+ it('renders upstream ahead and behind counts against the tracking branch', () => {
const stats = buildSourceControlBranchContextStats({
summary: { ...readySummary, commitsAhead: 0 },
baseRef: 'origin/main',
- upstreamStatus: { hasUpstream: true, ahead: 2, behind: 1 }
+ upstreamStatus: {
+ hasUpstream: true,
+ upstreamName: 'origin/feature',
+ ahead: 2,
+ behind: 1
+ }
})
expect(stats.map((stat) => stat.label)).toEqual(['↑2', '↓1'])
- expect(stats[0]?.title).toBe('2 commits ahead of origin/main')
- expect(stats[1]?.title).toBe('1 commit behind origin/main')
+ expect(stats[0]?.title).toBe('2 commits ahead of origin/feature')
+ expect(stats[1]?.title).toBe('1 commit behind origin/feature')
+ })
+
+ it('shows both upstream and compare ahead when counts match but targets differ', () => {
+ const stats = buildSourceControlBranchContextStats({
+ summary: readySummary,
+ baseRef: 'origin/main',
+ upstreamStatus: {
+ hasUpstream: true,
+ upstreamName: 'origin/feature',
+ ahead: 3,
+ behind: 0
+ }
+ })
+ expect(stats.map((stat) => ({ key: stat.key, label: stat.label, title: stat.title }))).toEqual([
+ {
+ key: 'upstream-ahead',
+ label: '↑3',
+ title: '3 commits ahead of origin/feature'
+ },
+ {
+ key: 'compare-ahead',
+ label: '↑3',
+ title: '3 commits ahead of origin/main'
+ }
+ ])
})
it('shows branch-compare ahead when it differs from upstream ahead', () => {
const stats = buildSourceControlBranchContextStats({
summary: readySummary,
baseRef: 'origin/main',
- upstreamStatus: { hasUpstream: true, ahead: 1, behind: 0 }
+ upstreamStatus: {
+ hasUpstream: true,
+ upstreamName: 'origin/feature',
+ ahead: 1,
+ behind: 0
+ }
})
expect(stats.map((stat) => stat.label)).toEqual(['↑1', '↑3'])
- expect(stats[0]?.title).toBe('1 commit ahead of origin/main')
+ expect(stats[0]?.title).toBe('1 commit ahead of origin/feature')
expect(stats[1]?.title).toBe('3 commits ahead of origin/main')
})
- it('dedupes branch-compare ahead when it matches upstream ahead', () => {
+ it('dedupes branch-compare ahead only when target and count match upstream', () => {
const stats = buildSourceControlBranchContextStats({
summary: { ...readySummary, commitsAhead: 2 },
baseRef: 'origin/main',
- upstreamStatus: { hasUpstream: true, ahead: 2, behind: 0 }
+ upstreamStatus: {
+ hasUpstream: true,
+ upstreamName: 'origin/main',
+ ahead: 2,
+ behind: 0
+ }
})
expect(stats.map((stat) => stat.label)).toEqual(['↑2'])
+ expect(stats[0]?.key).toBe('upstream-ahead')
expect(stats[0]?.title).toBe('2 commits ahead of origin/main')
})
@@ -76,6 +144,23 @@ describe('source-control branch context stats', () => {
expect(stats[0]?.title).toBe('3 commits ahead of origin/main')
})
+ it('formats namespaced base refs in stat titles', () => {
+ const stats = buildSourceControlBranchContextStats({
+ summary: readySummary,
+ baseRef: 'refs/remotes/origin/main'
+ })
+ expect(stats[0]?.title).toBe('3 commits ahead of origin/main')
+ })
+
+ it('falls back to a generic upstream label when upstreamName is missing', () => {
+ const stats = buildSourceControlBranchContextStats({
+ summary: { ...readySummary, commitsAhead: 0 },
+ baseRef: 'origin/main',
+ upstreamStatus: { hasUpstream: true, ahead: 2, behind: 0 }
+ })
+ expect(stats[0]?.title).toBe('2 commits ahead of upstream')
+ })
+
it('returns no stats when branch is even with base', () => {
expect(
buildSourceControlBranchContextStats({
diff --git a/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.ts b/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.ts
index 78aba21f9..238e3d971 100644
--- a/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.ts
+++ b/src/renderer/src/components/right-sidebar/source-control-branch-context-stats.ts
@@ -1,4 +1,5 @@
import type { GitBranchCompareSummary, GitUpstreamStatus } from '../../../../shared/types'
+import type { WorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import { translate } from '@/i18n/i18n'
function formatAheadOfBaseTitle(count: number, baseRef: string): string {
@@ -48,11 +49,41 @@ export function resolveSourceControlDisplayedBaseRef(
return configuredRef || null
}
+// Why: context-row labels should stay scannable — drop git namespace prefixes
+// but keep remote qualification (origin/main) so multi-remote bases stay distinct.
+export function formatSourceControlRefLabel(ref: string): string {
+ return ref
+ .trim()
+ .replace(/^refs\/remotes\//, '')
+ .replace(/^refs\/heads\//, '')
+ .replace(/^refs\/tags\//, '')
+}
+
+// Why: the compare row needs a displayable base; a summary alone with an empty
+// baseRef would still fail the component's displayedBaseRef guard.
export function shouldShowSourceControlBranchContextRow(
summary: GitBranchCompareSummary | null | undefined,
compareBaseRef: string | null | undefined
): boolean {
- return summary != null || resolveSourceControlDisplayedBaseRef(summary, compareBaseRef) != null
+ return resolveSourceControlDisplayedBaseRef(summary, compareBaseRef) != null
+}
+
+// Why: head-only identity still mounts when there is no base, so toolbar chrome
+// visibility is "base OR head" — not base alone.
+export function shouldShowSourceControlBranchContextChrome(
+ summary: GitBranchCompareSummary | null | undefined,
+ compareBaseRef: string | null | undefined,
+ headDisplay: WorktreeGitIdentityDisplay | null | undefined
+): boolean {
+ return shouldShowSourceControlBranchContextRow(summary, compareBaseRef) || headDisplay != null
+}
+
+function resolveUpstreamDisplayLabel(upstreamStatus: GitUpstreamStatus): string {
+ const named = upstreamStatus.upstreamName?.trim()
+ if (named) {
+ return formatSourceControlRefLabel(named)
+ }
+ return translate('auto.components.right.sidebar.SourceControl.f3a1b8c204', 'upstream')
}
export function buildSourceControlBranchContextStats({
@@ -69,13 +100,17 @@ export function buildSourceControlBranchContextStats({
}
const stats: SourceControlBranchContextStat[] = []
+ const baseLabel = formatSourceControlRefLabel(baseRef)
+ const hasUpstream = Boolean(upstreamStatus?.hasUpstream)
+ const upstreamLabel =
+ hasUpstream && upstreamStatus ? resolveUpstreamDisplayLabel(upstreamStatus) : null
- if (upstreamStatus?.hasUpstream) {
+ if (hasUpstream && upstreamStatus && upstreamLabel != null) {
if (upstreamStatus.ahead > 0) {
stats.push({
key: 'upstream-ahead',
label: `↑${upstreamStatus.ahead}`,
- title: formatAheadOfBaseTitle(upstreamStatus.ahead, baseRef),
+ title: formatAheadOfBaseTitle(upstreamStatus.ahead, upstreamLabel),
tone: 'ahead'
})
}
@@ -83,7 +118,7 @@ export function buildSourceControlBranchContextStats({
stats.push({
key: 'upstream-behind',
label: `↓${upstreamStatus.behind}`,
- title: formatBehindBaseTitle(upstreamStatus.behind, baseRef),
+ title: formatBehindBaseTitle(upstreamStatus.behind, upstreamLabel),
tone: 'behind'
})
}
@@ -91,12 +126,19 @@ export function buildSourceControlBranchContextStats({
const commitsAhead = summary.commitsAhead
if (typeof commitsAhead === 'number' && commitsAhead > 0) {
- const upstreamAhead = upstreamStatus?.hasUpstream ? upstreamStatus.ahead : 0
- if (commitsAhead !== upstreamAhead) {
+ // Why: only collapse compare-ahead into upstream-ahead when both describe the
+ // same ref and count — equal numbers against different targets must both show.
+ const sameTargetAsUpstream =
+ hasUpstream &&
+ upstreamStatus != null &&
+ upstreamLabel != null &&
+ upstreamLabel === baseLabel &&
+ commitsAhead === upstreamStatus.ahead
+ if (!sameTargetAsUpstream) {
stats.push({
key: 'compare-ahead',
label: `↑${commitsAhead}`,
- title: formatAheadOfBaseTitle(commitsAhead, baseRef),
+ title: formatAheadOfBaseTitle(commitsAhead, baseLabel),
tone: 'ahead'
})
}
diff --git a/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx b/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx
index a70397959..a58958bf0 100644
--- a/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx
+++ b/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx
@@ -1,9 +1,10 @@
import { renderToStaticMarkup } from 'react-dom/server'
import type { ReactNode } from 'react'
import { describe, expect, it, vi } from 'vitest'
+import { SourceControlHeaderToolbar } from './source-control-header-toolbar'
+import type { GitBranchCompareSummary } from '../../../../shared/types'
import type { WorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import type { PrimaryAction } from './source-control-primary-action'
-import { SourceControlHeaderToolbar } from './source-control-header-toolbar'
vi.mock('@/components/ui/tooltip', () => ({
Tooltip: ({ children }: { children: ReactNode }) => <>{children}>,
@@ -15,11 +16,6 @@ vi.mock('./source-control-header-overflow-menu', () => ({
SourceControlHeaderOverflowMenu: () => More actions
}))
-vi.mock('./source-control-branch-context-row', () => ({
- shouldShowSourceControlBranchContextRow: () => false,
- SourceControlBranchContextRow: () => null
-}))
-
const CREATE_PR_ACTION: PrimaryAction = {
kind: 'create_pr',
label: 'Create PR',
@@ -27,27 +23,29 @@ const CREATE_PR_ACTION: PrimaryAction = {
disabled: false
}
-function renderToolbar(
- overrides: {
- gitIdentityDisplay?: WorktreeGitIdentityDisplay | null
- createPrAction?: PrimaryAction | null
- } = {}
-): string {
- const gitIdentityDisplay =
- overrides.gitIdentityDisplay === undefined
- ? ({ kind: 'branch', branchName: 'brennanb2025/source-control-branch-name' } as const)
- : overrides.gitIdentityDisplay
- const createPrAction =
- overrides.createPrAction === undefined ? CREATE_PR_ACTION : overrides.createPrAction
+const readySummary: GitBranchCompareSummary = {
+ baseRef: 'origin/main',
+ baseOid: 'base',
+ compareRef: 'feature',
+ headOid: 'head',
+ mergeBase: 'base',
+ changedFiles: 0,
+ commitsAhead: 1,
+ status: 'ready'
+}
+function renderToolbar(options?: {
+ headDisplay?: WorktreeGitIdentityDisplay | null
+ branchSummary?: GitBranchCompareSummary | null
+ compareBaseRef?: string | null
+}): string {
return renderToStaticMarkup(
)
}
describe('SourceControlHeaderToolbar branch identity', () => {
- it('keeps the Create PR button while showing the branch identity above it', () => {
+ it('keeps Create PR while stacking head above base in the context row', () => {
const markup = renderToolbar()
const branchIndex = markup.indexOf('brennanb2025/source-control-branch-name')
const createPrIndex = markup.indexOf('Create PR')
- // Why: the #9787 revert regression — identity must not evict Create PR.
- expect(markup).toContain('data-testid="source-control-git-identity-row"')
+ // Why: the #9787 regression — identity must not evict Create PR.
expect(branchIndex).toBeGreaterThan(-1)
expect(createPrIndex).toBeGreaterThan(-1)
- // Identity row renders above the toolbar row that hosts Create PR.
- expect(branchIndex).toBeLessThan(createPrIndex)
+ expect(markup).toContain('aria-label="brennanb2025/source-control-branch-name → origin/main"')
expect(markup).toContain('aria-label="Current branch: brennanb2025/source-control-branch-name"')
- expect(markup).toContain('min-w-0 truncate')
+ expect(markup).toContain('data-testid="source-control-head-identity"')
})
- it('renders detached HEAD identity alongside the Create PR button', () => {
+ it('shows head-only identity with Create PR when no compare base is configured', () => {
const markup = renderToolbar({
- gitIdentityDisplay: {
+ branchSummary: null,
+ compareBaseRef: null,
+ headDisplay: { kind: 'branch', branchName: 'local-only-branch' }
+ })
+
+ expect(markup).toContain('Create PR')
+ expect(markup).toContain('data-testid="source-control-head-identity"')
+ expect(markup).toContain('local-only-branch')
+ expect(markup).not.toContain('→')
+ })
+
+ it('renders detached HEAD with Create PR when compare base is present', () => {
+ const markup = renderToolbar({
+ headDisplay: {
kind: 'detached',
shortHead: '8cec248',
sidebarLabel: 'Detached HEAD @ 8cec248',
@@ -94,22 +108,21 @@ describe('SourceControlHeaderToolbar branch identity', () => {
}
})
- expect(markup).not.toContain('aria-label="Current branch:')
- expect(markup).toContain('data-testid="source-control-git-identity-row"')
expect(markup).toContain('Detached HEAD · 8cec248')
- // Detached badge stays keyboard-reachable and exposes the full tooltip as its label.
- expect(markup).toContain(
- 'aria-label="Detached HEAD at 8cec248. You are viewing a commit, not a branch."'
- )
expect(markup).toContain('tabindex="0"')
expect(markup).toContain('Create PR')
+ expect(markup).toContain('aria-label="Detached HEAD · 8cec248 → origin/main"')
})
- it('omits the identity row when there is no git identity', () => {
- const markup = renderToolbar({ gitIdentityDisplay: null })
+ it('omits identity chrome when there is no git identity and no base', () => {
+ const markup = renderToolbar({
+ headDisplay: null,
+ branchSummary: null,
+ compareBaseRef: null
+ })
- expect(markup).not.toContain('data-testid="source-control-git-identity-row"')
- expect(markup).not.toContain('aria-label="Current branch:')
+ expect(markup).not.toContain('data-testid="source-control-head-identity"')
+ expect(markup).not.toContain('→')
expect(markup).toContain('Create PR')
})
})
diff --git a/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx b/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx
index d56d56b0c..f6bf15c87 100644
--- a/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx
+++ b/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useRef } from 'react'
-import { GitBranch, GitPullRequestArrow, Loader2, Search, X } from 'lucide-react'
+import { GitPullRequestArrow, Loader2, Search, X } from 'lucide-react'
import type {
GitBranchCompareSummary,
GitUpstreamStatus,
@@ -11,17 +11,13 @@ import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { cn } from '@/lib/utils'
import { translate } from '@/i18n/i18n'
-import { DetachedHeadBadge } from '@/components/DetachedHeadBadge'
import type { WorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import { HostedReviewHeaderLink, HostedReviewIcon } from './hosted-review-header-chrome'
-import {
- shouldShowSourceControlBranchContextRow,
- SourceControlBranchContextRow
-} from './source-control-branch-context-row'
+import { SourceControlBranchContextRow } from './source-control-branch-context-row'
+import { shouldShowSourceControlBranchContextChrome } from './source-control-branch-context-stats'
import { SourceControlHeaderOverflowMenu } from './source-control-header-overflow-menu'
type SourceControlHeaderToolbarProps = {
- gitIdentityDisplay: WorktreeGitIdentityDisplay | null
filterQuery: string
filterExpanded: boolean
onFilterQueryChange: (value: string) => void
@@ -42,60 +38,11 @@ type SourceControlHeaderToolbarProps = {
onExpandNotes: () => void
branchSummary: GitBranchCompareSummary | null
compareBaseRef: string | null
+ headDisplay?: WorktreeGitIdentityDisplay | null
upstreamStatus?: GitUpstreamStatus
manualReviewUrl?: string | null
}
-// Why: its own row above the toolbar so branch identity coexists with the Create PR
-// button instead of competing for the single toolbar slot (#9787 restore).
-function SourceControlGitIdentityRow({
- display
-}: {
- display: WorktreeGitIdentityDisplay
-}): React.JSX.Element {
- if (display.kind === 'detached') {
- return (
-
-
-
- )
- }
-
- const branchName = display.branchName
- const label = translate(
- 'auto.components.right.sidebar.SourceControl.a4e93c21d7',
- 'Current branch: {{value0}}',
- { value0: branchName }
- )
-
- return (
-
-
-
-
-
- {/* Why: match the 'vs main' base-ref typography (font/size/color) but no
- underline — this label isn't clickable, so the underline would mislead. */}
- {branchName}
-
-
-
- {branchName}
-
-
-
- )
-}
-
function HostedReviewToolbarLink({
review,
onOpenHostedReviewInChecks,
@@ -177,7 +124,6 @@ function renderOverflowMenu(
}
export function SourceControlHeaderToolbar({
- gitIdentityDisplay,
filterQuery,
filterExpanded,
onFilterQueryChange,
@@ -198,6 +144,7 @@ export function SourceControlHeaderToolbar({
onExpandNotes,
branchSummary,
compareBaseRef,
+ headDisplay = null,
upstreamStatus,
manualReviewUrl
}: SourceControlHeaderToolbarProps): React.JSX.Element {
@@ -244,7 +191,6 @@ export function SourceControlHeaderToolbar({
return (
- {gitIdentityDisplay ?
: null}
- {shouldShowSourceControlBranchContextRow(branchSummary, compareBaseRef) ? (
+ {shouldShowSourceControlBranchContextChrome(branchSummary, compareBaseRef, headDisplay) ? (