@@ -5,7 +5,6 @@ import { debugFn } from '@socketsecurity/registry/lib/debug'
55import { normalizePath } from '@socketsecurity/registry/lib/path'
66import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
77import { spawn } from '@socketsecurity/registry/lib/spawn'
8- import { stripAnsi } from '@socketsecurity/registry/lib/strings'
98
109import constants from '../../constants.mts'
1110import { getPurlObject } from '../../utils/purl.mts'
@@ -88,10 +87,11 @@ export async function getBaseGitBranch(cwd = process.cwd()): Promise<string> {
8887 // 3. Try to resolve the default remote branch using 'git remote show origin'.
8988 // This handles detached HEADs or workflows triggered by tags/releases.
9089 try {
91- const stdout = stripAnsi (
92- ( await spawn ( 'git' , [ 'remote' , 'show' , 'origin' ] , { cwd } ) ) . stdout . trim ( ) ,
93- )
94- const match = / (?< = H E A D b r a n c h : ) .+ / . exec ( stdout )
90+ const originDetails = (
91+ await spawn ( 'git' , [ 'remote' , 'show' , 'origin' ] , { cwd } )
92+ ) . stdout
93+
94+ const match = / (?< = H E A D b r a n c h : ) .+ / . exec ( originDetails )
9595 if ( match ?. [ 0 ] ) {
9696 return match [ 0 ] . trim ( )
9797 }
@@ -266,11 +266,9 @@ export async function gitRepoInfo(
266266 cwd = process . cwd ( ) ,
267267) : Promise < RepoInfo | null > {
268268 try {
269- const remoteUrl = stripAnsi (
270- (
271- await spawn ( 'git' , [ 'remote' , 'get-url' , 'origin' ] , { cwd } )
272- ) . stdout . trim ( ) ,
273- )
269+ const remoteUrl = (
270+ await spawn ( 'git' , [ 'remote' , 'get-url' , 'origin' ] , { cwd } )
271+ ) . stdout
274272 // 1. Handle SSH-style, e.g. git@github.com:owner/repo.git
275273 const sshMatch = / ^ g i t @ [ ^ : ] + : ( [ ^ / ] + ) \/ ( .+ ?) (?: \. g i t ) ? $ / . exec ( remoteUrl )
276274 if ( sshMatch ) {
@@ -309,11 +307,9 @@ export async function gitEnsureIdentity(
309307 let configValue
310308 try {
311309 // Will throw with exit code 1 if the config property is not set.
312- configValue = stripAnsi (
313- (
314- await spawn ( 'git' , [ 'config' , '--get' , prop ] , stdioPipeOptions )
315- ) . stdout . trim ( ) ,
316- )
310+ configValue = (
311+ await spawn ( 'git' , [ 'config' , '--get' , prop ] , stdioPipeOptions )
312+ ) . stdout
317313 } catch { }
318314 if ( configValue !== value ) {
319315 try {
@@ -333,19 +329,16 @@ export async function gitRemoteBranchExists(
333329 const stdioPipeOptions : SpawnOptions = { cwd }
334330 try {
335331 return (
336- stripAnsi (
337- (
338- await spawn (
339- 'git' ,
340- [ 'ls-remote' , '--heads' , 'origin' , branch ] ,
341- stdioPipeOptions ,
342- )
343- ) . stdout . trim ( ) ,
344- ) . length > 0
332+ (
333+ await spawn (
334+ 'git' ,
335+ [ 'ls-remote' , '--heads' , 'origin' , branch ] ,
336+ stdioPipeOptions ,
337+ )
338+ ) . stdout . length > 0
345339 )
346- } catch {
347- return false
348- }
340+ } catch { }
341+ return false
349342}
350343
351344export async function gitResetAndClean (
@@ -371,13 +364,14 @@ export async function gitUnstagedModifiedFiles(
371364) : Promise < CResult < string [ ] > > {
372365 try {
373366 const stdioPipeOptions : SpawnOptions = { cwd }
374- const stdout = stripAnsi (
375- (
376- await spawn ( 'git' , [ 'diff' , '--name-only' ] , stdioPipeOptions )
377- ) . stdout . trim ( ) ,
378- )
379- const rawFiles = stdout . split ( '\n' ) ?? [ ]
380- return { ok : true , data : rawFiles . map ( relPath => normalizePath ( relPath ) ) }
367+ const changedFilesDetails = (
368+ await spawn ( 'git' , [ 'diff' , '--name-only' ] , stdioPipeOptions )
369+ ) . stdout
370+ const rawRelPaths = changedFilesDetails . split ( '\n' ) ?? [ ]
371+ return {
372+ ok : true ,
373+ data : rawRelPaths . map ( relPath => normalizePath ( relPath ) ) ,
374+ }
381375 } catch ( e ) {
382376 debugFn ( 'catch: git diff --name-only failed\n' , e )
383377
0 commit comments