Skip to content

Commit

Permalink
first step for basic test of simple http configuration
Browse files Browse the repository at this point in the history
This showed an issue with remote name handling as well which
needs fixing once remote names are affecting the configuration.
  • Loading branch information
Byron committed Nov 10, 2022
1 parent 2ef0e09 commit 21bd85d
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 5 deletions.
25 changes: 25 additions & 0 deletions git-repository/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ pub mod checkout_options {
}
}

///
pub mod transport {

/// The error produced when configuring a transport for a particular protocol.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Invalid URL passed for configuration")]
ParseUrl(#[from] git_url::parse::Error),
#[error("Could obtain configuration for an HTTP url")]
Http(#[from] http::Error),
}

///
pub mod http {
/// The error produced when configuring a HTTP transport.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("TBD")]
TBD,
}
}
}

/// Utility type to keep pre-obtained configuration values, only for those required during initial setup
/// and other basic operations that are common enough to warrant a permanent cache.
///
Expand Down
4 changes: 4 additions & 0 deletions git-repository/src/remote/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use crate::{bstr::BStr, remote, Remote};
/// Access
impl Remote<'_> {
/// Return the name of this remote or `None` if it wasn't persisted to disk yet.
// TODO: name can also be a URL but we don't see it like this. There is a problem with accessing such names
// too as they would require a BStr, but valid subsection names are strings, so some degeneration must happen
// for access at least. Argh. Probably use `reference::remote::Name` and turn it into `remote::Name` as it's
// actually correct.
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
Expand Down
8 changes: 7 additions & 1 deletion git-repository/src/remote/connection/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P> {
self.remote
}

/// Provide a mutable transport to allow configuring it with [`configure()`][git_protocol::transport::client::TransportWithoutIO::configure()]
/// Provide a mutable transport to allow configuring it with [`configure()`][git_protocol::transport::client::TransportWithoutIO::configure()].
///
/// Please note that it is pre-configured, but can be configured again right after the [`Connection`] was instantiated without
/// the previous configuration having ever been used.
///
/// Also note that all of the default configuration is created from `git` configuration, which can also be manipulated through overrides
/// to affect the default configuration.
pub fn transport_mut(&mut self) -> &mut T {
&mut self.transport
}
Expand Down
28 changes: 28 additions & 0 deletions git-repository/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ impl crate::Repository {
}
}

#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
mod transport {
use crate::bstr::BStr;
use std::any::Any;

impl crate::Repository {
/// Produce configuration suitable for `url`, as differentiated by its protocol/scheme, to be passed to a transport instance via
/// [configure()][git_transport::client::Transport::configure()].
/// `None` is returned if there is no known configuration.
///
/// Note that the caller may cast the instance themselves to modify it before passing it on.
pub fn transport_config<'a>(
&self,
url: impl Into<&'a BStr>,
) -> Result<Option<Box<dyn Any>>, crate::config::transport::Error> {
let url = git_url::parse(url.into())?;
use git_url::Scheme::*;

match &url.scheme {
Http | Https => {
todo!()
}
File | Git | Ssh | Ext(_) => Ok(None),
}
}
}
}

mod remote {
use std::{borrow::Cow, collections::BTreeSet};

Expand Down
16 changes: 14 additions & 2 deletions git-repository/tests/fixtures/make_fetch_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ git clone --shared base two-origins
)

git clone --shared base worktree-root
(
cd worktree-root
(cd worktree-root

git worktree add ../wt-a
git worktree add ../prev/wt-a-nested
Expand All @@ -29,3 +28,16 @@ git clone --shared base worktree-root
git worktree add --lock ../wt-c-locked
git worktree add ../wt-deleted && rm -Rf ../wt-deleted
)

git init http-config
(cd http-config
git config http.extraHeader "ExtraHeader: value1"
git config --add http.extraHeader "ExtraHeader: value2"
git config http.followRedirects initial
git config http.lowSpeedLimit 5k
git config http.lowSpeedTime 10
git config http.postBuffer 8k
git config http.proxy localhost:9090
git config http.proxyAuthMethod anyauth
git config http.userAgent agentJustForHttp
)
1 change: 0 additions & 1 deletion git-repository/tests/remote/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod blocking_io {
use git_testtools::hex_to_id;

use crate::remote;

fn repo_rw(name: &str) -> (git::Repository, git_testtools::tempfile::TempDir) {
let dir = git_testtools::scripted_fixture_repo_writable_with_args(
"make_fetch_repos.sh",
Expand Down
2 changes: 1 addition & 1 deletion git-repository/tests/remote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) fn cow_str(s: &str) -> Cow<str> {
}

mod connect;
mod fetch;
pub(crate) mod fetch;
mod ref_map;
mod save;
mod name {
Expand Down
2 changes: 2 additions & 0 deletions git-repository/tests/repository/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod config_snapshot;
mod identity;
mod remote;
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
mod transport_config;
34 changes: 34 additions & 0 deletions git-repository/tests/repository/config/transport_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[cfg(feature = "blocking-http-transport")]
mod http {
use git_repository as git;

fn base_repo_path() -> String {
git::path::realpath(
git_testtools::scripted_fixture_repo_read_only("make_remote_repos.sh")
.unwrap()
.join("base"),
)
.unwrap()
.to_string_lossy()
.into_owned()
}

pub(crate) fn repo(name: &str) -> git::Repository {
let dir = git_testtools::scripted_fixture_repo_read_only_with_args("make_fetch_repos.sh", [base_repo_path()])
.unwrap();
git::open_opts(dir.join(name), git::open::Options::isolated()).unwrap()
}

#[test]
#[ignore]
fn simple_configuration() {
let repo = repo("http-config");
let http_config = repo
.transport_config("https://example.com/does/not/matter")
.expect("valid configuration")
.expect("configuration available for http");
let _options = http_config
.downcast_ref::<git_transport::client::http::Options>()
.expect("http options have been created");
}
}

0 comments on commit 21bd85d

Please sign in to comment.