Skip to content

Commit 6c301ad

Browse files
jrngitster
authored andcommitted
fetch: do not pass ref-prefixes for fetch by exact SHA1
When v2.18.0-rc0~10^2~1 (refspec: consolidate ref-prefix generation logic, 2018-05-16) factored out the ref-prefix generation code for reuse, it left out the 'if (!item->exact_sha1)' test in the original ref-prefix generation code. As a result, fetches by SHA-1 generate ref-prefixes as though the SHA-1 being fetched were an abbreviated ref name: $ GIT_TRACE_PACKET=1 bin-wrappers/git -c protocol.version=2 \ fetch origin 12039e0 [...] packet: fetch> ref-prefix 12039e0 packet: fetch> ref-prefix refs/12039e008f9a4e3394f3f94f8ea897785cb09448 packet: fetch> ref-prefix refs/tags/12039e008f9a4e3394f3f94f8ea897785cb09448 packet: fetch> ref-prefix refs/heads/12039e008f9a4e3394f3f94f8ea897785cb09448 packet: fetch> ref-prefix refs/remotes/12039e008f9a4e3394f3f94f8ea897785cb09448 packet: fetch> ref-prefix refs/remotes/12039e008f9a4e3394f3f94f8ea897785cb09448/HEAD packet: fetch> 0000 If there is another ref name on the command line or the object being fetched is already available locally, then that's mostly harmless. But otherwise, we error out with fatal: no matching remote head since the server did not send any refs we are interested in. Filter out the exact_sha1 refspecs to avoid this. This patch adds a test to check this behavior that notices another behavior difference between protocol v0 and v2 in the process. Add a NEEDSWORK comment to clear it up. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcc73cf commit 6c301ad

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

refspec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ void refspec_ref_prefixes(const struct refspec *rs,
202202
const struct refspec_item *item = &rs->items[i];
203203
const char *prefix = NULL;
204204

205+
if (item->exact_sha1)
206+
continue;
205207
if (rs->fetch == REFSPEC_FETCH)
206208
prefix = item->src;
207209
else if (item->dst)

refspec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ void refspec_clear(struct refspec *rs);
4242
int valid_fetch_refspec(const char *refspec);
4343
4444
struct argv_array;
45+
/*
46+
* Determine what <prefix> values to pass to the peer in ref-prefix lines
47+
* (see Documentation/technical/protocol-v2.txt).
48+
*/
4549
void refspec_ref_prefixes(const struct refspec *rs,
4650
struct argv_array *ref_prefixes);
4751

t/t5516-fetch-push.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,25 @@ test_expect_success 'fetch exact SHA1' '
11211121
)
11221122
'
11231123

1124+
test_expect_success 'fetch exact SHA1 in protocol v2' '
1125+
mk_test testrepo heads/master hidden/one &&
1126+
git push testrepo master:refs/hidden/one &&
1127+
git -C testrepo config transfer.hiderefs refs/hidden &&
1128+
check_push_result testrepo $the_commit hidden/one &&
1129+
1130+
mk_child testrepo child &&
1131+
git -C child config protocol.version 2 &&
1132+
1133+
# make sure $the_commit does not exist here
1134+
git -C child repack -a -d &&
1135+
git -C child prune &&
1136+
test_must_fail git -C child cat-file -t $the_commit &&
1137+
1138+
# fetching the hidden object succeeds by default
1139+
# NEEDSWORK: should this match the v0 behavior instead?
1140+
git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1141+
'
1142+
11241143
for configallowtipsha1inwant in true false
11251144
do
11261145
test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '

0 commit comments

Comments
 (0)