Skip to content

Commit

Permalink
handle delete remote ref that does not exist err
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Nov 11, 2024
1 parent dac43a8 commit 965edeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/env/node/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,13 @@ export class Git {
/! \[rejected\].*\(remote ref updated since checkout\)/m.test(ex.stderr || '')
) {
reason = PushErrorReason.PushRejectedWithLeaseIfIncludes;
} else if (/error: unable to delete '(.*?)': remote ref does not exist/m.test(ex.stderr || '')) {
reason = PushErrorReason.PushRejectedRefNotExists;
} else {
reason = PushErrorReason.PushRejected;
}
} else if (/error: unable to delete '(.*?)': remote ref does not exist/m.test(ex.stderr || '')) {
reason = PushErrorReason.PushRejectedRefNotExists;
} else {
reason = PushErrorReason.PushRejected;
}
Expand All @@ -1066,7 +1070,12 @@ export class Git {
reason = PushErrorReason.NoUpstream;
}

throw new PushError(reason, ex, options?.branch, options?.remote);
throw new PushError(
reason,
ex,
options?.branch || options?.delete?.branch,
options?.remote || options?.delete?.remote,
);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/git/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const enum PushErrorReason {
PushRejected,
PushRejectedWithLease,
PushRejectedWithLeaseIfIncludes,
PushRejectedRefNotExists,
PermissionDenied,
RemoteConnection,
NoUpstream,
Expand Down Expand Up @@ -197,6 +198,11 @@ export class PushError extends Error {
remote ? ` to ${remote}` : ''
} because some refs failed to push or the push was rejected. The tip of the remote-tracking branch has been updated since the last checkout. Try pulling first.`;
break;
case PushErrorReason.PushRejectedRefNotExists:
message = `Unable to delete branch${branch ? ` '${branch}'` : ''}${
remote ? ` on ${remote}` : ''
}, the remote reference does not exist`;
break;
case PushErrorReason.PermissionDenied:
message = `${baseMessage} because you don't have permission to push to this remote repository.`;
break;
Expand Down

0 comments on commit 965edeb

Please sign in to comment.