Teach GitCommandManager.exec about an object of exec parameters so we can add more

This commit is contained in:
Graham Christensen 2025-02-20 15:25:24 -05:00
parent c2125cf018
commit 65c46285dc
2 changed files with 14 additions and 10 deletions

View File

@ -19,7 +19,7 @@ export async function getWorkingBaseAndType(
): Promise<[string, WorkingBaseType]> { ): Promise<[string, WorkingBaseType]> {
const symbolicRefResult = await git.exec( const symbolicRefResult = await git.exec(
['symbolic-ref', 'HEAD', '--short'], ['symbolic-ref', 'HEAD', '--short'],
true {allowAllExitCodes: true}
) )
if (symbolicRefResult.exitCode == 0) { if (symbolicRefResult.exitCode == 0) {
// A ref is checked out // A ref is checked out
@ -200,7 +200,7 @@ export async function createOrUpdateBranch(
} else { } else {
aopts.push('-A') aopts.push('-A')
} }
await git.exec(aopts, true) await git.exec(aopts, {allowAllExitCodes: true})
const popts = ['-m', commitMessage] const popts = ['-m', commitMessage]
if (signoff) { if (signoff) {
popts.push('--signoff') popts.push('--signoff')

View File

@ -21,6 +21,10 @@ export type Commit = {
unparsedChanges: string[] unparsedChanges: string[]
} }
export type ExecOpts = {
allowAllExitCodes?: boolean,
}
export class GitCommandManager { export class GitCommandManager {
private gitPath: string private gitPath: string
private workingDirectory: string private workingDirectory: string
@ -66,7 +70,7 @@ export class GitCommandManager {
args.push(...options) args.push(...options)
} }
return await this.exec(args, allowAllExitCodes) return await this.exec(args, {allowAllExitCodes: allowAllExitCodes})
} }
async commit( async commit(
@ -82,7 +86,7 @@ export class GitCommandManager {
args.push(...options) args.push(...options)
} }
return await this.exec(args, allowAllExitCodes) return await this.exec(args, {allowAllExitCodes: allowAllExitCodes})
} }
async config( async config(
@ -113,7 +117,7 @@ export class GitCommandManager {
configKey, configKey,
configValue configValue
], ],
true {allowAllExitCodes: true}
) )
return output.exitCode === 0 return output.exitCode === 0
} }
@ -222,7 +226,7 @@ export class GitCommandManager {
if (options) { if (options) {
args.push(...options) args.push(...options)
} }
const output = await this.exec(args, true) const output = await this.exec(args, {allowAllExitCodes: true})
return output.exitCode === 1 return output.exitCode === 1
} }
@ -332,7 +336,7 @@ export class GitCommandManager {
configKey, configKey,
configValue configValue
], ],
true {allowAllExitCodes: true}
) )
return output.exitCode === 0 return output.exitCode === 0
} }
@ -340,7 +344,7 @@ export class GitCommandManager {
async tryGetRemoteUrl(): Promise<string> { async tryGetRemoteUrl(): Promise<string> {
const output = await this.exec( const output = await this.exec(
['config', '--local', '--get', 'remote.origin.url'], ['config', '--local', '--get', 'remote.origin.url'],
true {allowAllExitCodes: true}
) )
if (output.exitCode !== 0) { if (output.exitCode !== 0) {
@ -355,7 +359,7 @@ export class GitCommandManager {
return stdout return stdout
} }
async exec(args: string[], allowAllExitCodes = false): Promise<GitOutput> { async exec(args: string[], opts: ExecOpts = {}): Promise<GitOutput> {
const result = new GitOutput() const result = new GitOutput()
const env = {} const env = {}
@ -369,7 +373,7 @@ export class GitCommandManager {
const options = { const options = {
cwd: this.workingDirectory, cwd: this.workingDirectory,
env, env,
ignoreReturnCode: allowAllExitCodes, ignoreReturnCode: opts.allowAllExitCodes ?? false,
listeners: { listeners: {
stdout: (data: Buffer) => { stdout: (data: Buffer) => {
stdout.push(data.toString()) stdout.push(data.toString())