diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-12-27 00:11:40 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-12-27 00:11:40 -0800 |
commit | 6c18dd4dc370284417938a252ba7f1a36ad51053 (patch) | |
tree | c59a2ad8ff56e6fca6ce1c8984273c7e4ae7532e | |
parent | 1d1bdafd64266e5ee3bd46c6965228f32e4022ea (diff) | |
parent | b284495e93394394f7c7923f6d646947844cec04 (diff) | |
download | git-6c18dd4dc370284417938a252ba7f1a36ad51053.tar.gz git-6c18dd4dc370284417938a252ba7f1a36ad51053.tar.xz |
Merge branch 'jc/push-default-explicit'
A lazy "git push" without refspec did not internally use a fully
specified refspec to perform 'current', 'simple', or 'upstream'
push, causing unnecessary "ambiguous ref" errors.
* jc/push-default-explicit:
push: test pushing ambiguously named branches
push: do not use potentially ambiguous default refspec
-rw-r--r-- | builtin/push.c | 7 | ||||
-rwxr-xr-x | t/t5528-push-default.sh | 10 |
2 files changed, 15 insertions, 2 deletions
diff --git a/builtin/push.c b/builtin/push.c index 3bb9d6b7e..9307ad56a 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -194,15 +194,18 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch, die_push_simple(branch, remote); } - strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src); + strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src); add_refspec(refspec.buf); } static void setup_push_current(struct remote *remote, struct branch *branch) { + struct strbuf refspec = STRBUF_INIT; + if (!branch) die(_(message_detached_head_die), remote->name); - add_refspec(branch->name); + strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname); + add_refspec(refspec.buf); } static int is_workflow_triangular(struct remote *remote) diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index 73f4bb634..44309566f 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -98,6 +98,16 @@ test_expect_success 'push from/to new branch with upstream, matching and simple' test_push_failure upstream ' +test_expect_success 'push ambiguously named branch with upstream, matching and simple' ' + git checkout -b ambiguous && + test_config branch.ambiguous.remote parent1 && + test_config branch.ambiguous.merge refs/heads/ambiguous && + git tag ambiguous && + test_push_success simple ambiguous && + test_push_success matching ambiguous && + test_push_success upstream ambiguous +' + test_expect_success 'push from/to new branch with current creates remote branch' ' test_config branch.new-branch.remote repo1 && git checkout new-branch && |