Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jk/push-simple'
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"
  • Loading branch information
Junio C Hamano committed Dec 12, 2014
2 parents 0ddedd4 + 00a6fa0 commit 23c0956
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
8 changes: 4 additions & 4 deletions builtin/push.c
Expand Up @@ -161,7 +161,7 @@ static const char message_detached_head_die[] =
" git push %s HEAD:<name-of-remote-branch>\n");

static void setup_push_upstream(struct remote *remote, struct branch *branch,
int triangular)
int triangular, int simple)
{
struct strbuf refspec = STRBUF_INIT;

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

if (push_default == PUSH_DEFAULT_SIMPLE) {
if (simple) {
/* Additional safety */
if (strcmp(branch->refname, branch->merge[0]->src))
die_push_simple(branch, remote);
Expand Down Expand Up @@ -257,11 +257,11 @@ static void setup_default_push_refspecs(struct remote *remote)
if (triangular)
setup_push_current(remote, branch);
else
setup_push_upstream(remote, branch, triangular);
setup_push_upstream(remote, branch, triangular, 1);
break;

case PUSH_DEFAULT_UPSTREAM:
setup_push_upstream(remote, branch, triangular);
setup_push_upstream(remote, branch, triangular, 0);
break;

case PUSH_DEFAULT_CURRENT:
Expand Down
32 changes: 30 additions & 2 deletions t/t5528-push-default.sh
Expand Up @@ -26,15 +26,15 @@ check_pushed_commit () {
# $2 = expected target branch for the push
# $3 = [optional] repo to check for actual output (repo1 by default)
test_push_success () {
git -c push.default="$1" push &&
git ${1:+-c push.default="$1"} push &&
check_pushed_commit HEAD "$2" "$3"
}

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

# default tests, when no push-default is specified. This
# should behave the same as "simple" in non-triangular
# settings, and as "current" otherwise.

test_expect_success 'default behavior allows "simple" push' '
test_config branch.master.remote parent1 &&
test_config branch.master.merge refs/heads/master &&
test_config remote.pushdefault parent1 &&
test_commit default-master-master &&
test_push_success "" master
'

test_expect_success 'default behavior rejects non-simple push' '
test_config branch.master.remote parent1 &&
test_config branch.master.merge refs/heads/foo &&
test_config remote.pushdefault parent1 &&
test_commit default-master-foo &&
test_push_failure ""
'

test_expect_success 'default triangular behavior acts like "current"' '
test_config branch.master.remote parent1 &&
test_config branch.master.merge refs/heads/foo &&
test_config remote.pushdefault parent2 &&
test_commit default-triangular &&
test_push_success "" master repo2
'

test_done

0 comments on commit 23c0956

Please sign in to comment.