From fc9261ca611080b1dae76b86b3bf5f36d592042f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 3 Dec 2013 16:23:35 -0800 Subject: push: also use "upstream" mapping when pushing a single ref When the user is using the 'upstream' mode, these commands: $ git push $ git push origin would find the 'upstream' branch for the current branch, and then push the current branch to update it. However, pushing a single branch explicitly, i.e. $ git push origin $(git symbolic-ref --short HEAD) would not go through the same ref mapping process, and ends up updating the branch at 'origin' of the same name, which may not necessarily be the upstream of the branch being pushed. In the spirit similar to the previous one, map a colon-less refspec using the upstream mapping logic. Signed-off-by: Junio C Hamano --- builtin/push.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'builtin/push.c') diff --git a/builtin/push.c b/builtin/push.c index 857f76d85a..9e47c29a36 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -58,6 +58,17 @@ static const char *map_refspec(const char *ref, } } + if (push_default == PUSH_DEFAULT_UPSTREAM && + !prefixcmp(matched->name, "refs/heads/")) { + struct branch *branch = branch_get(matched->name + 11); + if (branch->merge_nr == 1 && branch->merge[0]->src) { + struct strbuf buf = STRBUF_INIT; + strbuf_addf(&buf, "%s:%s", + ref, branch->merge[0]->src); + return strbuf_detach(&buf, NULL); + } + } + return ref; } -- cgit v1.2.1