Skip to content

Commit dc1b0c0

Browse files
committed
Merge branch 'jk/unwanted-advices'
* jk/unwanted-advices: status: make "how to stage" messages optional push: make non-fast-forward help message configurable
2 parents 8b54f63 + edf563f commit dc1b0c0

File tree

8 files changed

+66
-1
lines changed

8 files changed

+66
-1
lines changed

Documentation/config.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ For command-specific variables, you will find a more detailed description
113113
in the appropriate manual page. You will find a description of non-core
114114
porcelain configuration variables in the respective porcelain documentation.
115115

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+
statusHints::
126+
Directions on how to stage/unstage/add shown in the
127+
output of linkgit:git-status[1] and the template shown
128+
when writing commit messages. Default: true.
129+
--
130+
116131
core.fileMode::
117132
If false, the executable bit differences between the index and
118133
the working copy are ignored; useful on broken filesystems like FAT.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export PERL_PATH
400400
LIB_FILE=libgit.a
401401
XDIFF_LIB=xdiff/lib.a
402402

403+
LIB_H += advice.h
403404
LIB_H += archive.h
404405
LIB_H += attr.h
405406
LIB_H += blob.h
@@ -457,6 +458,7 @@ LIB_H += utf8.h
457458
LIB_H += wt-status.h
458459

459460
LIB_OBJS += abspath.o
461+
LIB_OBJS += advice.o
460462
LIB_OBJS += alias.o
461463
LIB_OBJS += alloc.o
462464
LIB_OBJS += archive.o

advice.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "cache.h"
2+
3+
int advice_push_nonfastforward = 1;
4+
int advice_status_hints = 1;
5+
6+
static struct {
7+
const char *name;
8+
int *preference;
9+
} advice_config[] = {
10+
{ "pushnonfastforward", &advice_push_nonfastforward },
11+
{ "statushints", &advice_status_hints },
12+
};
13+
14+
int git_default_advice_config(const char *var, const char *value)
15+
{
16+
const char *k = skip_prefix(var, "advice.");
17+
int i;
18+
19+
for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
20+
if (strcmp(k, advice_config[i].name))
21+
continue;
22+
*advice_config[i].preference = git_config_bool(var, value);
23+
return 0;
24+
}
25+
26+
return 0;
27+
}

advice.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef ADVICE_H
2+
#define ADVICE_H
3+
4+
extern int advice_push_nonfastforward;
5+
extern int advice_status_hints;
6+
7+
int git_default_advice_config(const char *var, const char *value);
8+
9+
#endif /* ADVICE_H */

builtin-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int do_push(const char *repo, int flags)
157157
continue;
158158

159159
error("failed to push some refs to '%s'", url[i]);
160-
if (nonfastforward) {
160+
if (nonfastforward && advice_push_nonfastforward) {
161161
printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
162162
"Merge the remote changes before pushing again. See the 'non-fast forward'\n"
163163
"section of 'git push --help' for details.\n");

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "git-compat-util.h"
55
#include "strbuf.h"
66
#include "hash.h"
7+
#include "advice.h"
78

89
#include SHA1_HEADER
910
#ifndef git_SHA_CTX

config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ int git_default_config(const char *var, const char *value, void *dummy)
627627
if (!prefixcmp(var, "mailmap."))
628628
return git_default_mailmap_config(var, value);
629629

630+
if (!prefixcmp(var, "advice."))
631+
return git_default_advice_config(var, value);
632+
630633
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
631634
pager_use_color = git_config_bool(var,value);
632635
return 0;

wt-status.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
4848
{
4949
const char *c = color(WT_STATUS_HEADER, s);
5050
color_fprintf_ln(s->fp, c, "# Unmerged paths:");
51+
if (!advice_status_hints)
52+
return;
5153
if (!s->is_initial)
5254
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
5355
else
@@ -60,6 +62,8 @@ static void wt_status_print_cached_header(struct wt_status *s)
6062
{
6163
const char *c = color(WT_STATUS_HEADER, s);
6264
color_fprintf_ln(s->fp, c, "# Changes to be committed:");
65+
if (!advice_status_hints)
66+
return;
6367
if (!s->is_initial) {
6468
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
6569
} else {
@@ -73,6 +77,8 @@ static void wt_status_print_dirty_header(struct wt_status *s,
7377
{
7478
const char *c = color(WT_STATUS_HEADER, s);
7579
color_fprintf_ln(s->fp, c, "# Changed but not updated:");
80+
if (!advice_status_hints)
81+
return;
7682
if (!has_deleted)
7783
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
7884
else
@@ -85,6 +91,8 @@ static void wt_status_print_untracked_header(struct wt_status *s)
8591
{
8692
const char *c = color(WT_STATUS_HEADER, s);
8793
color_fprintf_ln(s->fp, c, "# Untracked files:");
94+
if (!advice_status_hints)
95+
return;
8896
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to include in what will be committed)");
8997
color_fprintf_ln(s->fp, c, "#");
9098
}

0 commit comments

Comments
 (0)