Skip to content

Commit b2ed944

Browse files
committed
push: switch default from "matching" to "simple"
We promised to change the behaviour of lazy "git push [there]" that does not say what to push on the command line from "matching" to "simple" in Git 2.0. This finally flips that bit. Helped-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac47a22 commit b2ed944

File tree

5 files changed

+25
-48
lines changed

5 files changed

+25
-48
lines changed

Documentation/config.txt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,11 @@ advice.*::
142142
--
143143
pushNonFastForward::
144144
Set this variable to 'false' if you want to disable
145-
'pushNonFFCurrent', 'pushNonFFDefault', and
145+
'pushNonFFCurrent', and
146146
'pushNonFFMatching' simultaneously.
147147
pushNonFFCurrent::
148148
Advice shown when linkgit:git-push[1] fails due to a
149149
non-fast-forward update to the current branch.
150-
pushNonFFDefault::
151-
Advice to set 'push.default' to 'upstream' or 'current'
152-
when you ran linkgit:git-push[1] and pushed 'matching
153-
refs' by default (i.e. you did not provide an explicit
154-
refspec, and no 'push.default' configuration was set)
155-
and it resulted in a non-fast-forward error.
156150
pushNonFFMatching::
157151
Advice shown when you ran linkgit:git-push[1] and pushed
158152
'matching refs' explicitly (i.e. you used ':', or
@@ -1750,15 +1744,15 @@ push.default::
17501744
since locally stalled branches will attempt a non-fast forward push
17511745
if other users updated the branch.
17521746
+
1753-
This is currently the default, but Git 2.0 will change the default
1754-
to `simple`.
1747+
This used to be the default, and stale web sites may still say so,
1748+
but Git 2.0 has changed the default to `simple`.
17551749
* `upstream` - push the current branch to its upstream branch.
17561750
With this, `git push` will update the same remote ref as the one which
17571751
is merged by `git pull`, making `push` and `pull` symmetrical.
17581752
See "branch.<name>.merge" for how to configure the upstream branch.
17591753
* `simple` - like `upstream`, but refuses to push if the upstream
17601754
branch's name is different from the local one. This is the safest
1761-
option and is well-suited for beginners. It will become the default
1755+
option and is well-suited for beginners. It has become the default
17621756
in Git 2.0.
17631757
* `current` - push the current branch to a branch of the same name.
17641758
--

Documentation/git-push.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ OPTIONS[[OPTIONS]]
3636
The format of a <refspec> parameter is an optional plus
3737
`+`, followed by the source ref <src>, followed
3838
by a colon `:`, followed by the destination ref <dst>.
39-
It is used to specify with what <src> object the <dst> ref
40-
in the remote repository is to be updated. If not specified,
39+
It is used to specify what <src> object the <dst> ref
40+
in the remote repository is to be updated to. If no
41+
<refspec> is specified on the command line, and if no
42+
<refspec> is configured for the <repository>,
4143
the behavior of the command is controlled by the `push.default`
42-
configuration variable.
44+
configuration variable, and if it is unset, the `simple`
45+
behaviour is used (see lingit:git-config[1] and look
46+
for `push.default`).
4347
+
4448
The <src> is often the name of the branch you would want to push, but
4549
it can be any arbitrary "SHA-1 expression", such as `master~4` or
@@ -65,14 +69,11 @@ the remote repository.
6569
The special refspec `:` (or `+:` to allow non-fast-forward updates)
6670
directs git to push "matching" branches: for every branch that exists on
6771
the local side, the remote side is updated if a branch of the same name
68-
already exists on the remote side. This is the default operation mode
69-
if no explicit refspec is found (that is neither on the command line
70-
nor in any Push line of the corresponding remotes file---see below) and
71-
no `push.default` configuration variable is set.
72+
already exists on the remote side.
7273

7374
--all::
74-
Instead of naming each ref to push, specifies that all
75-
refs under `refs/heads/` be pushed.
75+
Push all branches (i.e. refs under `refs/heads/`); cannot be
76+
used with other <refspec>.
7677

7778
--prune::
7879
Remove remote branches that don't have a local counterpart. For example
@@ -357,8 +358,10 @@ Examples
357358
configured for the current branch).
358359

359360
`git push origin`::
360-
Without additional configuration, works like
361-
`git push origin :`.
361+
Without additional configuration, pushes the current branch to
362+
the configured upstream (`remote.origin.merge` configuration
363+
variable) if it has the same name as the current branch, and
364+
errors out without pushing otherwise.
362365
+
363366
The default behavior of this command when no <refspec> is given can be
364367
configured by setting the `push` option of the remote, or the `push.default`

