Files
orca/src/main/git/status-upstream-ref.ts
T
Brennan Benson de64337c26 fix(worktree-watcher): refresh status after external pushes (#12361)
* fix(worktree-watcher): surface external push -u through the git-common watch

An external-shell 'git push -u' writes only the common .git/config (plus
refs/remotes/<remote>/<branch>), both invisible to the git-common event
filter, so the Checks panel stayed on 'No upstream configured' until the
renderer safety poll. Classify the common config and remote-tracking refs
as status-tier signals, poll config alongside the other primary-checkout
metadata files, and keep FETCH_HEAD/reflog/ref-lock churn ignored.

* fix(worktree-watcher): refresh after subsequent pushes
2026-08-05 11:26:13 -07:00

53 lines
1.4 KiB
TypeScript

import { isSafeGitRefName } from '../../shared/git-status-upstream-ref'
type GitStatusUpstreamRefExec = (
args: string[],
cwd: string,
signal: AbortSignal
) => Promise<{ stdout: string }>
function exactRefFromOutput(stdout: string): string | undefined {
const refs = stdout
.split(/\r?\n/)
.map((line) => line.trim())
.filter(isSafeGitRefName)
return refs.length === 1 ? refs[0] : undefined
}
export async function resolveGitStatusUpstreamRef(
execGit: GitStatusUpstreamRefExec,
worktreePath: string,
branch: string,
upstreamName: string,
signal: AbortSignal
): Promise<string | undefined> {
if (!branch.startsWith('refs/heads/') || !isSafeGitRefName(branch)) {
return undefined
}
const result = await execGit(
['for-each-ref', '--format=%(refname)%00%(upstream)%00%(upstream:short)', '--count=1', branch],
worktreePath,
signal
)
const fields = result.stdout.replace(/\r?\n$/, '').split('\0')
if (fields.length !== 3 || fields[0] !== branch) {
return undefined
}
if (fields[2] === upstreamName) {
return exactRefFromOutput(fields[1])
}
try {
const effective = await execGit(
['rev-parse', '--symbolic-full-name', '--end-of-options', upstreamName],
worktreePath,
signal
)
return exactRefFromOutput(effective.stdout)
} catch {
if (signal.aborted) {
throw signal.reason
}
return undefined
}
}