Skip to content

Commit dc66371

Browse files
committed
Merge branch 'gf/fetch-pack-direct-object-fetch' into maint
Fetching of history by naming a commit object name directly didn't work across remote-curl transport. * gf/fetch-pack-direct-object-fetch: fetch-pack: update the documentation for "<refs>..." arguments fetch-pack: fix object_id of exact sha1
2 parents 7488c2f + 754ecb1 commit dc66371

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

Documentation/git-fetch-pack.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ be in a separate packet, and the list must end with a flush packet.
104104
The remote heads to update from. This is relative to
105105
$GIT_DIR (e.g. "HEAD", "refs/heads/master"). When
106106
unspecified, update from all heads the remote side has.
107+
+
108+
If the remote has enabled the options `uploadpack.allowTipSHA1InWant` or
109+
`uploadpack.allowReachableSHA1InWant`, they may alternatively be 40-hex
110+
sha1s present on the remote.
107111

108112
SEE ALSO
109113
--------

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)