Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swallow "remote not found" error on git before 2.30 #514

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/lib/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
});

Expand Down
13 changes: 9 additions & 4 deletions src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading