+
{row.label}
diff --git a/src/renderer/src/components/sidebar/smart-sort.test.ts b/src/renderer/src/components/sidebar/smart-sort.test.ts
index 1cd2ff9f3..2793cd58d 100644
--- a/src/renderer/src/components/sidebar/smart-sort.test.ts
+++ b/src/renderer/src/components/sidebar/smart-sort.test.ts
@@ -32,6 +32,7 @@ function makeWorktree(overrides: Partial = {}): Worktree {
isArchived: overrides.isArchived ?? false,
comment: overrides.comment ?? '',
isUnread: overrides.isUnread ?? false,
+ isPinned: overrides.isPinned ?? false,
displayName: overrides.displayName ?? overrides.id ?? 'wt-1',
sortOrder: overrides.sortOrder ?? 0,
lastActivityAt: overrides.lastActivityAt ?? 0
diff --git a/src/renderer/src/components/sidebar/visible-worktrees.test.ts b/src/renderer/src/components/sidebar/visible-worktrees.test.ts
index 63778e525..15a26edcf 100644
--- a/src/renderer/src/components/sidebar/visible-worktrees.test.ts
+++ b/src/renderer/src/components/sidebar/visible-worktrees.test.ts
@@ -17,6 +17,7 @@ function makeWorktree(id: string, repoId = 'repo1'): Worktree {
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0
}
diff --git a/src/renderer/src/components/sidebar/worktree-list-groups.test.ts b/src/renderer/src/components/sidebar/worktree-list-groups.test.ts
index 1103c02fa..641edcf82 100644
--- a/src/renderer/src/components/sidebar/worktree-list-groups.test.ts
+++ b/src/renderer/src/components/sidebar/worktree-list-groups.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { getPRGroupKey, matchesSearch } from './worktree-list-groups'
+import { buildRows, getPRGroupKey, matchesSearch } from './worktree-list-groups'
import type { Repo, Worktree } from '../../../../shared/types'
const repo: Repo = {
@@ -23,6 +23,7 @@ const worktree: Worktree = {
isArchived: false,
comment: '',
isUnread: false,
+ isPinned: false,
displayName: 'feature/super-critical',
sortOrder: 0,
lastActivityAt: 0
@@ -147,3 +148,52 @@ describe('matchesSearch', () => {
expect(matchesSearch(w, '#', repoMap, prCache, null)).toBe(false)
})
})
+
+describe('buildRows with pinned worktrees', () => {
+ const pinned = { ...worktree, id: 'wt-pinned', isPinned: true, displayName: 'pinned-feature' }
+ const unpinned1 = { ...worktree, id: 'wt-1', displayName: 'alpha' }
+ const unpinned2 = { ...worktree, id: 'wt-2', displayName: 'beta' }
+
+ it('emits a Pinned header followed by pinned items in groupBy none', () => {
+ const rows = buildRows('none', [unpinned1, pinned, unpinned2], repoMap, null, new Set())
+ expect(rows[0]).toMatchObject({ type: 'header', key: 'pinned', label: 'Pinned', count: 1 })
+ expect(rows[1]).toMatchObject({ type: 'item', worktree: { id: 'wt-pinned' } })
+ })
+
+ it('emits a separator between pinned and unpinned in groupBy none', () => {
+ const rows = buildRows('none', [unpinned1, pinned, unpinned2], repoMap, null, new Set())
+ expect(rows[2]).toMatchObject({ type: 'separator', key: 'sep:pinned' })
+ expect(rows[3]).toMatchObject({ type: 'item', worktree: { id: 'wt-1' } })
+ expect(rows[4]).toMatchObject({ type: 'item', worktree: { id: 'wt-2' } })
+ })
+
+ it('excludes pinned items from regular groups in pr-status mode', () => {
+ const rows = buildRows('pr-status', [unpinned1, pinned], repoMap, null, new Set())
+ const pinnedHeader = rows.find((r) => r.type === 'header' && r.key === 'pinned')
+ expect(pinnedHeader).toBeDefined()
+ const prGroup = rows.filter((r) => r.type === 'header' && r.key.startsWith('pr:'))
+ for (const header of prGroup) {
+ if (header.type === 'header') {
+ expect(header.count).toBe(1)
+ }
+ }
+ })
+
+ it('does not emit pinned section when no worktrees are pinned', () => {
+ const rows = buildRows('none', [unpinned1, unpinned2], repoMap, null, new Set())
+ expect(rows.every((r) => r.type === 'item')).toBe(true)
+ })
+
+ it('collapses pinned group when in collapsedGroups', () => {
+ const rows = buildRows('none', [pinned, unpinned1], repoMap, null, new Set(['pinned']))
+ expect(rows[0]).toMatchObject({ type: 'header', key: 'pinned' })
+ expect(rows[1]).toMatchObject({ type: 'separator' })
+ expect(rows[2]).toMatchObject({ type: 'item', worktree: { id: 'wt-1' } })
+ })
+
+ it('does not emit separator when all worktrees are pinned', () => {
+ const allPinned = { ...unpinned1, isPinned: true }
+ const rows = buildRows('none', [pinned, allPinned], repoMap, null, new Set())
+ expect(rows.some((r) => r.type === 'separator')).toBe(false)
+ })
+})
diff --git a/src/renderer/src/components/sidebar/worktree-list-groups.ts b/src/renderer/src/components/sidebar/worktree-list-groups.ts
index 3d3aec428..d520ccb22 100644
--- a/src/renderer/src/components/sidebar/worktree-list-groups.ts
+++ b/src/renderer/src/components/sidebar/worktree-list-groups.ts
@@ -11,12 +11,13 @@ export type GroupHeaderRow = {
label: string
count: number
tone: string
- icon: React.ComponentType<{ className?: string }>
+ icon?: React.ComponentType<{ className?: string }>
repo?: Repo
}
+export type SeparatorRow = { type: 'separator'; key: string }
export type WorktreeRow = { type: 'item'; worktree: Worktree; repo: Repo | undefined }
-export type Row = GroupHeaderRow | WorktreeRow
+export type Row = GroupHeaderRow | SeparatorRow | WorktreeRow
export type PRGroupKey = 'done' | 'in-review' | 'in-progress' | 'closed'
@@ -57,6 +58,13 @@ export const REPO_GROUP_META = {
icon: FolderGit2
} as const
+export const PINNED_GROUP_KEY = 'pinned'
+
+export const PINNED_GROUP_META = {
+ label: 'Pinned',
+ tone: 'text-muted-foreground'
+} as const
+
export function getPRGroupKey(
worktree: Worktree,
repoMap: Map,
@@ -86,6 +94,36 @@ export function getPRGroupKey(
return 'in-review'
}
+/**
+ * Emit a "Pinned" header + its items into `result`, returning the set of
+ * pinned worktree IDs so the caller can exclude them from regular groups.
+ */
+function emitPinnedGroup(
+ worktrees: Worktree[],
+ repoMap: Map,
+ collapsedGroups: Set,
+ result: Row[]
+): Set {
+ const pinned = worktrees.filter((w) => w.isPinned)
+ if (pinned.length === 0) {
+ return new Set()
+ }
+
+ result.push({
+ type: 'header',
+ key: PINNED_GROUP_KEY,
+ label: PINNED_GROUP_META.label,
+ count: pinned.length,
+ tone: PINNED_GROUP_META.tone
+ })
+ if (!collapsedGroups.has(PINNED_GROUP_KEY)) {
+ for (const w of pinned) {
+ result.push({ type: 'item', worktree: w, repo: repoMap.get(w.repoId) })
+ }
+ }
+ return new Set(pinned.map((w) => w.id))
+}
+
/**
* Build the flat row list consumed by the virtualizer.
* Extracted here to keep WorktreeList.tsx under the line-count lint limit.
@@ -99,15 +137,21 @@ export function buildRows(
): Row[] {
const result: Row[] = []
+ const pinnedIds = emitPinnedGroup(worktrees, repoMap, collapsedGroups, result)
+ const unpinned = pinnedIds.size > 0 ? worktrees.filter((w) => !pinnedIds.has(w.id)) : worktrees
+
if (groupBy === 'none') {
- for (const w of worktrees) {
+ if (pinnedIds.size > 0 && unpinned.length > 0) {
+ result.push({ type: 'separator', key: 'sep:pinned' })
+ }
+ for (const w of unpinned) {
result.push({ type: 'item', worktree: w, repo: repoMap.get(w.repoId) })
}
return result
}
const grouped = new Map()
- for (const w of worktrees) {
+ for (const w of unpinned) {
let key: string
let label: string
let repo: Repo | undefined
diff --git a/src/renderer/src/lib/worktree-palette-search.test.ts b/src/renderer/src/lib/worktree-palette-search.test.ts
index 5de8af258..cbd379fb4 100644
--- a/src/renderer/src/lib/worktree-palette-search.test.ts
+++ b/src/renderer/src/lib/worktree-palette-search.test.ts
@@ -17,6 +17,7 @@ function makeWorktree(overrides: Partial = {}): Worktree {
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0,
...overrides
diff --git a/src/renderer/src/store/slices/store-session-cascades.test.ts b/src/renderer/src/store/slices/store-session-cascades.test.ts
index bf2ab59f8..360c3e57c 100644
--- a/src/renderer/src/store/slices/store-session-cascades.test.ts
+++ b/src/renderer/src/store/slices/store-session-cascades.test.ts
@@ -133,6 +133,7 @@ function makeWorktree(overrides: Partial & { id: string; repoId: strin
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0,
...overrides
diff --git a/src/renderer/src/store/slices/store-test-helpers.ts b/src/renderer/src/store/slices/store-test-helpers.ts
index c43519a64..012b1d3d0 100644
--- a/src/renderer/src/store/slices/store-test-helpers.ts
+++ b/src/renderer/src/store/slices/store-test-helpers.ts
@@ -78,6 +78,7 @@ export function makeWorktree(
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0,
...overrides
diff --git a/src/renderer/src/store/slices/tabs.test.ts b/src/renderer/src/store/slices/tabs.test.ts
index f60740074..71ac283ae 100644
--- a/src/renderer/src/store/slices/tabs.test.ts
+++ b/src/renderer/src/store/slices/tabs.test.ts
@@ -561,6 +561,7 @@ describe('TabsSlice', () => {
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0
}
@@ -652,6 +653,7 @@ describe('TabsSlice', () => {
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0
}
diff --git a/src/renderer/src/store/slices/worktrees.test.ts b/src/renderer/src/store/slices/worktrees.test.ts
index 9d061e540..94fc7432f 100644
--- a/src/renderer/src/store/slices/worktrees.test.ts
+++ b/src/renderer/src/store/slices/worktrees.test.ts
@@ -75,6 +75,7 @@ function makeWorktree(overrides: Partial & { id: string; repoId: strin
linkedPR: null,
isArchived: false,
isUnread: false,
+ isPinned: false,
sortOrder: 0,
lastActivityAt: 0,
...overrides
diff --git a/src/renderer/src/store/slices/worktrees.ts b/src/renderer/src/store/slices/worktrees.ts
index a19a655c1..83facccf5 100644
--- a/src/renderer/src/store/slices/worktrees.ts
+++ b/src/renderer/src/store/slices/worktrees.ts
@@ -31,6 +31,7 @@ function areWorktreesEqual(current: Worktree[] | undefined, next: Worktree[]): b
worktree.linkedPR === candidate.linkedPR &&
worktree.isArchived === candidate.isArchived &&
worktree.isUnread === candidate.isUnread &&
+ worktree.isPinned === candidate.isPinned &&
worktree.sortOrder === candidate.sortOrder &&
worktree.lastActivityAt === candidate.lastActivityAt
)
diff --git a/src/shared/types.ts b/src/shared/types.ts
index a6349bc25..d9800d2bc 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -42,6 +42,7 @@ export type Worktree = {
linkedPR: number | null
isArchived: boolean
isUnread: boolean
+ isPinned: boolean
sortOrder: number
lastActivityAt: number
} & GitWorktreeInfo
@@ -54,6 +55,7 @@ export type WorktreeMeta = {
linkedPR: number | null
isArchived: boolean
isUnread: boolean
+ isPinned: boolean
sortOrder: number
lastActivityAt: number
}