Skip to content

Commit 04ed1b6

Browse files
RajivTSfacebook-github-bot
authored andcommitted
Fix for pushing to empty repo on Mononoke Git server
Summary: In Protocol V1, the capability of the server is advertised along with the ref advertisement. This is done by null-separating the capabilities from the first ref while the rest of the refs are sent normally. However, since the capabilities are tied to ref advertisement in the write path, having no refs mean that we won't send any capabilities to the client. This is what was wrong with the current implementation. Now the logic has been corrected to make it consistent with [the spec](https://git-scm.com/docs/pack-protocol#_reference_discovery) Reviewed By: andreacampi Differential Revision: D67978800 fbshipit-source-id: bb9ea76dca8f27ac3ed1f4b6b06fc55f795e4804
1 parent 4a71278 commit 04ed1b6

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

eden/mononoke/git_server/src/read/capability_advertisement.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use core::str;
99

1010
use anyhow::Error;
1111
use bytes::Bytes;
12+
use gix_hash::Kind;
13+
use gix_hash::ObjectId;
1214
use gotham::mime;
1315
use gotham::state::FromState;
1416
use gotham::state::State;
@@ -84,14 +86,29 @@ async fn write_advertisement(
8486
.into_iter()
8587
.collect();
8688
refs.sort_by(|a, b| a.0.cmp(&b.0));
89+
8790
let mut refs = refs.into_iter();
88-
if let Some((ref_name, target)) = refs.next() {
89-
let first_ref_line = ref_line(ref_name.as_str(), &target);
90-
write_text_packetline(
91-
format!("{}\0{}", first_ref_line, RECEIVE_PACK_CAPABILITIES).as_bytes(),
92-
output,
93-
)
94-
.await?;
91+
match refs.next() {
92+
Some((ref_name, target)) => {
93+
let first_ref_line = ref_line(ref_name.as_str(), &target);
94+
write_text_packetline(
95+
format!("{}\0{}", first_ref_line, RECEIVE_PACK_CAPABILITIES).as_bytes(),
96+
output,
97+
)
98+
.await?;
99+
}
100+
None => {
101+
write_text_packetline(
102+
format!(
103+
"{} capabilities^{{}}\0{}",
104+
ObjectId::null(Kind::Sha1),
105+
RECEIVE_PACK_CAPABILITIES
106+
)
107+
.as_bytes(),
108+
output,
109+
)
110+
.await?;
111+
}
95112
}
96113
for (ref_name, target) in refs {
97114
write_text_packetline(ref_line(ref_name.as_str(), &target).as_bytes(), output).await?;

eden/mononoke/tests/integration/mononoke_git_server/test-mononoke-git-server-push-empty-repo.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535

3636
# Push Git repository to Mononoke
3737
$ git_client push origin --all
38-
error: failed to push some refs to 'https://*/repos/git/ro/repo.git' (glob)
39-
[1]
38+
To https://*/repos/git/ro/repo.git (glob)
39+
* [new branch] master_bookmark -> master_bookmark

0 commit comments

Comments
 (0)