diff --git a/src/lib/git.test.ts b/src/lib/git.test.ts index 3d89f835..7acafd2e 100644 --- a/src/lib/git.test.ts +++ b/src/lib/git.test.ts @@ -364,12 +364,24 @@ describe('deleteRemote', () => { repoName: 'kibana', } as ValidConfigOptions; - it('should swallow SpawnError error', async () => { + it('should swallow "no such remote" error', async () => { const err = new childProcess.SpawnError({ - code: 128, + 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, even if it is not in English', async () => { + const err = new childProcess.SpawnError({ + code: 2, cmdArgs: [], stdout: '', - stderr: "fatal: No such remote: 'origin'\n", + stderr: "Fehler: Remote-Repository nicht gefunden: 'my-remote'\n", }); jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err); diff --git a/src/lib/git.ts b/src/lib/git.ts index 43e9052c..93932a60 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -191,11 +191,10 @@ export async function deleteRemote( } catch (e) { const isSpawnError = e instanceof SpawnError; - if ( - isSpawnError && - e.context.code > 0 && - e.context.stderr.includes('No such remote') - ) { + // 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) { return; }