Skip to content

Commit

Permalink
Display warning for default git push with no push.default config
Browse files Browse the repository at this point in the history
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 <finnag@pvv.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Finn Arne Gangstad authored and Junio C Hamano committed Mar 17, 2009
1 parent 5215374 commit 665d3e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Documentation/RelNotes-1.6.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ branch pointed at by its HEAD, gets a large warning. You can choose what
should happen upon such a push by setting the configuration variable
receive.denyDeleteCurrent in the receiving repository.

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


Updates since v1.6.2
--------------------
Expand Down
23 changes: 23 additions & 0 deletions builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,34 @@ static void setup_push_tracking(void)
add_refspec(refspec.buf);
}

static const char *warn_unconfigured_push_msg[] = {
"You did not specify any refspecs to push, and the current remote",
"has not configured any push refspecs. The default action in this",
"case is to push all matching refspecs, that is, all branches",
"that exist both locally and remotely will be updated. This may",
"not necessarily be what you want to happen.",
"",
"You can specify what action you want to take in this case, and",
"avoid seeing this message again, by configuring 'push.default' to:",
" 'nothing' : Do not push anythig",
" 'matching' : Push all matching branches (default)",
" 'tracking' : Push the current branch to whatever it is tracking",
" 'current' : Push the current branch"
};

static void warn_unconfigured_push(void)
{
int i;
for (i = 0; i < ARRAY_SIZE(warn_unconfigured_push_msg); i++)
warning("%s", warn_unconfigured_push_msg[i]);
}

static void setup_default_push_refspecs(void)
{
git_config(git_default_config, NULL);
switch (push_default) {
case PUSH_DEFAULT_UNSPECIFIED:
warn_unconfigured_push();
/* fallthrough */

case PUSH_DEFAULT_MATCHING:
Expand Down

0 comments on commit 665d3e8

Please sign in to comment.