The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(projects): gate branch switching on non-git folder lanes (#61362)
Hermes Agentf6b17285cef0
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx b/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsxindex b367c89b34d..7d5d3bc11c2 100644--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx@@ -103,8 +103,11 @@ export function SidebarWorkspaceGroup({// Main-checkout lanes are branch-labeled views over the same repo root path.// Clicking "+" on `main` should open on `main`, not whatever branch the root- // currently sits on (`test0`, etc.), so explicitly switch first.- if (group.isMain && group.path && group.label) {+ // currently sits on (`test0`, etc.), so explicitly switch first. A NON-GIT+ // lane (the backend heuristic's folder lane) has no branch to switch — `git+ // switch` there dies with "fatal: not a git repository" (#61362) — so the+ // new session just lands in the folder as-is.+ if (group.isMain && group.isGit !== false && group.path && group.label) {try {await switchBranchInRepo(group.path, group.label)} catch (err) {diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.tsindex 5f85c5b75ee..045eafe028d 100644--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts@@ -28,6 +28,12 @@ export interface SidebarSessionGroup {// worktrees (`<repo>/.worktrees/t_*`) into one row, so a heavy board doesn't// spray hundreds of throwaway branch lanes across the sidebar.isKanban?: boolean+ // False ONLY for the non-git heuristic lane of a plain folder (backend+ // `_place_by_heuristic`): it renders like a main lane but `git switch` on it+ // dies with "fatal: not a git repository", so branch-targeted actions must+ // skip it (#61362). Absent (undefined) on lanes from older backends — treat+ // missing as git, matching the historical behavior.+ isGit?: booleanmode?: 'profile' | 'source' | 'workspace'sourceId?: string// Exact owner for gateway/profile sidebar sections; absent for workspace lanes.diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsxindex d3fdc4d4f4e..22985d367cd 100644--- a/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx@@ -356,6 +356,43 @@ describe('project-associated new-session drag sources', () => {)})+ it('does not run a branch switch for a non-git lane before creating the dragged session', async () => {+ // A plain non-git folder still gets an isMain lane from the backend+ // heuristic, but `git switch <folder-name>` there dies with "fatal: not a+ // git repository" (#61362). The lane's isGit=False flag must suppress the+ // switch while the new session still lands in the folder.+ const onNewSessionSplit = vi.fn()++ render(+ <SidebarSessionsSection+ {...baseProps()}+ groups={[+ group({+ id: '/www/notes::branch::main',+ isGit: false,+ isMain: true,+ label: 'notes',+ path: '/www/notes',+ sessions: [{ id: 'notes-session' } as SessionInfo]+ })+ ]}+ onNewSessionSplit={onNewSessionSplit}+ />+ )++ fireEvent.pointerDown(screen.getByRole('button', { name: 'New session in notes' }), { button: 0 })+ commitLatestDrag()++ await waitFor(() => {+ expect(onNewSessionSplit).toHaveBeenCalledWith('right', {+ anchor: 'workspace',+ before: 'session-tile:next',+ cwd: '/www/notes'+ })+ })+ expect(switchBranchInRepo).not.toHaveBeenCalled()+ })+it('drags from an entered-project repo + with that repo cwd', () => {const onNewSessionSplit = vi.fn()diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex a8faf4b7366..17139f1b605 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -2281,6 +2281,7 @@ export interface ProjectTreeLane {path?: string | nullisMain?: booleanisKanban?: boolean+ isGit?: booleansessions?: ProjectTreeSession[]}/** ``methods_projects._project_tree_row`` + ``project_tree.stamp_profile``: the minimal row the sidebar renders, stamped with the profile it belongs to. */diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 6f2e1493901..5d48c907972 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -24097,6 +24097,11 @@"title": "Iskanban","type": "boolean"},+ "isGit": {+ "default": true,+ "title": "Isgit",+ "type": "boolean"+ },"sessions": {"items": {"$ref": "#/components/schemas/ProjectTreeSession"diff --git a/tests/tui_gateway/test_project_tree.py b/tests/tui_gateway/test_project_tree.pyindex a09dff9e58d..a2652dbf0c3 100644--- a/tests/tui_gateway/test_project_tree.py+++ b/tests/tui_gateway/test_project_tree.py@@ -566,6 +566,31 @@ def test_existing_non_git_workspace_still_becomes_a_project():assert [p["id"] for p in tree["projects"]] == ["/www/notes"]+def test_git_lanes_are_flagged_is_git():+ # Every placement backed by a git probe (or a persisted repo root, when no+ # probe ran) marks its lane isGit, so the renderer can offer branch+ # switching only where `git switch` can actually run.+ probed = pt.build_tree(+ [], [_session("/repo", branch="main")], [], _resolver({"/repo": ("/repo", "/repo")}), hydrate=True)+ persisted = pt.build_tree(+ [], [_session("/repo", branch="main", repo_root="/repo")], [], None, hydrate=True)++ for tree in (probed, persisted):+ lane = tree["projects"][0]["repos"][0]["groups"][0]+ assert lane["isMain"] and lane["isGit"]+++def test_non_git_heuristic_lane_is_flagged_not_git():+ # The path-only heuristic lane for a plain folder keeps the project and the+ # lane (pinned above), but carries isGit=False so the renderer never runs+ # `git switch <folder-name>` and dies with "not a git repository" (#61362).+ tree = pt.build_tree([], [_session("/www/notes")], [], lambda _cwd: None, hydrate=True)++ lane = tree["projects"][0]["repos"][0]["groups"][0]+ assert lane["isMain"] and lane["id"] == "/www/notes::branch::main"+ assert lane["isGit"] is False++def test_stale_persisted_repo_root_does_not_become_a_project():# A session carrying a git_repo_root whose repo has since been deleted must# not resurrect it as a project on the strength of the persisted value alone.diff --git a/tui_gateway/contracts/projects_pets.py b/tui_gateway/contracts/projects_pets.pyindex e90a93bcbb6..2f17d6b9cdc 100644--- a/tui_gateway/contracts/projects_pets.py+++ b/tui_gateway/contracts/projects_pets.py@@ -246,6 +246,10 @@ class ProjectTreeLane(Result):path: str | None = NoneisMain: bool = FalseisKanban: bool = False+ # True only when the placement saw git (probe or persisted repo root). The+ # path-only heuristic lane for a non-git folder is isMain but isGit=False,+ # so the renderer never offers `git switch` on it (#61362).+ isGit: bool = Truesessions: list[ProjectTreeSession] = Field(default_factory=list)diff --git a/tui_gateway/project_tree.py b/tui_gateway/project_tree.pyindex 767a41ed018..22737a320b0 100644--- a/tui_gateway/project_tree.py+++ b/tui_gateway/project_tree.py@@ -121,12 +121,13 @@ def _last_active(sessions: list[dict]) -> float:def _placement(- repo_root: str, lane_key: str, lane_label: str, lane_path: str, is_main: bool, is_kanban: bool+ repo_root: str, lane_key: str, lane_label: str, lane_path: str, is_main: bool, is_kanban: bool,+ is_git: bool = True,) -> dict:return {"repo_key": repo_root, "repo_label": base_name(repo_root) or repo_root,"lane_key": lane_key, "lane_label": lane_label, "lane_path": lane_path,- "is_main": is_main, "is_kanban": is_kanban}+ "is_main": is_main, "is_kanban": is_kanban, "is_git": is_git}def _trunk_placement(repo_root: str, branch: str) -> dict:@@ -169,7 +170,9 @@ def _place_by_heuristic(path: str) -> Optional[dict]:m = re.match(r"^(.+)-wt-(.+)$", base)if m:return _placement(_with_base_name(path, m.group(1)), path, m.group(2), path, False, False)- return _placement(path, _branch_lane_id(path, DEFAULT_BRANCH_LABEL), base, path, True, False)+ # No git knowledge at all: the lane is the folder itself, not a branch —+ # is_git=False tells the renderer never to `git switch` it (#61362).+ return _placement(path, _branch_lane_id(path, DEFAULT_BRANCH_LABEL), base, path, True, False, is_git=False)def _place(@@ -246,8 +249,8 @@ def _disambiguate_labels(items: list[dict]) -> None:# Lane group wire fields <- placement keys (same order).-_LANE_FIELDS = ("id", "label", "path", "isMain", "isKanban")-_PLACEMENT_LANE_KEYS = ("lane_key", "lane_label", "lane_path", "is_main", "is_kanban")+_LANE_FIELDS = ("id", "label", "path", "isMain", "isKanban", "isGit")+_PLACEMENT_LANE_KEYS = ("lane_key", "lane_label", "lane_path", "is_main", "is_kanban", "is_git")def _repo_node(root: str, label: str) -> dict: