History

[clone] assert on ref-prefix for ls-refs command

Even though in V1, we don't call it, let's just codify it to keep the knowledge somewhere.

Sebastian Thiel committed 6 years ago

Commit 70347a51 parent d55cd562 files · +50 −11Browse files

Showing the changes to git-protocol/src (2 of 2 files). Show all

Unified · Split

2 files
  1. git-protocol/src/fetch/command.rs +7 −2
  2. git-protocol/src/fetch/tests/command.rs +43 −9
git-protocol/src/fetch/command.rs+7−2
@@ -62,7 +62,7 @@ impl Command { · 61 unmodified lines
6262 pub(crate) fn collect_initial_features<'a>(
6363 &'a self,
6464 _version: git_transport::Protocol,
65− capabilities: &'a Capabilities,
65+ server: &'a Capabilities,
6666 ) -> impl Iterator<Item = (&str, Option<&str>)> + 'a {
6767 match Command::LsRefs {
6868 Command::Fetch => unimplemented!("collect for fetch"),
@@ -70,7 +70,7 @@ impl Command { · 1 unmodified line
7070 .all_features()
7171 .filter(move |feature| {
7272 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())
7474 } else {
7575 true
7676 }
@@ -105,6 +105,11 @@ impl Command { · 28 unmodified lines
105105 }
106106 panic!("{}: capability {} is not supported", self.as_str(), feature);
107107 }
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+ }
108113 }
109114 git_transport::Protocol::V2 => {
110115 if let Some(allowed) = server.iter().find_map(|c| {
git-protocol/src/fetch/tests/command.rs+43−9
@@ -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+}
76
7+mod v1 {
88 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+ }
924 mod collect_initial_features {
1025 use crate::{
1126 fetch,
12− fetch::{tests::command::v1::capabilities_from_v1, Command},
27+ fetch::{tests::command::capabilities, Command},
1328 };
1429
1530 #[test]
@@ -18,7 +33,7 @@ mod v1 { · 2 unmodified lines
1833 Command::LsRefs
1934 .collect_initial_features(
2035 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")
2237 )
2338 .collect::<Vec<_>>(),
2439 &[("symrefs", None), ("peel", None), fetch::agent()]
@@ -31,7 +46,7 @@ mod v1 { · 6 unmodified lines
3146 Command::LsRefs
3247 .collect_initial_features(
3348 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")
3550 )
3651 .collect::<Vec<_>>(),
3752 &[("peel", None), fetch::agent()]
@@ -40,3 +55,22 @@ mod v1 { · 2 unmodified lines
4055 }
4156 }
4257 }
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+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t