Skip to content

Commit 4a8d202

Browse files
gbsfgitster
authored andcommitted
fetch-pack: fix object_id of exact sha1
Commit 58f2ed0 (remote-curl: pass ref SHA-1 to fetch-pack as well, 2013-12-05) added support for specifying a SHA-1 as well as a ref name. Add support for specifying just a SHA-1 and set the ref name to the same value in this case. Signed-off-by: Gabriel Souza Franco <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f02fbc4 commit 4a8d202

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

builtin/fetch-pack.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
1616
struct ref *ref;
1717
struct object_id oid;
1818

19-
if (!get_oid_hex(name, &oid) && name[GIT_SHA1_HEXSZ] == ' ')
20-
name += GIT_SHA1_HEXSZ + 1;
21-
else
19+
if (!get_oid_hex(name, &oid)) {
20+
if (name[GIT_SHA1_HEXSZ] == ' ') {
21+
/* <sha1> <ref>, find refname */
22+
name += GIT_SHA1_HEXSZ + 1;
23+
} else if (name[GIT_SHA1_HEXSZ] == '\0') {
24+
; /* <sha1>, leave sha1 as name */
25+
} else {
26+
/* <ref>, clear cruft from oid */
27+
oidclr(&oid);
28+
}
29+
} else {
30+
/* <ref>, clear cruft from get_oid_hex */
2231
oidclr(&oid);
32+
}
2333

2434
ref = alloc_ref(name);
2535
oidcpy(&ref->old_oid, &oid);

t/t5500-fetch-pack.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,20 @@ test_expect_success 'shallow fetch with tags does not break the repository' '
531531
git fsck
532532
)
533533
'
534+
535+
test_expect_success 'fetch-pack can fetch a raw sha1' '
536+
git init hidden &&
537+
(
538+
cd hidden &&
539+
test_commit 1 &&
540+
test_commit 2 &&
541+
git update-ref refs/hidden/one HEAD^ &&
542+
git config transfer.hiderefs refs/hidden &&
543+
git config uploadpack.allowtipsha1inwant true
544+
) &&
545+
git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
546+
'
547+
534548
check_prot_path () {
535549
cat >expected <<-EOF &&
536550
Diag: url=$1

0 commit comments

Comments
 (0)