mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
Merge worktree fix for desktop branch display
Bring the issue #539 fix from the detached Codex worktree into the canonical local main checkout so desktop sessions in materialized worktrees report the actual checked-out branch. Constraint: Local main had advanced independently, so this could not fast-forward cleanly. Confidence: high Scope-risk: narrow Tested: bun test src/server/__tests__/sessions.test.ts -t "git-info" Tested: /tmp/cc-haha-issue-539-verify API reproduction returned the worktree branch Tested: bun run check:server
This commit is contained in:
commit
cb8bdce316
@ -2022,7 +2022,7 @@ describe('Sessions API', () => {
|
||||
branch: string | null
|
||||
} | null
|
||||
}
|
||||
expect(body.branch).toBe('main')
|
||||
expect(body.branch).toBe(repository!.worktreeBranch)
|
||||
expect(body.workDir).toBe(activeWorktree)
|
||||
expect(body.worktree).toEqual({
|
||||
enabled: true,
|
||||
@ -2067,7 +2067,7 @@ describe('Sessions API', () => {
|
||||
branch: string | null
|
||||
} | null
|
||||
}
|
||||
expect(body.branch).toBe('main')
|
||||
expect(body.branch).toBe('worktree-desktop-main-12345678')
|
||||
expect(body.workDir).toBe(activeWorktree)
|
||||
expect(body.worktree).toEqual({
|
||||
enabled: true,
|
||||
@ -2121,7 +2121,7 @@ describe('Sessions API', () => {
|
||||
branch: string | null
|
||||
} | null
|
||||
}
|
||||
expect(body.branch).toBe('main')
|
||||
expect(body.branch).toBe('worktree-desktop-main-12345678')
|
||||
expect(body.worktree).toMatchObject({
|
||||
path: activeWorktree,
|
||||
plannedPath: activeWorktree,
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
* PATCH /api/sessions/:id — 重命名会话
|
||||
*/
|
||||
|
||||
import * as path from 'node:path'
|
||||
import { sessionService } from '../services/sessionService.js'
|
||||
import { conversationService } from '../services/conversationService.js'
|
||||
import { ApiError, errorResponse } from '../middleware/errorHandler.js'
|
||||
@ -622,6 +623,11 @@ function chooseRicherUsage(
|
||||
: currentUsage
|
||||
}
|
||||
|
||||
function sameResolvedPath(left: string | null | undefined, right: string | null | undefined): boolean {
|
||||
if (!left || !right) return false
|
||||
return path.resolve(left) === path.resolve(right)
|
||||
}
|
||||
|
||||
async function getGitInfo(sessionId: string): Promise<Response> {
|
||||
const workDir = conversationService.getSessionWorkDir(sessionId) || await sessionService.getSessionWorkDir(sessionId)
|
||||
if (!workDir) {
|
||||
@ -653,7 +659,14 @@ async function getGitInfo(sessionId: string): Promise<Response> {
|
||||
stderr: 'pipe',
|
||||
})
|
||||
const branchText = await new Response(branchProc.stdout).text()
|
||||
const branch = sessionBranch || branchText.trim()
|
||||
const gitBranch = branchText.trim() || null
|
||||
const materializedWorktree = !!worktree && (
|
||||
sameResolvedPath(workDir, worktree.path) ||
|
||||
sameResolvedPath(workDir, worktree.plannedPath)
|
||||
)
|
||||
const branch = materializedWorktree
|
||||
? (gitBranch || worktree.branch || sessionBranch)
|
||||
: (sessionBranch || gitBranch)
|
||||
|
||||
// Get repo name from remote or directory
|
||||
let repoName = ''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user