diff --git a/src/lib/git.test.ts b/src/lib/git.test.ts index 7acafd2e..4db7a7b5 100644 --- a/src/lib/git.test.ts +++ b/src/lib/git.test.ts @@ -364,9 +364,9 @@ describe('deleteRemote', () => { repoName: 'kibana', } as ValidConfigOptions; - it('should swallow "no such remote" error', async () => { + it('should swallow "no such remote" error on git before 2.30.0', async () => { const err = new childProcess.SpawnError({ - code: 2, + code: 128, cmdArgs: [], stdout: '', stderr: "fatal: No such remote: 'my-remote'\n", @@ -376,11 +376,23 @@ describe('deleteRemote', () => { await expect(await deleteRemote(options, remoteName)).toBe(undefined); }); - it('should swallow "no such remote" error, even if it is not in English', async () => { + it('should swallow "no such remote" error on git 2.30.0 or later', async () => { const err = new childProcess.SpawnError({ code: 2, cmdArgs: [], stdout: '', + stderr: "fatal: No such remote: 'my-remote'\n", + }); + + jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err); + await expect(await deleteRemote(options, remoteName)).toBe(undefined); + }); + + it('should swallow "no such remote" error on git 2.30.0+, even if it is not in English', async () => { + const err = new childProcess.SpawnError({ + code: 2, // returned only by git 2.30.0 or later, earlier versions returned 128 + cmdArgs: [], + stdout: '', stderr: "Fehler: Remote-Repository nicht gefunden: 'my-remote'\n", }); diff --git a/src/lib/git.ts b/src/lib/git.ts index 93932a60..4dc1688b 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -191,10 +191,15 @@ export async function deleteRemote( } catch (e) { const isSpawnError = e instanceof SpawnError; - // Swallow the "remote does not exist" failure, indicated by a return - // code of 2. From `git help remote`: "When subcommands such as add, rename, - // and remove can’t find the remote in question, the exit status is 2." - if (isSpawnError && e.context.code == 2) { + // Swallow the "remote does not exist" failure. + // Since git 2.30.0, this failure is indicated by the specific exit code 2. + // In earlier versions, the exit code is 128 and only the error message can + // tell the problems apart. + if ( + isSpawnError && + (e.context.code == 2 || + (e.context.code == 128 && e.context.stderr.includes('No such remote'))) + ) { return; }