Merge branch 'js/colored-push-errors'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:34 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:34 +0000 (15:59 +0900)
Error messages from "git push" can be painted for more visibility.

* js/colored-push-errors:
  config: document the settings to colorize push errors/hints
  push: test to verify that push errors are colored
  push: colorize errors
  color: introduce support for colorizing stderr

1  2 
Documentation/config.txt
config.c
transport.c

Simple merge
diff --cc config.c
Simple merge
diff --cc transport.c
  #include "sha1-array.h"
  #include "sigchain.h"
  #include "transport-internal.h"
 +#include "protocol.h"
  #include "object-store.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 transport_color_config(void)
+ {
+       const char *keys[] = {
+               "color.transport.reset",
+               "color.transport.rejected"
+       }, *key = "color.transport";
+       char *value;
+       int i;
+       static int initialized;
+       if (initialized)
+               return 0;
+       initialized = 1;
+       if (!git_config_get_string(key, &value))
+               transport_use_color = git_config_colorbool(key, value);
+       if (!want_color_stderr(transport_use_color))
+               return 0;
+       for (i = 0; i < ARRAY_SIZE(keys); i++)
+               if (!git_config_get_string(keys[i], &value)) {
+                       if (!value)
+                               return config_error_nonbool(keys[i]);
+                       if (color_parse(value, transport_colors[i]) < 0)
+                               return -1;
+               }
+       return 0;
+ }
+ static const char *transport_get_color(enum color_transport ix)
+ {
+       if (want_color_stderr(transport_use_color))
+               return transport_colors[ix];
+       return "";
+ }
  
  static void set_upstreams(struct transport *transport, struct ref *refs,
        int pretend)
@@@ -586,10 -611,19 +645,13 @@@ static int git_transport_push(struct tr
  {
        struct git_transport_data *data = transport->data;
        struct send_pack_args args;
 -      int ret;
 +      int ret = 0;
  
 -      if (!data->got_remote_heads) {
 -              struct ref *tmp_refs;
 -              connect_setup(transport, 1);
 -
 -              get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL,
 -                               NULL, &data->shallow);
 -              data->got_remote_heads = 1;
 -      }
+       if (transport_color_config() < 0)
+               return -1;
 +      if (!data->got_remote_heads)
 +              get_refs_via_connect(transport, 1, NULL);
  
        memset(&args, 0, sizeof(args));
        args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);