]> Pileus Git - ~andy/git/commitdiff
Merge branch 'jk/unwanted-advices'
authorJunio C Hamano <gitster@pobox.com>
Sun, 13 Sep 2009 08:33:18 +0000 (01:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Sep 2009 08:33:18 +0000 (01:33 -0700)
* jk/unwanted-advices:
  status: make "how to stage" messages optional
  push: make non-fast-forward help message configurable

Documentation/config.txt
Makefile
advice.c [new file with mode: 0644]
advice.h [new file with mode: 0644]
builtin-push.c
cache.h
config.c
wt-status.c

index 5256c7fb811ae6f5777bf528a22b19b16b132f26..8cbabe8012bbd8519592bcdfdc32d9dbb7e1ad03 100644 (file)
@@ -113,6 +113,21 @@ 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.
+       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::
        If false, the executable bit differences between the index and
        the working copy are ignored; useful on broken filesystems like FAT.
index 01eea770d3dc977403ff7630510c343ddc29e422..d4958b832a29412d0bc3656e98f0e8a2079fe492 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -400,6 +400,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
@@ -457,6 +458,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 (file)
index 0000000..ae4b1e8
--- /dev/null
+++ b/advice.c
@@ -0,0 +1,27 @@
+#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)
+{
+       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 (file)
index 0000000..e9df8e0
--- /dev/null
+++ b/advice.h
@@ -0,0 +1,9 @@
+#ifndef ADVICE_H
+#define ADVICE_H
+
+extern int advice_push_nonfastforward;
+extern int advice_status_hints;
+
+int git_default_advice_config(const char *var, const char *value);
+
+#endif /* ADVICE_H */
index 787011f928556972b287ca5621a5d462cd6e2543..6eda372a55ec72e1a26119ffdff0dd69456bdcf5 100644 (file)
@@ -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 1668f284f68ad3bdb0af56003b46c67fb2fd6b29..1a6412dfd65e6a2cc733f07a335d8b6b88b4264e 100644 (file)
--- 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
index bf122202a014160321d97444a9b3bf2b546f6f3f..c64406113686e8886c0719206ce57d73fee13b29 100644 (file)
--- 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;
index 85f3fcb8a2f55b362268e00c5bb67434e38382b0..38eb24536b34e40af4c43eb1631e08624e8993d6 100644 (file)
@@ -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 <file>...\" 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 <file>...\" 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 <file>...\" 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 <file>...\" to include in what will be committed)");
        color_fprintf_ln(s->fp, c, "#");
 }