Handle unborn worktrees with resolvable base (#2398)
- Treat new remote worktrees without a HEAD commit as an empty compare when the base ref exists, avoiding a broken source-control compare state - Keep the existing unborn-head error for cases where the base cannot resolve
This commit is contained in:
@@ -151,18 +151,33 @@ export async function branchCompare(
|
||||
}
|
||||
|
||||
let headOid: string
|
||||
let baseOid = ''
|
||||
try {
|
||||
const { stdout } = await git(['rev-parse', '--verify', 'HEAD'], worktreePath)
|
||||
headOid = stdout.trim()
|
||||
summary.headOid = headOid
|
||||
} catch {
|
||||
try {
|
||||
const { stdout } = await git(['rev-parse', '--verify', baseRef], worktreePath)
|
||||
baseOid = stdout.trim()
|
||||
summary.baseOid = baseOid
|
||||
// Why: new remote worktrees can be on an unborn branch until the first
|
||||
// commit. There are no committed branch changes yet; surfacing this as a
|
||||
// compare error makes the source-control panel look broken.
|
||||
summary.changedFiles = 0
|
||||
summary.commitsAhead = 0
|
||||
summary.status = 'ready'
|
||||
return { summary, entries: [] }
|
||||
} catch {
|
||||
// Preserve the existing unborn-head message when even the base is not
|
||||
// resolvable; callers cannot compare or present a useful empty state.
|
||||
}
|
||||
summary.status = 'unborn-head'
|
||||
summary.errorMessage =
|
||||
'This branch does not have a committed HEAD yet, so compare-to-base is unavailable.'
|
||||
return { summary, entries: [] }
|
||||
}
|
||||
|
||||
let baseOid: string
|
||||
try {
|
||||
const { stdout } = await git(['rev-parse', '--verify', baseRef], worktreePath)
|
||||
baseOid = stdout.trim()
|
||||
|
||||
Reference in New Issue
Block a user