Files
orca/src/shared/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

46 lines
1.2 KiB
TypeScript

const REF_PREFIX = 'refs/'
const LOCAL_BRANCH_REF_PREFIX = 'refs/heads/'
const WORKTREE_REF_PREFIXES = ['refs/bisect/', 'refs/rewritten/', 'refs/worktree/']
const FORBIDDEN_REF_CHARS = '~^:?*[\\'
function hasForbiddenRefChar(ref: string): boolean {
for (const char of ref) {
const code = char.charCodeAt(0)
if (code <= 0x20 || code === 0x7f || FORBIDDEN_REF_CHARS.includes(char)) {
return true
}
}
return false
}
export function isSafeGitRefName(ref: string): boolean {
if (!ref.startsWith(REF_PREFIX) || ref.endsWith('/')) {
return false
}
if (ref.includes('..') || ref.includes('@{') || hasForbiddenRefChar(ref)) {
return false
}
const parts = ref.split('/')
return (
parts.length >= 2 &&
parts.every(
(part) =>
part.length > 0 &&
part !== '.' &&
part !== '..' &&
!part.startsWith('.') &&
!part.endsWith('.') &&
!part.endsWith('.lock')
)
)
}
export function isSafeGitStatusUpstreamRef(ref: string): boolean {
return (
isSafeGitRefName(ref) &&
ref !== 'refs/heads' &&
!ref.startsWith(LOCAL_BRANCH_REF_PREFIX) &&
!WORKTREE_REF_PREFIXES.some((prefix) => ref === prefix.slice(0, -1) || ref.startsWith(prefix))
)
}