Skip to content

Commit

Permalink
Merge branch 'push-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 16, 2022
2 parents 0c9c48b + 4d84a20 commit 42356ab
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ This also means that CI may fail despite everything being alright locally, and t

## How to update fixtures

### For object data

Fixtures are created by using a line like this which produces a line we ignore via `tail +1` followed by the un-prettified object payload
trailed by a newline.
```sh
Expand Down
8 changes: 8 additions & 0 deletions git-transport/src/client/async_io/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ impl<'a> RequestWriter<'a> {
self.write_message(self.on_into_read).await?;
Ok(self.reader)
}

/// Dissolve this instance into its write and read handles without any side-effect.
///
/// This is useful to take more over when to write with packetline or not, which is why the writer doesn't write
/// packetlines but verbatim.
pub fn into_parts(self) -> (Box<dyn AsyncWrite + Unpin + 'a>, Box<dyn ExtendedBufRead + Unpin + 'a>) {
(self.writer.into_inner(), self.reader)
}
}
8 changes: 8 additions & 0 deletions git-transport/src/client/blocking_io/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ impl<'a> RequestWriter<'a> {
self.write_message(self.on_into_read)?;
Ok(self.reader)
}

/// Dissolve this instance into its write and read handles without any side-effect.
///
/// This is useful to take more over when to write with packetline or not, which is why the writer doesn't write
/// packetlines but verbatim.
pub fn into_parts(self) -> (Box<dyn io::Write + 'a>, Box<dyn ExtendedBufRead + Unpin + 'a>) {
(self.writer.into_inner(), self.reader)
}
}
64 changes: 64 additions & 0 deletions git-transport/tests/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,70 @@ async fn handshake_v1_and_request() -> crate::Result {
Ok(())
}

#[maybe_async::test(feature = "blocking-client", async(feature = "async-client", async_std::test))]
async fn push_v1_simulated() -> crate::Result {
let mut out = Vec::new();
let server_response = fixture_bytes("v1/push.response");
let mut c = git::Connection::new(
server_response.as_slice(),
&mut out,
Protocol::V1,
"/foo.git",
Some(("example.org", None)),
git::ConnectMode::Process,
);

let mut writer = c.request(client::WriteMode::Binary, client::MessageKind::Flush)?;
let expected = fixture_bytes("v1/push.request");
writer.write_all(b"7c09ba0c4c3680af369bda4fc8e3c58d3fccdc76 32690d87d3943c7c0dda81246d0cde344ca7e633 refs/heads/main\0 report-status-v2 side-band-64k object-format=sha1 agent=git/2.37.1.(Apple.Git-137.1)").await?;
writer.write_message(client::MessageKind::Flush).await?;
{
let (mut write, mut read) = writer.into_parts();
write.write_all(&expected[191..]).await?;

let messages = Arc::new(Mutex::new(Vec::<String>::new()));
read.set_progress_handler(Some(Box::new({
let sb = messages.clone();
move |is_err, data| {
assert!(!is_err);
sb.deref()
.lock()
.expect("no panic in other threads")
.push(std::str::from_utf8(data).expect("valid utf8").to_owned())
}
})));
let mut lines = read.lines();
let mut info = Vec::new();
#[allow(clippy::while_let_on_iterator)] // needed in async version of test
while let Some(line) = lines.next().await {
info.push(line?)
}
assert_eq!(
info,
&["000eunpack ok", "0017ok refs/heads/main", "0000"],
"this seems to be a packetline encoding within a packetline encoding! Including a flush package. Strange, but it's the real deal."
);
let expected_progress = &["Resolving deltas: 0% (0/2)\r",
"Resolving deltas: 50% (1/2)\r",
"Resolving deltas: 100% (2/2)\r",
"Resolving deltas: 100% (2/2), completed with 2 local objects.",
"\nGitHub found 1 vulnerability on the-lean-crate/criner's default branch (1 high). To find out more, visit:\n https://github.com/the-lean-crate/criner/security/dependabot/1\n"
];
assert_eq!(
messages.lock().expect("no poison").as_slice(),
expected_progress,
"these look like they are created once the whole pack has been received"
);
}

assert_eq!(
out.as_slice().as_bstr(),
expected.as_bstr(),
"we are able to reproduce a typical push request by hand with a little bit of juggling"
);
Ok(())
}

#[maybe_async::test(feature = "blocking-client", async(feature = "async-client", async_std::test))]
async fn handshake_v1_process_mode() -> crate::Result {
let mut out = Vec::new();
Expand Down
Binary file added git-transport/tests/fixtures/v1/push.request
Binary file not shown.
8 changes: 8 additions & 0 deletions git-transport/tests/fixtures/v1/push.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0022Resolving deltas: 0% (0/2)0022Resolving deltas: 50% (1/2)0022Resolving deltas: 100% (2/2)0043Resolving deltas: 100% (2/2), completed with 2 local objects.
0013000eunpack ok
001c0017ok refs/heads/main
00b5
GitHub found 1 vulnerability on the-lean-crate/criner's default branch (1 high). To find out more, visit:
https://github.com/the-lean-crate/criner/security/dependabot/1

000900000000
Expand Down

0 comments on commit 42356ab

Please sign in to comment.