From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 7/7] push: add DWYM support for "git push refs/remotes/...:<dst>"
Date: Fri, 26 Oct 2018 19:27:34 +0000 [thread overview]
Message-ID: <20181026192734.9609-8-avarab@gmail.com> (raw)
In-Reply-To: <xmqq5zy8f6gr.fsf@gitster-ct.c.googlers.com>
Add DWYM support for pushing a ref in refs/remotes/* when the <dst>
ref is unqualified, e.g.:
git push origin refs/remotes/origin/master:upstream-master
Before this we wouldn't know what do do with
refs/remotes/origin/master, now we'll look it up and discover that
it's a commit (or tag) and add a refs/{heads,tags}/ prefix to <dst> as
appropriate.
I'm bending over backwards and assuming that someone might have hacked
in remote tracking tags (see [1] for a discussion of how that can be
done), but punting on any tree or blob objects found under
refs/remotes/*.
This is the first use of the %N$<fmt> style of printf format in
the *.[ch] files in our codebase, but it's supported by POSIX[2] and
there's existing uses for it in po/*.po files, so hopefully it won't
cause any trouble. It's more obvious for translators than to have a
3rd argument to the function identical to the 2nd, by re-using the 2nd
it's clear that we're continuing to talk about the <src> part of the
refspec.
1. https://public-inbox.org/git/87zi1jxjqn.fsf@evledraar.gmail.com/
2. http://pubs.opengroup.org/onlinepubs/7908799/xsh/fprintf.html
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
remote.c | 20 +++++++++++++++++++-
t/t5505-remote.sh | 14 +++++++++-----
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/remote.c b/remote.c
index 93f802509d..c243e3d89e 100644
--- a/remote.c
+++ b/remote.c
@@ -973,6 +973,21 @@ static char *guess_ref(const char *name, struct ref *peer)
strbuf_addstr(&buf, "refs/heads/");
} else if (starts_with(r, "refs/tags/")) {
strbuf_addstr(&buf, "refs/tags/");
+ } else if (starts_with(r, "refs/remotes/")) {
+ struct object_id oid;
+ enum object_type type;
+
+ if (get_oid(peer->name, &oid))
+ BUG("'%s' is not a valid object, "
+ "match_explicit_lhs() should catch this!",
+ peer->name);
+ type = oid_object_info(the_repository, &oid, NULL);
+ if (type == OBJ_COMMIT)
+ strbuf_addstr(&buf, "refs/heads/");
+ else if (type == OBJ_TAG)
+ strbuf_addstr(&buf, "refs/tags/");
+ else
+ return NULL;
} else {
return NULL;
}
@@ -1024,8 +1039,11 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
"- Checking if the <src> being pushed ('%s')\n"
" is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n"
" refs/{heads,tags}/ prefix on the remote side.\n"
+ "- Checking if the <src> being pushed ('%2$s')\n"
+ " is a commit or tag in \"refs/remotes/*\". Then we infer a\n"
+ " corresponding refs/{heads,tags} on the remote side.\n"
"\n"
- "Neither worked, so we gave up. You must fully-qualify the ref."),
+ "None of those worked, so we gave up. You must fully-qualify the ref."),
dst_value, matched_src_name);
if (!advice_push_unqualified_ref_name)
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 979a13b415..a6337b50e4 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -1260,11 +1260,15 @@ test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and
git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/two-blobs/*" &&
git fetch --no-tags two &&
- test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
- test_i18ngrep "error: The destination you" err &&
-
- test_must_fail git push origin refs/remotes/two-tags/some-tag:dst-tag 2>err &&
- test_i18ngrep "error: The destination you" err &&
+ echo commit >expected &&
+ git push origin refs/remotes/two/another:dst &&
+ git -C ../one cat-file -t refs/heads/dst >actual &&
+ test_cmp expected actual &&
+
+ echo tag >expected &&
+ git push origin refs/remotes/two-tags/some-tag:dst-tag &&
+ git -C ../one cat-file -t refs/tags/dst-tag >actual &&
+ test_cmp expected actual &&
test_must_fail git push origin refs/remotes/two-trees/my-head-tree:dst-tree 2>err &&
test_i18ngrep "error: The destination you" err &&
--
2.19.1.759.g500967bb5e
next prev parent reply other threads:[~2018-10-26 19:28 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-10 10:41 [PATCH 0/2] add an advice on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-10 10:41 ` [PATCH 1/2] i18n: remote.c: mark error(...) messages for translation Ævar Arnfjörð Bjarmason
2018-10-10 20:55 ` Jeff King
2018-10-10 10:41 ` [PATCH 2/2] push: add an advice on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-10 20:55 ` Jeff King
2018-10-10 21:23 ` Ævar Arnfjörð Bjarmason
2018-10-11 0:16 ` Jeff King
2018-10-11 22:45 ` Junio C Hamano
2018-10-26 15:45 ` Ævar Arnfjörð Bjarmason
2018-10-29 1:00 ` Junio C Hamano
2018-10-29 4:17 ` Junio C Hamano
2018-10-26 19:27 ` [PATCH v2 0/7] fixes for " Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 0/8] " Ævar Arnfjörð Bjarmason
2018-11-02 6:52 ` Jeff King
2018-11-13 19:52 ` [PATCH v4 0/7] " Ævar Arnfjörð Bjarmason
2018-11-14 7:00 ` Junio C Hamano
2018-11-13 19:52 ` [PATCH v4 1/7] remote.c: add braces in anticipation of a follow-up change Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 2/7] i18n: remote.c: mark error(...) messages for translation Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 3/7] push: improve the error shown on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 4/7] push: move unqualified refname error into a function Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 5/7] push: add an advice on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 6/7] push: test that <src> doesn't DWYM if <dst> is unqualified Ævar Arnfjörð Bjarmason
2018-11-13 19:52 ` [PATCH v4 7/7] push doc: document the DWYM behavior pushing to unqualified <dst> Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 1/8] remote.c: add braces in anticipation of a follow-up change Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 2/8] i18n: remote.c: mark error(...) messages for translation Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 3/8] push: improve the error shown on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-29 5:03 ` Junio C Hamano
2018-10-26 23:07 ` [PATCH v3 4/8] push: move unqualified refname error into a function Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 5/8] push: add an advice on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-29 5:14 ` Junio C Hamano
2018-11-02 6:47 ` Jeff King
2018-10-26 23:07 ` [PATCH v3 6/8] push: test that <src> doesn't DWYM if <dst> is unqualified Ævar Arnfjörð Bjarmason
2018-10-29 5:19 ` Junio C Hamano
2018-10-26 23:07 ` [PATCH v3 7/8] push: add DWYM support for "git push refs/remotes/...:<dst>" Ævar Arnfjörð Bjarmason
2018-10-29 5:24 ` Junio C Hamano
2018-10-29 8:13 ` Ævar Arnfjörð Bjarmason
2018-11-01 4:18 ` Junio C Hamano
2018-11-05 11:31 ` Ævar Arnfjörð Bjarmason
2018-11-05 12:29 ` Junio C Hamano
2018-10-29 7:06 ` Junio C Hamano
2018-10-29 7:57 ` Junio C Hamano
2018-10-29 8:05 ` Ævar Arnfjörð Bjarmason
2018-10-26 23:07 ` [PATCH v3 8/8] push doc: document the DWYM behavior pushing to unqualified <dst> Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` [PATCH v2 1/7] remote.c: add braces in anticipation of a follow-up change Ævar Arnfjörð Bjarmason
2018-10-26 21:05 ` Stefan Beller
2018-10-26 19:27 ` [PATCH v2 2/7] i18n: remote.c: mark error(...) messages for translation Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` [PATCH v2 3/7] push: improve the error shown on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` [PATCH v2 4/7] push: move unqualified refname error into a function Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` [PATCH v2 5/7] push: add an advice on unqualified <dst> push Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` [PATCH v2 6/7] push: test that <src> doesn't DWYM if <dst> is unqualified Ævar Arnfjörð Bjarmason
2018-10-26 19:27 ` Ævar Arnfjörð Bjarmason [this message]
2018-10-10 21:54 ` [PATCH 2/2] push: add an advice on unqualified <dst> push Junio C Hamano
2018-10-11 0:19 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181026192734.9609-8-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).