mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(session): show the workspace branch in the session detail header
Resolve the branch from the repo's siblings so a session running in a worktree shows that worktree's branch, falling back to the repo branch and staying empty when no branch is resolvable. Desktop renders a branch chip in the header; mobile appends it to the repo name in the subtitle.
This commit is contained in:
1 parent
4e8051b75a
commit
f5d073d7ee
8 files changed
+105
-2
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
hasUnmatchedActiveDirectory,
|
||||
needsWorktreeLookup,
|
||||
repoActivityFromIndex,
|
||||
resolveSessionBranch,
|
||||
rootSessionID,
|
||||
type ActiveWorktree,
|
||||
} from './activeWork'
|
||||
@@ -611,3 +612,41 @@ describe('buildWorktreeActivity', () => {
|
||||
expect(buildWorktreeActivity([main], [{ data: [main] }])).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveSessionBranch', () => {
|
||||
it('returns the matching worktree sibling branch, tolerating a trailing slash', () => {
|
||||
const main = createRepo({ id: 1, fullPath: '/repos/a', currentBranch: 'main' })
|
||||
const worktree = createWorktreeSibling(-1, '/repos/a/.worktrees/feature', 'feature', 'opencode')
|
||||
|
||||
expect(resolveSessionBranch(main, '/repos/a/.worktrees/feature', [main, worktree])).toBe('feature')
|
||||
expect(resolveSessionBranch(main, '/repos/a/.worktrees/feature/', [main, worktree])).toBe('feature')
|
||||
})
|
||||
|
||||
it('returns the branch of a registered worktree repo row without a worktree source', () => {
|
||||
const main = createRepo({ id: 1, fullPath: '/repos/a', currentBranch: 'main' })
|
||||
const registered = createRepo({ id: 2, fullPath: '/repos/a-feature', isWorktree: true, currentBranch: 'feature' })
|
||||
|
||||
expect(resolveSessionBranch(main, '/repos/a-feature', [main, registered])).toBe('feature')
|
||||
})
|
||||
|
||||
it('returns null for a matching sibling with no branch instead of the repo branch', () => {
|
||||
const main = createRepo({ id: 1, fullPath: '/repos/a', currentBranch: 'main' })
|
||||
const detached = createRepo({ id: 2, fullPath: '/repos/a-detached', isWorktree: true })
|
||||
|
||||
expect(resolveSessionBranch(main, '/repos/a-detached', [main, detached])).toBeNull()
|
||||
})
|
||||
|
||||
it('falls back to the repo branch when no sibling matches', () => {
|
||||
const current = createRepo({ id: 1, fullPath: '/repos/a', currentBranch: 'main' })
|
||||
const legacy = createRepo({ id: 1, fullPath: '/repos/a', branch: 'develop' })
|
||||
|
||||
expect(resolveSessionBranch(current, '/repos/other', [current])).toBe('main')
|
||||
expect(resolveSessionBranch(legacy, '/repos/other', [legacy])).toBe('develop')
|
||||
})
|
||||
|
||||
it('returns the repo branch when siblings are undefined', () => {
|
||||
const main = createRepo({ id: 1, fullPath: '/repos/a', currentBranch: 'main' })
|
||||
|
||||
expect(resolveSessionBranch(main, '/repos/a', undefined)).toBe('main')
|
||||
})
|
||||
})
|
||||
@@ -3,6 +3,7 @@ import type { ChildOutcome } from '@/lib/backgroundWork'
|
||||
import type { SessionStatusType } from '@/stores/sessionStatusStore'
|
||||
import { getSessionKey } from '@/lib/sessionKey'
|
||||
import { getSessionPath } from '@/lib/navigation'
|
||||
import { getRepoBranchLabel } from '@/lib/utils'
|
||||
import { findRepoForDirectory, normalizeDirectory } from '@/components/navigation/sidebar-session-tree'
|
||||
import { isWorktreeSibling, type RepoSibling } from '@opencode-manager/shared/utils'
|
||||
|
||||
@@ -259,6 +260,23 @@ export function buildWorktreeActivity(
|
||||
return worktrees
|
||||
}
|
||||
|
||||
/**
|
||||
* The branch of the workspace a session runs in: the matching sibling's branch when the session
|
||||
* directory is one of the repo's siblings (a worktree), otherwise the repo's own branch.
|
||||
*/
|
||||
export function resolveSessionBranch(
|
||||
repo: Pick<Repo, 'currentBranch' | 'branch'>,
|
||||
directory: string | null | undefined,
|
||||
siblings?: ReadonlyArray<RepoSibling>,
|
||||
): string | null {
|
||||
const normalized = normalizeDirectory(directory)
|
||||
const sibling = normalized
|
||||
? siblings?.find((entry) => normalizeDirectory(entry.fullPath) === normalized)
|
||||
: undefined
|
||||
if (!sibling) return getRepoBranchLabel(repo)
|
||||
return sibling.currentBranch ?? sibling.branch ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the worktree lookup is worth running: true when some non-archived session that matches no
|
||||
* repo is either updated inside the window or has its root active (needs-input or running).
|
||||
|
||||
Reference in new issue
Block a user