Skip to content

Commit 0eeb9b8

Browse files
committed
Merge branch 'jk/push-simple' into maint
Git 2.0 was supposed to make the "simple" mode for the default of "git push", but it didn't. * jk/push-simple: push: truly use "simple" as default, not "upstream"
2 parents e524fb4 + 00a6fa0 commit 0eeb9b8

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

builtin/push.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static const char message_detached_head_die[] =
161161
" git push %s HEAD:<name-of-remote-branch>\n");
162162

163163
static void setup_push_upstream(struct remote *remote, struct branch *branch,
164-
int triangular)
164+
int triangular, int simple)
165165
{
166166
struct strbuf refspec = STRBUF_INIT;
167167

@@ -184,7 +184,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
184184
"to update which remote branch."),
185185
remote->name, branch->name);
186186

187-
if (push_default == PUSH_DEFAULT_SIMPLE) {
187+
if (simple) {
188188
/* Additional safety */
189189
if (strcmp(branch->refname, branch->merge[0]->src))
190190
die_push_simple(branch, remote);
@@ -257,11 +257,11 @@ static void setup_default_push_refspecs(struct remote *remote)
257257
if (triangular)
258258
setup_push_current(remote, branch);
259259
else
260-
setup_push_upstream(remote, branch, triangular);
260+
setup_push_upstream(remote, branch, triangular, 1);
261261
break;
262262

263263
case PUSH_DEFAULT_UPSTREAM:
264-
setup_push_upstream(remote, branch, triangular);
264+
setup_push_upstream(remote, branch, triangular, 0);
265265
break;
266266

267267
case PUSH_DEFAULT_CURRENT:

t/t5528-push-default.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ check_pushed_commit () {
2626
# $2 = expected target branch for the push
2727
# $3 = [optional] repo to check for actual output (repo1 by default)
2828
test_push_success () {
29-
git -c push.default="$1" push &&
29+
git ${1:+-c push.default="$1"} push &&
3030
check_pushed_commit HEAD "$2" "$3"
3131
}
3232

3333
# $1 = push.default value
3434
# check that push fails and does not modify any remote branch
3535
test_push_failure () {
3636
git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect &&
37-
test_must_fail git -c push.default="$1" push &&
37+
test_must_fail git ${1:+-c push.default="$1"} push &&
3838
git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual &&
3939
test_cmp expect actual
4040
}
@@ -172,4 +172,32 @@ test_pushdefault_workflow success simple master triangular
172172
# master is updated (parent2 does not have foo)
173173
test_pushdefault_workflow success matching master triangular
174174

175+
# default tests, when no push-default is specified. This
176+
# should behave the same as "simple" in non-triangular
177+
# settings, and as "current" otherwise.
178+
179+
test_expect_success 'default behavior allows "simple" push' '
180+
test_config branch.master.remote parent1 &&
181+
test_config branch.master.merge refs/heads/master &&
182+
test_config remote.pushdefault parent1 &&
183+
test_commit default-master-master &&
184+
test_push_success "" master
185+
'
186+
187+
test_expect_success 'default behavior rejects non-simple push' '
188+
test_config branch.master.remote parent1 &&
189+
test_config branch.master.merge refs/heads/foo &&
190+
test_config remote.pushdefault parent1 &&
191+
test_commit default-master-foo &&
192+
test_push_failure ""
193+
'
194+
195+
test_expect_success 'default triangular behavior acts like "current"' '
196+
test_config branch.master.remote parent1 &&
197+
test_config branch.master.merge refs/heads/foo &&
198+
test_config remote.pushdefault parent2 &&
199+
test_commit default-triangular &&
200+
test_push_success "" master repo2
201+
'
202+
175203
test_done

0 commit comments

Comments
 (0)