From 75194438f412714f4e82ca01e9038dc6714498c4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 9 Sep 2009 07:38:58 -0400 Subject: [PATCH 1/2] 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 Signed-off-by: Junio C Hamano --- Documentation/config.txt | 11 +++++++++++ Makefile | 2 ++ advice.c | 25 +++++++++++++++++++++++++ advice.h | 8 ++++++++ builtin-push.c | 2 +- cache.h | 1 + config.c | 3 +++ 7 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 advice.c create mode 100644 advice.h diff --git a/Documentation/config.txt b/Documentation/config.txt index 5256c7fb81..a35b9181bc 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -113,6 +113,17 @@ For command-specific variables, you will find a more detailed description in the appropriate manual page. You will find a description of non-core porcelain configuration variables in the respective porcelain documentation. +advice.*:: + When set to 'true', display the given optional help message. + When set to 'false', do not display. The configuration variables + are: ++ +-- + pushNonFastForward:: + Advice shown when linkgit:git-push[1] refuses + non-fast-forward refs. Default: true. +-- + core.fileMode:: If false, the executable bit differences between the index and the working copy are ignored; useful on broken filesystems like FAT. diff --git a/Makefile b/Makefile index a614347568..9d9ff45fb2 100644 --- a/Makefile +++ b/Makefile @@ -397,6 +397,7 @@ export PERL_PATH LIB_FILE=libgit.a XDIFF_LIB=xdiff/lib.a +LIB_H += advice.h LIB_H += archive.h LIB_H += attr.h LIB_H += blob.h @@ -454,6 +455,7 @@ LIB_H += utf8.h LIB_H += wt-status.h LIB_OBJS += abspath.o +LIB_OBJS += advice.o LIB_OBJS += alias.o LIB_OBJS += alloc.o LIB_OBJS += archive.o diff --git a/advice.c b/advice.c new file mode 100644 index 0000000000..b5216a2456 --- /dev/null +++ b/advice.c @@ -0,0 +1,25 @@ +#include "cache.h" + +int advice_push_nonfastforward = 1; + +static struct { + const char *name; + int *preference; +} advice_config[] = { + { "pushnonfastforward", &advice_push_nonfastforward }, +}; + +int git_default_advice_config(const char *var, const char *value) +{ + const char *k = skip_prefix(var, "advice."); + int i; + + for (i = 0; i < ARRAY_SIZE(advice_config); i++) { + if (strcmp(k, advice_config[i].name)) + continue; + *advice_config[i].preference = git_config_bool(var, value); + return 0; + } + + return 0; +} diff --git a/advice.h b/advice.h new file mode 100644 index 0000000000..862bae37b8 --- /dev/null +++ b/advice.h @@ -0,0 +1,8 @@ +#ifndef ADVICE_H +#define ADVICE_H + +extern int advice_push_nonfastforward; + +int git_default_advice_config(const char *var, const char *value); + +#endif /* ADVICE_H */ diff --git a/builtin-push.c b/builtin-push.c index 787011f928..6eda372a55 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -157,7 +157,7 @@ static int do_push(const char *repo, int flags) continue; error("failed to push some refs to '%s'", url[i]); - if (nonfastforward) { + if (nonfastforward && advice_push_nonfastforward) { printf("To prevent you from losing history, non-fast-forward updates were rejected\n" "Merge the remote changes before pushing again. See the 'non-fast forward'\n" "section of 'git push --help' for details.\n"); diff --git a/cache.h b/cache.h index 5fad24ce21..e1ab09292f 100644 --- a/cache.h +++ b/cache.h @@ -4,6 +4,7 @@ #include "git-compat-util.h" #include "strbuf.h" #include "hash.h" +#include "advice.h" #include SHA1_HEADER #ifndef git_SHA_CTX diff --git a/config.c b/config.c index e87edeab0c..f21530cdbd 100644 --- a/config.c +++ b/config.c @@ -627,6 +627,9 @@ int git_default_config(const char *var, const char *value, void *dummy) if (!prefixcmp(var, "mailmap.")) return git_default_mailmap_config(var, value); + if (!prefixcmp(var, "advice.")) + return git_default_advice_config(var, value); + if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { pager_use_color = git_config_bool(var,value); return 0; From edf563fbaa2ab50734db4a61e9092f25fbb5a417 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 9 Sep 2009 07:43:03 -0400 Subject: [PATCH 2/2] status: make "how to stage" messages optional These messages are nice for new users, but experienced git users know how to manipulate the index, and these messages waste a lot of screen real estate. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++++ advice.c | 2 ++ advice.h | 1 + wt-status.c | 8 ++++++++ 4 files changed, 15 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index a35b9181bc..8cbabe8012 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -122,6 +122,10 @@ advice.*:: pushNonFastForward:: Advice shown when linkgit:git-push[1] refuses non-fast-forward refs. Default: true. + statusHints:: + Directions on how to stage/unstage/add shown in the + output of linkgit:git-status[1] and the template shown + when writing commit messages. Default: true. -- core.fileMode:: diff --git a/advice.c b/advice.c index b5216a2456..ae4b1e81df 100644 --- a/advice.c +++ b/advice.c @@ -1,12 +1,14 @@ #include "cache.h" int advice_push_nonfastforward = 1; +int advice_status_hints = 1; static struct { const char *name; int *preference; } advice_config[] = { { "pushnonfastforward", &advice_push_nonfastforward }, + { "statushints", &advice_status_hints }, }; int git_default_advice_config(const char *var, const char *value) diff --git a/advice.h b/advice.h index 862bae37b8..e9df8e026c 100644 --- a/advice.h +++ b/advice.h @@ -2,6 +2,7 @@ #define ADVICE_H extern int advice_push_nonfastforward; +extern int advice_status_hints; int git_default_advice_config(const char *var, const char *value); diff --git a/wt-status.c b/wt-status.c index 85f3fcb8a2..38eb24536b 100644 --- a/wt-status.c +++ b/wt-status.c @@ -48,6 +48,8 @@ static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + if (!advice_status_hints) + return; if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); else @@ -60,6 +62,8 @@ static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Changes to be committed:"); + if (!advice_status_hints) + return; if (!s->is_initial) { color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); } else { @@ -73,6 +77,8 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Changed but not updated:"); + if (!advice_status_hints) + return; if (!has_deleted) color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to update what will be committed)"); else @@ -85,6 +91,8 @@ static void wt_status_print_untracked_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Untracked files:"); + if (!advice_status_hints) + return; color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to include in what will be committed)"); color_fprintf_ln(s->fp, c, "#"); }