History

first step for basic test of simple http configuration

This showed an issue with remote name handling as well which needs fixing once remote names are affecting the configuration.

Sebastian Thiel committed 4 years ago

Commit 21bd85d1 parent 2ef0e099 files · +115 −5Browse files

Unified · Split

9 files
  1. git-repository/src/config/mod.rs +25 −0
  2. git-repository/src/remote/access.rs +4 −0
  3. git-repository/src/remote/connection/access.rs +7 −1
  4. git-repository/src/repository/config.rs +28 −0
  5. git-repository/tests/fixtures/make_fetch_repos.sh +14 −2
  6. git-repository/tests/remote/fetch.rs +0 −1
  7. git-repository/tests/remote/mod.rs +1 −1
  8. git-repository/tests/repository/config/mod.rs +2 −0
  9. git-repository/tests/repository/config/transport_config.rs +34 −0
git-repository/src/config/mod.rs+25−0
@@ -107,6 +107,31 @@ pub mod checkout_options { · 106 unmodified lines
107107 }
108108 }
109109
110+///
111+pub mod transport {
112+
113+ /// The error produced when configuring a transport for a particular protocol.
114+ #[derive(Debug, thiserror::Error)]
115+ #[allow(missing_docs)]
116+ pub enum Error {
117+ #[error("Invalid URL passed for configuration")]
118+ ParseUrl(#[from] git_url::parse::Error),
119+ #[error("Could obtain configuration for an HTTP url")]
120+ Http(#[from] http::Error),
121+ }
122+
123+ ///
124+ pub mod http {
125+ /// The error produced when configuring a HTTP transport.
126+ #[derive(Debug, thiserror::Error)]
127+ #[allow(missing_docs)]
128+ pub enum Error {
129+ #[error("TBD")]
130+ TBD,
131+ }
132+ }
133+}
134+
110135 /// Utility type to keep pre-obtained configuration values, only for those required during initial setup
111136 /// and other basic operations that are common enough to warrant a permanent cache.
112137 ///
git-repository/src/remote/access.rs+4−0
@@ -5,6 +5,10 @@ use crate::{bstr::BStr, remote, Remote}; · 4 unmodified lines
55 /// Access
66 impl Remote<'_> {
77 /// Return the name of this remote or `None` if it wasn't persisted to disk yet.
8+ // TODO: name can also be a URL but we don't see it like this. There is a problem with accessing such names
9+ // too as they would require a BStr, but valid subsection names are strings, so some degeneration must happen
10+ // for access at least. Argh. Probably use `reference::remote::Name` and turn it into `remote::Name` as it's
11+ // actually correct.
812 pub fn name(&self) -> Option<&str> {
913 self.name.as_deref()
1014 }
git-repository/src/remote/connection/access.rs+7−1
@@ -41,7 +41,13 @@ impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P> { · 40 unmodified lines
4141 self.remote
4242 }
4343
44− /// Provide a mutable transport to allow configuring it with [`configure()`][git_protocol::transport::client::TransportWithoutIO::configure()]
44+ /// Provide a mutable transport to allow configuring it with [`configure()`][git_protocol::transport::client::TransportWithoutIO::configure()].
45+ ///
46+ /// Please note that it is pre-configured, but can be configured again right after the [`Connection`] was instantiated without
47+ /// the previous configuration having ever been used.
48+ ///
49+ /// Also note that all of the default configuration is created from `git` configuration, which can also be manipulated through overrides
50+ /// to affect the default configuration.
4551 pub fn transport_mut(&mut self) -> &mut T {
4652 &mut self.transport
4753 }
git-repository/src/repository/config.rs+28−0
@@ -33,6 +33,34 @@ impl crate::Repository { · 32 unmodified lines
3333 }
3434 }
3535
36+#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
37+mod transport {
38+ use crate::bstr::BStr;
39+ use std::any::Any;
40+
41+ impl crate::Repository {
42+ /// Produce configuration suitable for `url`, as differentiated by its protocol/scheme, to be passed to a transport instance via
43+ /// [configure()][git_transport::client::Transport::configure()].
44+ /// `None` is returned if there is no known configuration.
45+ ///
46+ /// Note that the caller may cast the instance themselves to modify it before passing it on.
47+ pub fn transport_config<'a>(
48+ &self,
49+ url: impl Into<&'a BStr>,
50+ ) -> Result<Option<Box<dyn Any>>, crate::config::transport::Error> {
51+ let url = git_url::parse(url.into())?;
52+ use git_url::Scheme::*;
53+
54+ match &url.scheme {
55+ Http | Https => {
56+ todo!()
57+ }
58+ File | Git | Ssh | Ext(_) => Ok(None),
59+ }
60+ }
61+ }
62+}
63+
3664 mod remote {
3765 use std::{borrow::Cow, collections::BTreeSet};
3866
git-repository/tests/fixtures/make_fetch_repos.sh+14−2
@@ -19,8 +19,7 @@ git clone --shared base two-origins · 18 unmodified lines
1919 )
2020
2121 git clone --shared base worktree-root
22−(
23− cd worktree-root
22+(cd worktree-root
2423
2524 git worktree add ../wt-a
2625 git worktree add ../prev/wt-a-nested
@@ -29,3 +28,16 @@ git clone --shared base worktree-root · 2 unmodified lines
2928 git worktree add --lock ../wt-c-locked
3029 git worktree add ../wt-deleted && rm -Rf ../wt-deleted
3130 )
31+
32+git init http-config
33+(cd http-config
34+ git config http.extraHeader "ExtraHeader: value1"
35+ git config --add http.extraHeader "ExtraHeader: value2"
36+ git config http.followRedirects initial
37+ git config http.lowSpeedLimit 5k
38+ git config http.lowSpeedTime 10
39+ git config http.postBuffer 8k
40+ git config http.proxy localhost:9090
41+ git config http.proxyAuthMethod anyauth
42+ git config http.userAgent agentJustForHttp
43+)
git-repository/tests/remote/fetch.rs+0−1
@@ -8,7 +8,6 @@ mod blocking_io { · 7 unmodified lines
88 use git_testtools::hex_to_id;
99
1010 use crate::remote;
11−
1211 fn repo_rw(name: &str) -> (git::Repository, git_testtools::tempfile::TempDir) {
1312 let dir = git_testtools::scripted_fixture_repo_writable_with_args(
1413 "make_fetch_repos.sh",
git-repository/tests/remote/mod.rs+1−1
@@ -17,7 +17,7 @@ pub(crate) fn cow_str(s: &str) -> Cow<str> { · 16 unmodified lines
1717 }
1818
1919 mod connect;
20−mod fetch;
20+pub(crate) mod fetch;
2121 mod ref_map;
2222 mod save;
2323 mod name {
git-repository/tests/repository/config/mod.rs+2−0
@@ -1,3 +1,5 @@
11 mod config_snapshot;
22 mod identity;
33 mod remote;
4+#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
5+mod transport_config;
git-repository/tests/repository/config/transport_config.rs+34−0
@@ -0,0 +1,34 @@
1+#[cfg(feature = "blocking-http-transport")]
2+mod http {
3+ use git_repository as git;
4+
5+ fn base_repo_path() -> String {
6+ git::path::realpath(
7+ git_testtools::scripted_fixture_repo_read_only("make_remote_repos.sh")
8+ .unwrap()
9+ .join("base"),
10+ )
11+ .unwrap()
12+ .to_string_lossy()
13+ .into_owned()
14+ }
15+
16+ pub(crate) fn repo(name: &str) -> git::Repository {
17+ let dir = git_testtools::scripted_fixture_repo_read_only_with_args("make_fetch_repos.sh", [base_repo_path()])
18+ .unwrap();
19+ git::open_opts(dir.join(name), git::open::Options::isolated()).unwrap()
20+ }
21+
22+ #[test]
23+ #[ignore]
24+ fn simple_configuration() {
25+ let repo = repo("http-config");
26+ let http_config = repo
27+ .transport_config("https://example.com/does/not/matter")
28+ .expect("valid configuration")
29+ .expect("configuration available for http");
30+ let _options = http_config
31+ .downcast_ref::<git_transport::client::http::Options>()
32+ .expect("http options have been created");
33+ }
34+}