Files
orca/src/relay/git-handler-utils.test.ts
T
Trevin ChowandNeil b2b5cac9a9 Add per-file line counts to the source control sidebar (#2865)
* Add per-file line counts to the source control sidebar

Show +N/-N (green/red) next to each file in the Changes, Untracked, and
Committed-on-branch sections so the magnitude of a change is visible at a
glance. Counts are computed per staging area via `git diff --numstat`;
untracked/new files count their full contents as additions and binary
files show no count.

Consolidate numstat parsing and binary-buffer detection into shared
modules reused by the local status path, the SSH/relay path, and the
existing branch-compare code. Include added/removed in the status-entry
equality check so the sidebar doesn't re-render on unchanged polls.

* fix: harden source control line counts

---------

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-05-26 20:09:54 -07:00

51 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { parseStatusOutput } from './git-status-output-parser'
describe('parseStatusOutput', () => {
it('parses upstream ahead/behind from porcelain v2 branch headers', () => {
const result = parseStatusOutput(
[
'# branch.oid abcdef1234567890',
'# branch.head feature/prompts',
'# branch.upstream origin/feature/prompts',
'# branch.ab +2 -3',
''
].join('\n')
)
expect(result.upstreamStatus).toEqual({
hasUpstream: true,
upstreamName: 'origin/feature/prompts',
ahead: 2,
behind: 3
})
})
it('reports no upstream when porcelain v2 omits branch.upstream', () => {
const result = parseStatusOutput(
['# branch.oid abcdef1234567890', '# branch.head feature/prompts', ''].join('\n')
)
expect(result.upstreamStatus).toEqual({ hasUpstream: false, ahead: 0, behind: 0 })
})
it('parses ignored porcelain records separately from actionable entries', () => {
const result = parseStatusOutput(['! dist/', '! .env', '? scratch.txt', ''].join('\n'))
expect(result.ignoredPaths).toEqual(['dist/', '.env'])
expect(result.entries).toEqual([
{ path: 'scratch.txt', status: 'untracked', area: 'untracked' }
])
})
it('parses rename records with spaces in the paths', () => {
const result = parseStatusOutput(
'2 R. N... 100644 100644 100644 aaaa bbbb R100 src/new name.ts\tsrc/old name.ts\n'
)
expect(result.entries).toEqual([
{ path: 'src/new name.ts', oldPath: 'src/old name.ts', status: 'renamed', area: 'staged' }
])
})
})