@matheusbsbs / matheus-bagliano / commits / 75194438f4
Fork 0

push: make non-fast-forward help message configurable

This message is designed to help new users understand what has happened when refs fail to push. However, it does not help experienced users at all, and significantly clutters the output, frequently dwarfing the regular status table and making it harder to see. This patch introduces a general configuration mechanism for optional messages, with this push message as the first example. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 9, 2009 at 07:38 UTC 75194438f412714f4e82ca01e9038dc6714498c4
7 files changed +51 -1
Documentation/config.txt
+11
@@ -113,6 +113,17 @@ For command-specific variables, you will find a more detailed description
113 in the appropriate manual page. You will find a description of non-core
114 porcelain configuration variables in the respective porcelain documentation.
115
116 +advice.*::
117 + When set to 'true', display the given optional help message.
118 + When set to 'false', do not display. The configuration variables
119 + are:
120 ++
121 +--
122 + pushNonFastForward::
123 + Advice shown when linkgit:git-push[1] refuses
124 + non-fast-forward refs. Default: true.
125 +--
126 +
127 core.fileMode::
128 If false, the executable bit differences between the index and
129 the working copy are ignored; useful on broken filesystems like FAT.
Makefile
+2
@@ -397,6 +397,7 @@ export PERL_PATH
397 LIB_FILE=libgit.a
398 XDIFF_LIB=xdiff/lib.a
399
400 +LIB_H += advice.h
401 LIB_H += archive.h
402 LIB_H += attr.h
403 LIB_H += blob.h
@@ -454,6 +455,7 @@ LIB_H += utf8.h
455 LIB_H += wt-status.h
456
457 LIB_OBJS += abspath.o
458 +LIB_OBJS += advice.o
459 LIB_OBJS += alias.o
460 LIB_OBJS += alloc.o
461 LIB_OBJS += archive.o
advice.c new
+25
@@ -0,0 +1,25 @@
1 +#include "cache.h"
2 +
3 +int advice_push_nonfastforward = 1;
4 +
5 +static struct {
6 + const char *name;
7 + int *preference;
8 +} advice_config[] = {
9 + { "pushnonfastforward", &advice_push_nonfastforward },
10 +};
11 +
12 +int git_default_advice_config(const char *var, const char *value)
13 +{
14 + const char *k = skip_prefix(var, "advice.");
15 + int i;
16 +
17 + for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
18 + if (strcmp(k, advice_config[i].name))
19 + continue;
20 + *advice_config[i].preference = git_config_bool(var, value);
21 + return 0;
22 + }
23 +
24 + return 0;
25 +}
advice.h new
+8
@@ -0,0 +1,8 @@
1 +#ifndef ADVICE_H
2 +#define ADVICE_H
3 +
4 +extern int advice_push_nonfastforward;
5 +
6 +int git_default_advice_config(const char *var, const char *value);
7 +
8 +#endif /* ADVICE_H */
builtin-push.c
+1 -1
@@ -157,7 +157,7 @@ static int do_push(const char *repo, int flags)
157 continue;
158
159 error("failed to push some refs to '%s'", url[i]);
160 - if (nonfastforward) {
160 + if (nonfastforward && advice_push_nonfastforward) {
161 printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
162 "Merge the remote changes before pushing again. See the 'non-fast forward'\n"
163 "section of 'git push --help' for details.\n");
cache.h
+1
@@ -4,6 +4,7 @@
4 #include "git-compat-util.h"
5 #include "strbuf.h"
6 #include "hash.h"
7 +#include "advice.h"
8
9 #include SHA1_HEADER
10 #ifndef git_SHA_CTX
config.c
+3
@@ -627,6 +627,9 @@ int git_default_config(const char *var, const char *value, void *dummy)
627 if (!prefixcmp(var, "mailmap."))
628 return git_default_mailmap_config(var, value);
629
630 + if (!prefixcmp(var, "advice."))
631 + return git_default_advice_config(var, value);
632 +
633 if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
634 pager_use_color = git_config_bool(var,value);
635 return 0;