From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v2 3/3] push: also use "upstream" mapping when pushing a single ref
Date: Wed, 4 Dec 2013 17:27:29 -0800 [thread overview]
Message-ID: <1386206849-6503-4-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1386206849-6503-1-git-send-email-gitster@pobox.com>
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 <gitster@pobox.com>
---
builtin/push.c | 11 +++++++++++
t/t5516-fetch-push.sh | 30 ++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/builtin/push.c b/builtin/push.c
index 857f76d..9e47c29 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;
}
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 6d7f102..926e7f6 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1160,6 +1160,7 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' '
git pull ../testrepo master &&
git branch next &&
git config remote.dst.url ../dst &&
+ git config push.default matching &&
git push dst master &&
git show-ref refs/heads/master >../dst/expect
) &&
@@ -1171,6 +1172,35 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' '
test_cmp dst/expect dst/actual
'
+test_expect_success 'with no remote.$name.push, upstream mapping is used' '
+ mk_test testrepo heads/master &&
+ rm -fr src dst &&
+ git init src &&
+ git init --bare dst &&
+ (
+ cd src &&
+ git pull ../testrepo master &&
+ git branch next &&
+ git config remote.dst.url ../dst &&
+ git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
+ git config push.default upstream &&
+
+ git config branch.master.merge refs/heads/trunk &&
+ git config branch.master.remote dst &&
+
+ git push dst master &&
+ git show-ref refs/heads/master |
+ sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
+ ) &&
+ (
+ cd dst &&
+ test_must_fail git show-ref refs/heads/master &&
+ test_must_fail git show-ref refs/heads/next &&
+ git show-ref refs/heads/trunk >actual
+ ) &&
+ test_cmp dst/expect dst/actual
+'
+
test_expect_success 'push does not follow tags by default' '
mk_test testrepo heads/master &&
rm -fr src dst &&
--
1.8.5.1-402-gdd8f092
prev parent reply other threads:[~2013-12-05 1:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-04 0:39 [PATCH 0/3] Teaching "git push" to map pushed refs Junio C Hamano
2013-12-04 0:39 ` [PATCH 1/3] builtin/push.c: use strbuf instead of manual allocation Junio C Hamano
2013-12-04 0:39 ` [PATCH 2/3] push: use remote.$name.push as a refmap Junio C Hamano
2013-12-04 0:39 ` [PATCH 3/3] push: also use "upstream" mapping when pushing a single ref Junio C Hamano
2013-12-05 1:27 ` [PATCH v2 0/3] Teaching "git push" to map pushed refs Junio C Hamano
2013-12-05 1:27 ` [PATCH v2 1/3] builtin/push.c: use strbuf instead of manual allocation Junio C Hamano
2013-12-05 1:27 ` [PATCH v2 2/3] push: use remote.$name.push as a refmap Junio C Hamano
2013-12-05 1:27 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386206849-6503-4-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).