Skip to content

Commit

Permalink
reproduce #1598
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 23, 2024
1 parent 73a7d15 commit 6c82f31
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gix-protocol/src/handshake/refs/shared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bstr::{BStr, BString, ByteSlice};

use crate::handshake::{refs::parse::Error, Ref};
use bstr::{BStr, BString, ByteSlice};

impl From<InternalRef> for Ref {
fn from(v: InternalRef) -> Self {
Expand Down Expand Up @@ -160,7 +159,13 @@ pub(in crate::handshake::refs) fn parse_v1(
});
}
None => {
let object = gix_hash::ObjectId::from_hex(hex_hash.as_bytes())?;
let object = match gix_hash::ObjectId::from_hex(hex_hash.as_bytes()) {
Ok(id) => id,
Err(_) if hex_hash.as_bstr() == "shallow" => {
todo!("shallow");
}
Err(err) => return Err(err.into()),
};
match out_refs
.iter()
.take(num_initial_out_refs)
Expand Down
52 changes: 52 additions & 0 deletions gix-protocol/src/handshake/refs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ dce0ea858eef7ff61ad345cc5cdac62203fb3c10 refs/tags/gix-commitgraph-v0.0.0
);
}

#[maybe_async::test(feature = "blocking-client", async(feature = "async-client", async_std::test))]
async fn extract_references_from_v1_refs_with_shallow() {
let input = &mut Fixture(
"73a6868963993a3328e7d8fe94e5a6ac5078a944 HEAD
21c9b7500cb144b3169a6537961ec2b9e865be81 MISSING_NAMESPACE_TARGET
73a6868963993a3328e7d8fe94e5a6ac5078a944 refs/heads/main
8e472f9ccc7d745927426cbb2d9d077de545aa4e refs/pull/13/head
dce0ea858eef7ff61ad345cc5cdac62203fb3c10 refs/tags/gix-commitgraph-v0.0.0
21c9b7500cb144b3169a6537961ec2b9e865be81 refs/tags/gix-commitgraph-v0.0.0^{}
shallow 21c9b7500cb144b3169a6537961ec2b9e865be81
shallow dce0ea858eef7ff61ad345cc5cdac62203fb3c10"
.as_bytes(),
);
let out = refs::from_v1_refs_received_as_part_of_handshake_and_capabilities(
input,
Capabilities::from_bytes(b"\0symref=HEAD:refs/heads/main symref=MISSING_NAMESPACE_TARGET:(null)")
.expect("valid capabilities")
.0
.iter(),
)
.await
.expect("no failure from valid input");
assert_eq!(
out,
vec![
Ref::Symbolic {
full_ref_name: "HEAD".into(),
target: "refs/heads/main".into(),
tag: None,
object: oid("73a6868963993a3328e7d8fe94e5a6ac5078a944")
},
Ref::Direct {
full_ref_name: "MISSING_NAMESPACE_TARGET".into(),
object: oid("21c9b7500cb144b3169a6537961ec2b9e865be81")
},
Ref::Direct {
full_ref_name: "refs/heads/main".into(),
object: oid("73a6868963993a3328e7d8fe94e5a6ac5078a944")
},
Ref::Direct {
full_ref_name: "refs/pull/13/head".into(),
object: oid("8e472f9ccc7d745927426cbb2d9d077de545aa4e")
},
Ref::Peeled {
full_ref_name: "refs/tags/gix-commitgraph-v0.0.0".into(),
tag: oid("dce0ea858eef7ff61ad345cc5cdac62203fb3c10"),
object: oid("21c9b7500cb144b3169a6537961ec2b9e865be81")
},
]
);
}

#[test]
fn extract_symbolic_references_from_capabilities() -> Result<(), client::Error> {
let caps = client::Capabilities::from_bytes(
Expand Down

0 comments on commit 6c82f31

Please sign in to comment.