Skip to content

Commit ab4f84c

Browse files
committed
handle delete remote ref that does not exist err
1 parent 81146eb commit ab4f84c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/env/node/git/git.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,13 @@ export class Git {
10521052
/! \[rejected\].*\(remote ref updated since checkout\)/m.test(ex.stderr || '')
10531053
) {
10541054
reason = PushErrorReason.PushRejectedWithLeaseIfIncludes;
1055+
} else if (/error: unable to delete '(.*?)': remote ref does not exist/m.test(ex.stderr || '')) {
1056+
reason = PushErrorReason.PushRejectedRefNotExists;
10551057
} else {
10561058
reason = PushErrorReason.PushRejected;
10571059
}
1060+
} else if (/error: unable to delete '(.*?)': remote ref does not exist/m.test(ex.stderr || '')) {
1061+
reason = PushErrorReason.PushRejectedRefNotExists;
10581062
} else {
10591063
reason = PushErrorReason.PushRejected;
10601064
}
@@ -1066,7 +1070,12 @@ export class Git {
10661070
reason = PushErrorReason.NoUpstream;
10671071
}
10681072

1069-
throw new PushError(reason, ex, options?.branch, options?.remote);
1073+
throw new PushError(
1074+
reason,
1075+
ex,
1076+
options?.branch || options?.delete?.branch,
1077+
options?.remote || options?.delete?.remote,
1078+
);
10701079
}
10711080
}
10721081

src/git/errors.ts

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export const enum PushErrorReason {
148148
PushRejected,
149149
PushRejectedWithLease,
150150
PushRejectedWithLeaseIfIncludes,
151+
PushRejectedRefNotExists,
151152
PermissionDenied,
152153
RemoteConnection,
153154
NoUpstream,
@@ -197,6 +198,11 @@ export class PushError extends Error {
197198
remote ? ` to ${remote}` : ''
198199
} 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.`;
199200
break;
201+
case PushErrorReason.PushRejectedRefNotExists:
202+
message = `Unable to delete branch${branch ? ` '${branch}'` : ''}${
203+
remote ? ` on ${remote}` : ''
204+
}, the remote reference does not exist`;
205+
break;
200206
case PushErrorReason.PermissionDenied:
201207
message = `${baseMessage} because you don't have permission to push to this remote repository.`;
202208
break;

0 commit comments

Comments
 (0)