Skip to content

1422 Properly Color Failed Remote Push Messages #1429

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

Closed
Closed
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
31 changes: 30 additions & 1 deletion advice.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cache.h"
#include "config.h"
#include "color.h"

int advice_push_update_rejected = 1;
int advice_push_non_ff_current = 1;
Expand All @@ -20,6 +21,33 @@ int advice_add_embedded_repo = 1;
int advice_ignored_hook = 1;
int advice_waiting_for_editor = 1;

static int advice_use_color = -1;

This comment was marked as off-topic.

This comment was marked as off-topic.

static char advice_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET,
GIT_COLOR_YELLOW, /* HINT */
};

enum color_advice {
ADVICE_COLOR_RESET = 0,
ADVICE_COLOR_HINT = 1,
};

static int parse_advise_color_slot(const char *slot)
{
if (!strcasecmp(slot, "reset"))
return ADVICE_COLOR_RESET;
if (!strcasecmp(slot, "advice"))
return ADVICE_COLOR_HINT;
return -1;
}

static const char *advise_get_color(enum color_advice ix)
{
if (want_color(advice_use_color))

This comment was marked as off-topic.

return advice_colors[ix];
return "";
}

static struct {
const char *name;
int *preference;
Expand Down Expand Up @@ -59,7 +87,8 @@ void advise(const char *advice, ...)

for (cp = buf.buf; *cp; cp = np) {
np = strchrnul(cp, '\n');
fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
fprintf(stderr, _("%shint: %.*s%s\n"), advise_get_color(ADVICE_COLOR_HINT),
(int)(np - cp), cp, advise_get_color(ADVICE_COLOR_RESET));

This comment was marked as off-topic.

if (*np)
np++;
}
Expand Down
30 changes: 30 additions & 0 deletions builtin/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,40 @@
#include "submodule.h"
#include "submodule-config.h"
#include "send-pack.h"
#include "color.h"

static const char * const push_usage[] = {
N_("git push [<options>] [<repository> [<refspec>...]]"),
NULL,
};

static int push_use_color = -1;
static char push_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET,
GIT_COLOR_RED, /* ERROR */
};

enum color_push {
PUSH_COLOR_RESET = 0,
PUSH_COLOR_ERROR = 1
};

static int parse_push_color_slot(const char *slot)
{
if (!strcasecmp(slot, "reset"))
return PUSH_COLOR_RESET;
if (!strcasecmp(slot, "error"))
return PUSH_COLOR_ERROR;
return -1;
}

static const char *push_get_color(enum color_push ix)
{
if (want_color(push_use_color))
return push_colors[ix];
return "";
}

static int thin = 1;
static int deleterefs;
static const char *receivepack;
Expand Down Expand Up @@ -338,7 +366,9 @@ static int push_with_options(struct transport *transport, int flags)
err = transport_push(transport, refspec_nr, refspec, flags,
&reject_reasons);
if (err != 0)
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
error(_("failed to push some refs to '%s'"), transport->url);
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));

This comment was marked as off-topic.


err |= transport_disconnect(transport);
if (!err)
Expand Down
34 changes: 33 additions & 1 deletion transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@
#include "sha1-array.h"
#include "sigchain.h"
#include "transport-internal.h"
#include "color.h"

static int transport_use_color = -1;
static char transport_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET,
GIT_COLOR_RED /* REJECTED */
};

enum color_transport {
TRANSPORT_COLOR_RESET = 0,
TRANSPORT_COLOR_REJECTED = 1
};

static int parse_transport_color_slot(const char *slot)
{
if (!strcasecmp(slot, "reset"))
return TRANSPORT_COLOR_RESET;
if (!strcasecmp(slot, "rejected"))
return TRANSPORT_COLOR_REJECTED;
return -1;
}

static const char *transport_get_color(enum color_transport ix)
{
if (want_color(transport_use_color))
return transport_colors[ix];
return "";
}

static void set_upstreams(struct transport *transport, struct ref *refs,
int pretend)
Expand Down Expand Up @@ -326,7 +354,11 @@ static void print_ref_status(char flag, const char *summary,
else
fprintf(stdout, "%s\n", summary);
} else {
fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
if (strstr(summary, "rejected") != NULL || strstr(summary, "failure") != NULL)

This comment was marked as off-topic.

fprintf(stderr, " %s%c %-*s%s ", transport_get_color(TRANSPORT_COLOR_REJECTED),
flag, summary_width, summary, transport_get_color(TRANSPORT_COLOR_RESET));
else
fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
if (from)
fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
else
Expand Down