Even though in V1, we don't call it, let's just codify it to keep the knowledge somewhere.
Showing the changes to git-protocol/src (2 of 2 files). Show all
Unified · Split
| @@ -62,7 +62,7 @@ impl Command { · 61 unmodified lines | ||
| 62 | 62 | pub(crate) fn collect_initial_features<'a>( |
| 63 | 63 | &'a self, |
| 64 | 64 | _version: git_transport::Protocol, |
| 65 | − capabilities: &'a Capabilities, | |
| 65 | + server: &'a Capabilities, | |
| 66 | 66 | ) -> impl Iterator<Item = (&str, Option<&str>)> + 'a { |
| 67 | 67 | match Command::LsRefs { |
| 68 | 68 | Command::Fetch => unimplemented!("collect for fetch"), |
| @@ -70,7 +70,7 @@ impl Command { · 1 unmodified line | ||
| 70 | 70 | .all_features() |
| 71 | 71 | .filter(move |feature| { |
| 72 | 72 | if *feature == "symrefs" { |
| 73 | − capabilities.iter().any(|c| c.name() == b"symref".as_bstr()) | |
| 73 | + server.iter().any(|c| c.name() == b"symref".as_bstr()) | |
| 74 | 74 | } else { |
| 75 | 75 | true |
| 76 | 76 | } |
| @@ -105,6 +105,11 @@ impl Command { · 28 unmodified lines | ||
| 105 | 105 | } |
| 106 | 106 | panic!("{}: capability {} is not supported", self.as_str(), feature); |
| 107 | 107 | } |
| 108 | + if *self == Command::LsRefs { | |
| 109 | + if arguments.iter().any(|a| a.starts_with_str("ref-prefix ")) { | |
| 110 | + panic!("ref-prefix is not supported in V1 ls-refs"); | |
| 111 | + } | |
| 112 | + } | |
| 108 | 113 | } |
| 109 | 114 | git_transport::Protocol::V2 => { |
| 110 | 115 | if let Some(allowed) = server.iter().find_map(|c| { |
| @@ -1,15 +1,30 @@ | ||
| 1 | −mod v1 { | |
| 2 | − fn capabilities_from_v1(input: &str) -> git_transport::client::Capabilities { | |
| 3 | − git_transport::client::Capabilities::from_bytes(format!("\0{}", input).as_bytes()) | |
| 4 | − .expect("valid input capabilities") | |
| 5 | − .0 | |
| 6 | − } | |
| 1 | +fn capabilities(input: &str) -> git_transport::client::Capabilities { | |
| 2 | + git_transport::client::Capabilities::from_bytes(format!("\0{}", input).as_bytes()) | |
| 3 | + .expect("valid input capabilities") | |
| 4 | + .0 | |
| 5 | +} | |
| 7 | 6 | |
| 7 | +mod v1 { | |
| 8 | 8 | mod ls_refs { |
| 9 | + mod validate_arguments { | |
| 10 | + use crate::{fetch::tests::command::capabilities, fetch::Command}; | |
| 11 | + use bstr::ByteSlice; | |
| 12 | + | |
| 13 | + #[test] | |
| 14 | + #[should_panic] | |
| 15 | + fn ref_prefixes_cannot_be_used() { | |
| 16 | + Command::LsRefs.validate_argument_prefixes_or_panic( | |
| 17 | + git_transport::Protocol::V1, | |
| 18 | + &capabilities("do-not-matter"), | |
| 19 | + &[b"ref-prefix hello/".as_bstr().into()], | |
| 20 | + &[], | |
| 21 | + ); | |
| 22 | + } | |
| 23 | + } | |
| 9 | 24 | mod collect_initial_features { |
| 10 | 25 | use crate::{ |
| 11 | 26 | fetch, |
| 12 | − fetch::{tests::command::v1::capabilities_from_v1, Command}, | |
| 27 | + fetch::{tests::command::capabilities, Command}, | |
| 13 | 28 | }; |
| 14 | 29 | |
| 15 | 30 | #[test] |
| @@ -18,7 +33,7 @@ mod v1 { · 2 unmodified lines | ||
| 18 | 33 | Command::LsRefs |
| 19 | 34 | .collect_initial_features( |
| 20 | 35 | git_transport::Protocol::V1, |
| 21 | − &capabilities_from_v1("symref=HEAD:refs/heads/master object-format=sha1 agent=git/2.28.0") | |
| 36 | + &capabilities("symref=HEAD:refs/heads/master object-format=sha1 agent=git/2.28.0") | |
| 22 | 37 | ) |
| 23 | 38 | .collect::<Vec<_>>(), |
| 24 | 39 | &[("symrefs", None), ("peel", None), fetch::agent()] |
| @@ -31,7 +46,7 @@ mod v1 { · 6 unmodified lines | ||
| 31 | 46 | Command::LsRefs |
| 32 | 47 | .collect_initial_features( |
| 33 | 48 | git_transport::Protocol::V1, |
| 34 | − &capabilities_from_v1("object-format=sha1 agent=git/2.28.0") | |
| 49 | + &capabilities("object-format=sha1 agent=git/2.28.0") | |
| 35 | 50 | ) |
| 36 | 51 | .collect::<Vec<_>>(), |
| 37 | 52 | &[("peel", None), fetch::agent()] |
| @@ -40,3 +55,22 @@ mod v1 { · 2 unmodified lines | ||
| 40 | 55 | } |
| 41 | 56 | } |
| 42 | 57 | } |
| 58 | + | |
| 59 | +mod v2 { | |
| 60 | + mod ls_refs { | |
| 61 | + mod validate_arguments { | |
| 62 | + use crate::{fetch::tests::command::capabilities, fetch::Command}; | |
| 63 | + use bstr::ByteSlice; | |
| 64 | + | |
| 65 | + #[test] | |
| 66 | + fn ref_prefixes_always_be_used() { | |
| 67 | + Command::LsRefs.validate_argument_prefixes_or_panic( | |
| 68 | + git_transport::Protocol::V2, | |
| 69 | + &capabilities("do-not-matter"), | |
| 70 | + &[b"ref-prefix hello/".as_bstr().into()], | |
| 71 | + &[], | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + } | |
| 76 | +} | |