diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 2eecd45d..746a3a03 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -19,7 +19,7 @@ export async function getWorkingBaseAndType( ): Promise<[string, WorkingBaseType]> { const symbolicRefResult = await git.exec( ['symbolic-ref', 'HEAD', '--short'], - true + {allowAllExitCodes: true} ) if (symbolicRefResult.exitCode == 0) { // A ref is checked out @@ -200,7 +200,7 @@ export async function createOrUpdateBranch( } else { aopts.push('-A') } - await git.exec(aopts, true) + await git.exec(aopts, {allowAllExitCodes: true}) const popts = ['-m', commitMessage] if (signoff) { popts.push('--signoff') diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 303c4b53..b5cc5721 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -21,6 +21,10 @@ export type Commit = { unparsedChanges: string[] } +export type ExecOpts = { + allowAllExitCodes?: boolean, +} + export class GitCommandManager { private gitPath: string private workingDirectory: string @@ -66,7 +70,7 @@ export class GitCommandManager { args.push(...options) } - return await this.exec(args, allowAllExitCodes) + return await this.exec(args, {allowAllExitCodes: allowAllExitCodes}) } async commit( @@ -82,7 +86,7 @@ export class GitCommandManager { args.push(...options) } - return await this.exec(args, allowAllExitCodes) + return await this.exec(args, {allowAllExitCodes: allowAllExitCodes}) } async config( @@ -113,7 +117,7 @@ export class GitCommandManager { configKey, configValue ], - true + {allowAllExitCodes: true} ) return output.exitCode === 0 } @@ -222,7 +226,7 @@ export class GitCommandManager { if (options) { args.push(...options) } - const output = await this.exec(args, true) + const output = await this.exec(args, {allowAllExitCodes: true}) return output.exitCode === 1 } @@ -332,7 +336,7 @@ export class GitCommandManager { configKey, configValue ], - true + {allowAllExitCodes: true} ) return output.exitCode === 0 } @@ -340,7 +344,7 @@ export class GitCommandManager { async tryGetRemoteUrl(): Promise { const output = await this.exec( ['config', '--local', '--get', 'remote.origin.url'], - true + {allowAllExitCodes: true} ) if (output.exitCode !== 0) { @@ -355,7 +359,7 @@ export class GitCommandManager { return stdout } - async exec(args: string[], allowAllExitCodes = false): Promise { + async exec(args: string[], opts: ExecOpts = {}): Promise { const result = new GitOutput() const env = {} @@ -369,7 +373,7 @@ export class GitCommandManager { const options = { cwd: this.workingDirectory, env, - ignoreReturnCode: allowAllExitCodes, + ignoreReturnCode: opts.allowAllExitCodes ?? false, listeners: { stdout: (data: Buffer) => { stdout.push(data.toString())