Skip to content

Commit eef2bda

Browse files
committed
push: do not use potentially ambiguous default refspec
When the user does the lazy "git push" with no parameters with push.default set to either "upstream", "simple" or "current", we internally generated a refspec that has the current branch name on the source side and used it to push. However, the branch name (say "test") may be an ambiguous refname in the context of the source repository---there may be a tag with the same name, for example. This would trigger an unnecessary error without any fault on the end-user's side. Be explicit and give a full refname as the source side to avoid the ambiguity. The destination side when pushing with the "current" sent only the name of the branch and forcing the receiving end to guess, which is the same issue. Be explicit there as well. Reported-by: Kannan Goundan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit eef2bda

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-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)

0 commit comments

Comments
 (0)