advice.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
int advice_push_nonfastforward = 1;
44
int advice_push_non_ff_current = 1;
5-
int advice_push_non_ff_default = 1;
65
int advice_push_non_ff_matching = 1;
76
int advice_status_hints = 1;
87
int advice_commit_before_merge = 1;
@@ -16,7 +15,6 @@ static struct {
1615
} advice_config[] = {
1716
{ "pushnonfastforward", &advice_push_nonfastforward },
1817
{ "pushnonffcurrent", &advice_push_non_ff_current },
19-
{ "pushnonffdefault", &advice_push_non_ff_default },
2018
{ "pushnonffmatching", &advice_push_non_ff_matching },
2119
{ "statushints", &advice_status_hints },
2220
{ "commitbeforemerge", &advice_commit_before_merge },

advice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
extern int advice_push_nonfastforward;
77
extern int advice_push_non_ff_current;
8-
extern int advice_push_non_ff_default;
98
extern int advice_push_non_ff_matching;
109
extern int advice_status_hints;
1110
extern int advice_commit_before_merge;

builtin/push.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static int progress = -1;
2424
static const char **refspec;
2525
static int refspec_nr;
2626
static int refspec_alloc;
27-
static int default_matching_used;
2827

2928
static void add_refspec(const char *ref)
3029
{
@@ -148,9 +147,9 @@ static void setup_push_upstream(struct remote *remote, int simple)
148147
}
149148

150149
static char warn_unspecified_push_default_msg[] =
151-
N_("push.default is unset; its implicit value is changing in\n"
150+
N_("push.default is unset; its implicit value has changed in\n"
152151
"Git 2.0 from 'matching' to 'simple'. To squelch this message\n"
153-
"and maintain the current behavior after the default changes, use:\n"
152+
"and maintain the traditional behavior, use:\n"
154153
"\n"
155154
" git config --global push.default matching\n"
156155
"\n"
@@ -175,14 +174,14 @@ static void setup_default_push_refspecs(struct remote *remote)
175174
{
176175
switch (push_default) {
177176
default:
178-
case PUSH_DEFAULT_UNSPECIFIED:
179-
default_matching_used = 1;
180-
warn_unspecified_push_default_configuration();
181-
/* fallthru */
182177
case PUSH_DEFAULT_MATCHING:
183178
add_refspec(":");
184179
break;
185180

181+
case PUSH_DEFAULT_UNSPECIFIED:
182+
warn_unspecified_push_default_configuration();
183+
/* fallthru */
184+
186185
case PUSH_DEFAULT_SIMPLE:
187186
setup_push_upstream(remote, 1);
188187
break;
@@ -208,12 +207,6 @@ static const char message_advice_pull_before_push[] =
208207
"before pushing again.\n"
209208
"See the 'Note about fast-forwards' in 'git push --help' for details.");
210209

211-
static const char message_advice_use_upstream[] =
212-
N_("Updates were rejected because a pushed branch tip is behind its remote\n"
213-
"counterpart. If you did not intend to push that branch, you may want to\n"
214-
"specify branches to push or set the 'push.default' configuration variable\n"
215-
"to 'simple', 'current' or 'upstream' to push only the current branch.");
216-
217210
static const char message_advice_checkout_pull_push[] =
218211
N_("Updates were rejected because a pushed branch tip is behind its remote\n"
219212
"counterpart. Check out this branch and merge the remote changes\n"
@@ -227,13 +220,6 @@ static void advise_pull_before_push(void)
227220
advise(_(message_advice_pull_before_push));
228221
}
229222

230-
static void advise_use_upstream(void)
231-
{
232-
if (!advice_push_non_ff_default || !advice_push_nonfastforward)
233-
return;
234-
advise(_(message_advice_use_upstream));
235-
}
236-
237223
static void advise_checkout_pull_push(void)
238224
{
239225
if (!advice_push_non_ff_matching || !advice_push_nonfastforward)
@@ -272,10 +258,7 @@ static int push_with_options(struct transport *transport, int flags)
272258
advise_pull_before_push();
273259
break;
274260
case NON_FF_OTHER:
275-
if (default_matching_used)
276-
advise_use_upstream();
277-
else
278-
advise_checkout_pull_push();
261+
advise_checkout_pull_push();
279262
break;
280263
}
281264

0 commit comments

Comments
 (0)