1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![allow(clippy::result_large_err)]
use std::convert::TryInto;
use crate::bstr::BString;
type ConfigureRemoteFn =
Box<dyn FnMut(crate::Remote<'_>) -> Result<crate::Remote<'_>, Box<dyn std::error::Error + Send + Sync>>>;
#[must_use]
pub struct PrepareFetch {
repo: Option<crate::Repository>,
remote_name: Option<BString>,
configure_remote: Option<ConfigureRemoteFn>,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
fetch_options: crate::remote::ref_map::Options,
#[cfg_attr(not(feature = "blocking-network-client"), allow(dead_code))]
url: git_url::Url,
}
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
Init(#[from] crate::init::Error),
#[error(transparent)]
UrlParse(#[from] git_url::parse::Error),
#[error("Failed to turn a the relative file url \"{}\" into an absolute one", url.to_bstring())]
CanonicalizeUrl {
url: git_url::Url,
source: git_path::realpath::Error,
},
}
impl PrepareFetch {
#[allow(clippy::result_large_err)]
pub fn new<Url, E>(
url: Url,
path: impl AsRef<std::path::Path>,
kind: crate::create::Kind,
mut create_opts: crate::create::Options,
open_opts: crate::open::Options,
) -> Result<Self, Error>
where
Url: TryInto<git_url::Url, Error = E>,
git_url::parse::Error: From<E>,
{
let mut url = url.try_into().map_err(git_url::parse::Error::from)?;
url.canonicalize().map_err(|err| Error::CanonicalizeUrl {
url: url.clone(),
source: err,
})?;
create_opts.destination_must_be_empty = true;
let repo = crate::ThreadSafeRepository::init_opts(path, kind, create_opts, open_opts)?.to_thread_local();
Ok(PrepareFetch {
url,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
fetch_options: Default::default(),
repo: Some(repo),
remote_name: None,
configure_remote: None,
})
}
}
#[must_use]
pub struct PrepareCheckout {
pub(self) repo: Option<crate::Repository>,
}
pub mod fetch;
pub mod checkout;