git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Matt McCutchen <matt@mattmccutchen.net>
To: git@vger.kernel.org
Subject: [PATCH v2 2/3] fetch_refs_via_pack: call report_unmatched_refs
Date: Wed, 22 Feb 2017 11:02:15 -0500	[thread overview]
Message-ID: <88eff6268d0f2e447c19a1b43fd5c7a827314bf5.1487784184.git.matt@mattmccutchen.net> (raw)
In-Reply-To: <xmqqpoiacfqw.fsf@gitster.mtv.corp.google.com>

"git fetch" currently doesn't bother to check that it got all refs it
sought, because the common case of requesting a nonexistent ref triggers
a die() in get_fetch_map.  However, there's at least one case that
slipped through: "git fetch REMOTE SHA1" if the server doesn't allow
requests for unadvertised objects.  Make fetch_refs_via_pack (which is
on the "git fetch" code path) call report_unmatched_refs so that we at
least get an error message in that case.

Signed-off-by: Matt McCutchen <matt@mattmccutchen.net>
---
 t/t5516-fetch-push.sh |  3 ++-
 transport.c           | 14 +++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 26b2caf..0d13a45 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1098,7 +1098,8 @@ test_expect_success 'fetch exact SHA1' '
 		test_must_fail git cat-file -t $the_commit &&
 
 		# fetching the hidden object should fail by default
-		test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
+		test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
+		test_i18ngrep "no such remote ref" err &&
 		test_must_fail git rev-parse --verify refs/heads/copy &&
 
 		# the server side can allow it to succeed
diff --git a/transport.c b/transport.c
index 04e5d66..c377907 100644
--- a/transport.c
+++ b/transport.c
@@ -204,6 +204,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
 static int fetch_refs_via_pack(struct transport *transport,
 			       int nr_heads, struct ref **to_fetch)
 {
+	int ret = 0;
 	struct git_transport_data *data = transport->data;
 	struct ref *refs;
 	char *dest = xstrdup(transport->url);
@@ -241,19 +242,22 @@ static int fetch_refs_via_pack(struct transport *transport,
 			  &transport->pack_lockfile);
 	close(data->fd[0]);
 	close(data->fd[1]);
-	if (finish_connect(data->conn)) {
-		free_refs(refs);
-		refs = NULL;
-	}
+	if (finish_connect(data->conn))
+		ret = -1;
 	data->conn = NULL;
 	data->got_remote_heads = 0;
 	data->options.self_contained_and_connected =
 		args.self_contained_and_connected;
 
+	if (refs == NULL)
+		ret = -1;
+	if (report_unmatched_refs(to_fetch, nr_heads))
+		ret = -1;
+
 	free_refs(refs_tmp);
 	free_refs(refs);
 	free(dest);
-	return (refs ? 0 : -1);
+	return ret;
 }
 
 static int push_had_errors(struct ref *ref)
-- 
2.9.3



  parent reply	other threads:[~2017-02-22 17:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 17:26 [PATCH] fetch: print an error when declining to request an unadvertised object Matt McCutchen
2017-02-10 18:36 ` Junio C Hamano
2017-02-12 21:13   ` Matt McCutchen
2017-02-12 23:49     ` Junio C Hamano
2017-02-19  1:55       ` Matt McCutchen
2017-02-21  6:36         ` Junio C Hamano
2017-02-22 16:01           ` [PATCH 1/3] fetch-pack: move code to report unmatched refs to a function Matt McCutchen
2017-02-22 17:11             ` Junio C Hamano
2017-02-22 16:01               ` [PATCH v2 " Matt McCutchen
2017-02-22 16:02               ` Matt McCutchen [this message]
2017-02-22 16:05               ` [PATCH v2 3/3] fetch-pack: add specific error for fetching an unadvertised object Matt McCutchen
2017-02-22 17:26               ` [PATCH 1/3] fetch-pack: move code to report unmatched refs to a function Matt McCutchen
2017-02-22 16:02           ` [PATCH 2/3] fetch_refs_via_pack: call report_unmatched_refs Matt McCutchen
2017-02-22 16:05           ` [PATCH 3/3] fetch-pack: add specific error for fetching an unadvertised object Matt McCutchen
2017-02-22 16:17           ` [PATCH] fetch: print an error when declining to request " Matt McCutchen
2017-02-22 17:07             ` Junio C Hamano
2017-02-19  2:07       ` Matt McCutchen

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=88eff6268d0f2e447c19a1b43fd5c7a827314bf5.1487784184.git.matt@mattmccutchen.net \
    --to=matt@mattmccutchen.net \
    --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.
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).