Skip to content

Commit

Permalink
push: make non-fast-forward help message configurable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Sep 12, 2009
1 parent 6ea71fe commit 7519443
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions advice.c
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions advice.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7519443

Please sign in to comment.