Skip to content

Commit 6c18dd4

Browse files
committed
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
2 parents 1d1bdaf + b284495 commit 6c18dd4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

builtin/push.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,18 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
194194
die_push_simple(branch, remote);
195195
}
196196

197-
strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
197+
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
198198
add_refspec(refspec.buf);
199199
}
200200

201201
static void setup_push_current(struct remote *remote, struct branch *branch)
202202
{
203+
struct strbuf refspec = STRBUF_INIT;
204+
203205
if (!branch)
204206
die(_(message_detached_head_die), remote->name);
205-
add_refspec(branch->name);
207+
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
208+
add_refspec(refspec.buf);
206209
}
207210

208211
static int is_workflow_triangular(struct remote *remote)

t/t5528-push-default.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ test_expect_success 'push from/to new branch with upstream, matching and simple'
9898
test_push_failure upstream
9999
'
100100

101+
test_expect_success 'push ambiguously named branch with upstream, matching and simple' '
102+
git checkout -b ambiguous &&
103+
test_config branch.ambiguous.remote parent1 &&
104+
test_config branch.ambiguous.merge refs/heads/ambiguous &&
105+
git tag ambiguous &&
106+
test_push_success simple ambiguous &&
107+
test_push_success matching ambiguous &&
108+
test_push_success upstream ambiguous
109+
'
110+
101111
test_expect_success 'push from/to new branch with current creates remote branch' '
102112
test_config branch.new-branch.remote repo1 &&
103113
git checkout new-branch &&

0 commit comments

Comments
 (0)