Repository navigation
fix(sidebar): "Hide default branch" hides a folder project's root workspace #22744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
167c011
c264f51
ccb89f8
705cde2
fda8eff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { LOCAL_EXECUTION_HOST_ID } from '../../../../shared/execution-host' | ||
| import type { Repo } from '../../../../shared/repo-types' | ||
| import type { Worktree } from '../../../../shared/worktree/types' | ||
| import { isDefaultBranchWorkspace } from './default-branch-workspace' | ||
| import { computeVisibleWorktreeIds } from './visible-worktrees' | ||
|
|
||
| function makeRepo(id: string, path: string, kind: Repo['kind']): Repo { | ||
| return { id, path, displayName: id, badgeColor: '#000', addedAt: 0, kind } | ||
| } | ||
|
|
||
| function makeRow(repo: Repo, overrides: Partial<Worktree> & { id: string }): Worktree { | ||
| return { | ||
| repoId: repo.id, | ||
| path: repo.path, | ||
| head: 'abc123', | ||
| branch: 'refs/heads/main', | ||
| isBare: false, | ||
| isMainWorktree: true, | ||
| displayName: repo.id, | ||
| comment: '', | ||
| linkedIssue: null, | ||
| linkedPR: null, | ||
| linkedLinearIssue: null, | ||
| isArchived: false, | ||
| isUnread: false, | ||
| isPinned: false, | ||
| sortOrder: 0, | ||
| lastActivityAt: 0, | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| // Mirrors mergeFolderWorkspace: every row of a folder project has no head or branch, | ||
| // and only the root (id `${repoId}::${path}`) is the main worktree. | ||
| function folderProjectRows(repo: Repo): { root: Worktree; instance: Worktree } { | ||
| const rootId = `${repo.id}::${repo.path}` | ||
| return { | ||
| root: makeRow(repo, { id: rootId, head: '', branch: '' }), | ||
| instance: makeRow(repo, { | ||
| id: `${rootId}::workspace:task-1`, | ||
| head: '', | ||
| branch: '', | ||
| isMainWorktree: false | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| function visibleWithHideDefault(repos: Repo[], worktrees: Worktree[]): string[] { | ||
| const worktreesByRepo: Record<string, Worktree[]> = {} | ||
| for (const worktree of worktrees) { | ||
| ;(worktreesByRepo[worktree.repoId] ??= []).push(worktree) | ||
| } | ||
| return computeVisibleWorktreeIds( | ||
| worktreesByRepo, | ||
| worktrees.map((worktree) => worktree.id), | ||
| { | ||
| filterRepoIds: [], | ||
| showSleepingWorkspaces: true, | ||
| tabsByWorktree: {}, | ||
| ptyIdsByTabId: {}, | ||
| browserTabsByWorktree: {}, | ||
| worktreeIdsWithLiveAgent: new Set(), | ||
| hideDefaultBranchWorkspace: true, | ||
| hideAutomationGeneratedWorkspaces: false, | ||
| hideCliCreatedWorkspaces: false, | ||
| hideDetachedHeadWorkspaces: false, | ||
| hideWorkspacesFromOtherDevices: false, | ||
| pairedDeviceIdsByEnvironment: new Map(), | ||
| repoMap: new Map(repos.map((repo) => [repo.id, repo])), | ||
| workspaceHostScope: 'all', | ||
| defaultHostId: LOCAL_EXECUTION_HOST_ID, | ||
| worktreeLineageById: {} | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| describe('"Hide default branch" on folder projects', () => { | ||
| it('hides the root of a non-git folder project and keeps its other workspaces', () => { | ||
| const repo = makeRepo('notes', '/Users/me/notes', 'folder') | ||
| const { root, instance } = folderProjectRows(repo) | ||
|
|
||
| expect(isDefaultBranchWorkspace(root, repo)).toBe(true) | ||
| expect(isDefaultBranchWorkspace(instance, repo)).toBe(false) | ||
| expect(visibleWithHideDefault([repo], [root, instance])).toEqual([instance.id]) | ||
| }) | ||
|
|
||
| it('hides the root of a folder project added from a git subdirectory', () => { | ||
| const repo = makeRepo('app', '/Users/me/monorepo/packages/app', 'folder') | ||
| const { root, instance } = folderProjectRows(repo) | ||
|
|
||
| expect(visibleWithHideDefault([repo], [root, instance])).toEqual([instance.id]) | ||
| }) | ||
|
|
||
| it('keeps an empty-branch git main visible: detached HEAD, or an SSH row synthesized offline', () => { | ||
| const repo = makeRepo('repo', '/code/repo', 'git') | ||
| const remoteRepo = makeRepo('remote', '/srv/remote', 'git') | ||
| const detached = makeRow(repo, { id: 'repo::/code/repo', branch: '' }) | ||
| const sshOffline = makeRow(remoteRepo, { id: 'remote::/srv/remote', branch: '', head: '' }) | ||
|
|
||
| expect(isDefaultBranchWorkspace(detached, repo)).toBe(false) | ||
| expect(isDefaultBranchWorkspace(sshOffline, remoteRepo)).toBe(false) | ||
| expect(visibleWithHideDefault([repo, remoteRepo], [detached, sshOffline])).toEqual([ | ||
| detached.id, | ||
| sshOffline.id | ||
| ]) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| import { isFolderRepo } from '../../../../shared/repo-kind' | ||
| import type { Repo } from '../../../../shared/repo-types' | ||
| import type { Worktree } from '../../../../shared/worktree/types' | ||
|
|
||
| /** Keeps provisioned roots visible because they are the recipe-created workspace, not a source-repo row. */ | ||
| export function isDefaultBranchWorkspace(worktree: Worktree): boolean { | ||
| return ( | ||
| worktree.isMainWorktree && | ||
| worktree.branch.trim() !== '' && | ||
| worktree.ephemeralVmCheckoutMode !== 'provisioned-root' | ||
| ) | ||
| export function isDefaultBranchWorkspace( | ||
| worktree: Worktree, | ||
| repo: Pick<Repo, 'kind'> | undefined | ||
| ): boolean { | ||
| if (!worktree.isMainWorktree || worktree.ephemeralVmCheckoutMode === 'provisioned-root') { | ||
| return false | ||
| } | ||
| // Why: a folder project's root is its default workspace but has no branch; on a git repo an | ||
| // empty branch means detached HEAD or an offline SSH row, which stay visible. | ||
| return worktree.branch.trim() !== '' || (repo !== undefined && isFolderRepo(repo)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,10 +56,10 @@ import { getWorktreeHostIdentity } from '../../../../shared/worktree/host-qualif | |
| * Whether the "Hide sleeping" sweep must keep this row (#8873). | ||
| * | ||
| * Why isMainWorktree and not isDefaultBranchWorkspace: the project's primary | ||
| * checkout is the repo's only guaranteed entry point. Folder workspaces and | ||
| * detached-HEAD mains fail the default-branch predicate yet often have no | ||
| * sibling row at all, so sweeping them drops the entire project out of the | ||
| * sidebar, Cmd+J and the board with no way back except changing a filter. | ||
| * checkout is the repo's only guaranteed entry point. Detached-HEAD and offline | ||
| * SSH mains fail the default-branch predicate yet often have no sibling row at | ||
| * all, so sweeping them drops the entire project out of the sidebar, Cmd+J and | ||
| * the board with no way back except changing a filter. | ||
| * | ||
| * Why shared: the sidebar pipeline and the jump palette both apply this, and a | ||
| * second copy is how the two surfaces drift. | ||
|
|
@@ -109,7 +109,7 @@ export function computeVisibleWorktrees( | |
| } | ||
|
|
||
| if (opts.hideDefaultBranchWorkspace) { | ||
| all = all.filter((w) => !isDefaultBranchWorkspace(w)) | ||
| all = all.filter((w) => !isDefaultBranchWorkspace(w, opts.repoMap.get(w.repoId))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Inspect folder-row creation and the lineage rules used by the visibility pass.
rg -n -C 3 'mergeFolderWorkspace|parentWorktreeId|worktreeLineageById' src/renderer/src/components/sidebar -g '*.ts'
rg -n -C 4 'getLineageAncestorIndex|getLineageRenderInfo|addVisibleLineageAncestors' src/renderer/src/components/sidebar/visible-worktrees.tsRepository: stablyai/orca Length of output: 41412 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- visible-worktrees.ts ---'
sed -n '80,225p' src/renderer/src/components/sidebar/visible-worktrees.ts
printf '%s\n' '--- lineage projection ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-lineage-projection.ts
printf '%s\n' '--- folder workspace symbols ---'
rg -n -C 5 'mergeFolderWorkspace|FolderWorkspace|folderWorkspace|isEligibleWorktreeParent|parent eligibility' src/renderer/src -g '*.ts' -g '*.tsx' | head -n 320Repository: stablyai/orca Length of output: 41658 🏁 Script executed: set -e
printf '%s\n' '--- visible-worktrees.ts ---'
sed -n '80,225p' src/renderer/src/components/sidebar/visible-worktrees.ts
printf '%s\n' '--- worktree-lineage-projection.ts ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-lineage-projection.ts
printf '%s\n' '--- folder and eligibility symbols ---'
rg -n -C 5 'mergeFolderWorkspace|FolderWorkspace|folderWorkspace|isEligibleWorktreeParent|parent eligibility' src/renderer/src -g '*.ts' -g '*.tsx' | head -n 320Repository: stablyai/orca Length of output: 42077 🏁 Script executed: set -e
rg -l 'function isEligibleWorktreeParent|const isEligibleWorktreeParent|isEligibleWorktreeParent\s*=' src
rg -l 'mergeFolderWorkspace' src
rg -n -C 12 'isEligibleWorktreeParent|mergeFolderWorkspace' src/renderer/src/components/sidebar src/renderer/src -g '*.ts' -g '*.tsx' | head -n 240Repository: stablyai/orca Length of output: 26177 🏁 Script executed: set -e
printf '%s\n' '--- worktree-parent-candidates.ts ---'
sed -n '1,145p' src/renderer/src/components/sidebar/worktree-parent-candidates.ts
printf '%s\n' '--- resolved lineage contract ---'
rg -n -C 8 'isValidResolvedWorktreeLineageEdge' src/shared src/renderer/src -g '*.ts' | head -n 180
printf '%s\n' '--- folder workspace catalog ---'
rg -n -C 12 'mergeFolderWorkspace|isMainWorktree|rootId|folderWorkspace' src/main/ipc/worktrees/listing/folder-workspace-catalog.tsRepository: stablyai/orca Length of output: 22433 🏁 Script executed: set -e
printf '%s\n' '--- worktree-parent-candidates.ts ---'
sed -n '1,145p' src/renderer/src/components/sidebar/worktree-parent-candidates.ts
printf '%s\n' '--- resolved lineage helper ---'
rg -n -C 12 'isValidResolvedWorktreeLineageEdge' src/shared src/renderer/src -g '*.ts'
printf '%s\n' '--- folder catalog implementation ---'
rg -n -C 18 'mergeFolderWorkspace|isMainWorktree|rootId' src/main/ipc/worktrees/listing/folder-workspace-catalog.tsRepository: stablyai/orca Length of output: 29160 🏁 Script executed: set -e
printf '%s\n' '--- parent assignment rules ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-parent-eligibility.ts
printf '%s\n' '--- folder workspace model ---'
rg -n -C 20 'export function mergeFolderWorkspace|getFolderWorkspaceRootId|isMainWorktree' src/main/ipc/worktrees/folder-workspace-model.ts src/main/ipc/worktrees -g '*.ts'Repository: stablyai/orca Length of output: 41532 Keep hidden folder roots out of lineage injection. A folder workspace instance can use its folder root as a valid lineage parent. When |
||
| } | ||
|
|
||
| if (opts.hideAutomationGeneratedWorkspaces) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exclude archived worktrees from the skip visibility decision.
If an imported folder project has a root and an archived non-main workspace,
everyreturns false.computeVisibleWorktreesremoves the archived workspace at Line 99 ofsrc/renderer/src/components/sidebar/visible-worktrees.tsand hides the root. The project therefore disappears after Skip. Check the unarchived imported worktrees, with a nonempty guard, before deciding whether to disable default-workspace hiding.