This commit is contained in:
Edward Thomson
2025-03-06 09:42:37 +00:00
parent 4f24b2729f
commit 298a484af2
2 changed files with 21 additions and 3 deletions

View File

@@ -22,13 +22,20 @@ static int notification_cb(
void *data)
{
const char *level_string;
int error = 0;
GIT_UNUSED(notification);
GIT_UNUSED(data);
switch (level) {
case GIT_NOTIFICATION_FATAL:
/*
* Set an error class of 1 to suppress printing the error
* message a second time in our error handler.
*/
level_string = "fatal";
git_error_set_str(CLI_ERROR_SUPPRESS, message);
error = GIT_EUSER;
break;
case GIT_NOTIFICATION_ERROR:
level_string = "error";
@@ -38,12 +45,13 @@ static int notification_cb(
break;
default:
level_string = "warning";
break;
}
fprintf(stderr, "%s: %s\n", level_string, message);
fflush(stderr);
return (level == GIT_NOTIFICATION_FATAL) ? -1 : 0;
return error;
}
void cli_init(void)

View File

@@ -17,6 +17,8 @@
#define CLI_EXIT_GIT 128
#define CLI_EXIT_USAGE 129
#define CLI_ERROR_SUPPRESS -1
#define cli_error__print(fmt) do { \
va_list ap; \
va_start(ap, fmt); \
@@ -41,8 +43,16 @@ GIT_INLINE(int) cli_error_usage(const char *fmt, ...)
GIT_INLINE(int) cli_error_git(void)
{
const git_error *err = git_error_last();
fprintf(stderr, "%s: %s\n", PROGRAM_NAME,
err ? err->message : "unknown error");
/*
* We set an error class of `CLI_ERROR_SUPPRESS` in our
* notification handler since we've shown the message already.
*/
if (err && err->klass != CLI_ERROR_SUPPRESS) {
fprintf(stderr, "%s: %s\n", PROGRAM_NAME,
err ? err->message : "unknown error");
}
return CLI_EXIT_GIT;
}