Skip to content

Commit 179ccd7

Browse files
committed
adapt to changes in git-protocol (#450)
1 parent cd867ad commit 179ccd7

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

git-repository/src/remote/connection/fetch/negotiate.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ pub(crate) fn one_round(
3535
.and_then(|r| r.target().try_id().map(ToOwned::to_owned))
3636
});
3737
match have_id {
38-
Some(have_id) if mapping.remote.as_id() != have_id => {
39-
arguments.want(mapping.remote.as_id());
40-
arguments.have(have_id);
38+
Some(have_id) => {
39+
if let Some(want_id) = mapping.remote.as_id() {
40+
if want_id != have_id {
41+
arguments.want(want_id);
42+
arguments.have(have_id);
43+
}
44+
}
4145
}
42-
Some(_) => {}
4346
None => {
44-
arguments.want(mapping.remote.as_id());
45-
has_missing_tracking_branch = true;
47+
if let Some(have_id) = mapping.remote.as_id() {
48+
arguments.want(have_id);
49+
has_missing_tracking_branch = true;
50+
}
4651
}
4752
}
4853
}

git-repository/src/remote/connection/fetch/update_refs/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ pub(crate) fn update(
5656
spec_index,
5757
}| refspecs.get(*spec_index).map(|spec| (remote, local, spec)),
5858
) {
59-
let remote_id = remote.as_id();
59+
let remote_id = match remote.as_id() {
60+
Some(id) => id,
61+
None => continue,
62+
};
6063
if dry_run == fetch::DryRun::No && !repo.objects.contains(remote_id) {
6164
updates.push(update::Mode::RejectedSourceObjectNotFound { id: remote_id.into() }.into());
6265
continue;

git-repository/src/remote/connection/fetch/update_refs/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ mod update {
487487
let (full_ref_name, target, object) = r.unpack();
488488
git_refspec::match_group::Item {
489489
full_ref_name,
490-
target,
490+
target: target.expect("no unborn HEAD"),
491491
object,
492492
}
493493
}

git-repository/src/remote/connection/ref_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ where
8282
handshake_parameters,
8383
}: Options,
8484
) -> Result<fetch::RefMap, Error> {
85+
static NULL: git_hash::ObjectId = git_hash::ObjectId::null(git_hash::Kind::Sha1); // OK to hardcode Sha1, it's not supposed to match, ever.
8586
let remote = self
8687
.fetch_refs(prefix_from_spec_as_filter_on_remote, handshake_parameters)
8788
.await?;
@@ -91,7 +92,7 @@ where
9192
let (full_ref_name, target, object) = r.unpack();
9293
git_refspec::match_group::Item {
9394
full_ref_name,
94-
target,
95+
target: target.unwrap_or(&NULL),
9596
object,
9697
}
9798
}))

git-repository/src/remote/fetch.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ pub enum Source {
4141
impl Source {
4242
/// Return either the direct object id we refer to or the direct target that a reference refers to.
4343
/// The latter may be a direct or a symbolic reference, and we degenerate this to the peeled object id.
44-
pub fn as_id(&self) -> &git_hash::oid {
44+
/// If unborn, `None` is returned.
45+
pub fn as_id(&self) -> Option<&git_hash::oid> {
4546
match self {
46-
Source::ObjectId(id) => id,
47+
Source::ObjectId(id) => Some(id),
4748
Source::Ref(r) => r.unpack().1,
4849
}
4950
}

git-repository/tests/remote/fetch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod blocking_io {
182182
if dry_run {
183183
assert_eq!(
184184
edit.change.new_value().expect("no deletions").id(),
185-
mapping.remote.as_id()
185+
mapping.remote.as_id().expect("no unborn")
186186
);
187187
assert!(
188188
repo.try_find_reference(edit.name.as_ref())?.is_none(),
@@ -192,7 +192,7 @@ mod blocking_io {
192192
let r = repo.find_reference(edit.name.as_ref()).unwrap();
193193
assert_eq!(
194194
r.id(),
195-
*mapping.remote.as_id(),
195+
*mapping.remote.as_id().expect("no unborn"),
196196
"local reference should point to remote id"
197197
);
198198
}

0 commit comments

Comments
 (0)