Skip to content

Commit 665d3e8

Browse files
Finn Arne Gangstadgitster
authored andcommitted
Display warning for default git push with no push.default config
If a git push without any refspecs is attempted, display a warning. The current default behavior is to push all matching refspecs, which may come as a surprise to new users, so the warning shows how push.default can be configured and what the possible values are. Traditionalists who wish to keep the current behaviour are also told how to configure this once and never see the warning again. Signed-off-by: Finn Arne Gangstad <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5215374 commit 665d3e8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Documentation/RelNotes-1.6.3.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ branch pointed at by its HEAD, gets a large warning. You can choose what
2222
should happen upon such a push by setting the configuration variable
2323
receive.denyDeleteCurrent in the receiving repository.
2424

25+
In a future release, the default of "git push" without further
26+
arguments might be changed. Currently, it will push all matching
27+
refspecs to the current remote. A configuration variable push.default
28+
has been introduced to select the default behaviour. To ease the
29+
transition, a big warning is issued if this is not configured and a
30+
git push without arguments is attempted.
31+
2532

2633
Updates since v1.6.2
2734
--------------------

builtin-push.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,34 @@ static void setup_push_tracking(void)
6464
add_refspec(refspec.buf);
6565
}
6666

67+
static const char *warn_unconfigured_push_msg[] = {
68+
"You did not specify any refspecs to push, and the current remote",
69+
"has not configured any push refspecs. The default action in this",
70+
"case is to push all matching refspecs, that is, all branches",
71+
"that exist both locally and remotely will be updated. This may",
72+
"not necessarily be what you want to happen.",
73+
"",
74+
"You can specify what action you want to take in this case, and",
75+
"avoid seeing this message again, by configuring 'push.default' to:",
76+
" 'nothing' : Do not push anythig",
77+
" 'matching' : Push all matching branches (default)",
78+
" 'tracking' : Push the current branch to whatever it is tracking",
79+
" 'current' : Push the current branch"
80+
};
81+
82+
static void warn_unconfigured_push(void)
83+
{
84+
int i;
85+
for (i = 0; i < ARRAY_SIZE(warn_unconfigured_push_msg); i++)
86+
warning("%s", warn_unconfigured_push_msg[i]);
87+
}
88+
6789
static void setup_default_push_refspecs(void)
6890
{
6991
git_config(git_default_config, NULL);
7092
switch (push_default) {
7193
case PUSH_DEFAULT_UNSPECIFIED:
94+
warn_unconfigured_push();
7295
/* fallthrough */
7396

7497
case PUSH_DEFAULT_MATCHING:

0 commit comments

Comments
 (0)