Skip to content

Commit 0eb460c

Browse files
committed
Add configuration support for backend selection
Add git_backend field to ProtofetchConfig and support loading from config file or PROTOFETCH_GIT_BACKEND environment variable.
1 parent b2bb5ed commit 0eb460c

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/config.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ use config::{Config, ConfigError, Environment, File, FileFormat};
55
use log::{debug, trace};
66
use serde::Deserialize;
77

8-
use crate::model::protofetch::Protocol;
8+
use crate::{git::backend::GitBackendType, model::protofetch::Protocol};
99

1010
#[derive(Debug)]
1111
pub struct ProtofetchConfig {
1212
pub cache_dir: PathBuf,
1313
pub default_protocol: Protocol,
1414
pub jobs: Option<usize>,
1515
pub copy_jobs: Option<usize>,
16+
pub git_backend: GitBackendType,
17+
pub git_executable: Option<String>,
1618
}
1719

1820
impl ProtofetchConfig {
@@ -28,6 +30,8 @@ impl ProtofetchConfig {
2830
default_protocol: raw_config.git.protocol.unwrap_or(Protocol::Ssh),
2931
jobs: raw_config.jobs,
3032
copy_jobs: raw_config.copy_jobs,
33+
git_backend: raw_config.git.backend.unwrap_or_default(),
34+
git_executable: raw_config.git.executable_path,
3135
};
3236
trace!("Loaded configuration: {:?}", config);
3337

@@ -55,6 +59,8 @@ struct CacheConfig {
5559
#[derive(Default, Debug, Deserialize, PartialEq, Eq)]
5660
struct GitConfig {
5761
protocol: Option<Protocol>,
62+
backend: Option<GitBackendType>,
63+
executable_path: Option<String>,
5864
}
5965

6066
impl RawConfig {
@@ -146,7 +152,11 @@ mod tests {
146152
config,
147153
RawConfig {
148154
cache: CacheConfig { dir: None },
149-
git: GitConfig { protocol: None },
155+
git: GitConfig {
156+
protocol: None,
157+
backend: None,
158+
executable_path: None,
159+
},
150160
jobs: None,
151161
copy_jobs: None,
152162
}
@@ -158,7 +168,10 @@ mod tests {
158168
let env = HashMap::from([
159169
("PROTOFETCH_CACHE_DIR".to_owned(), "/cache".to_owned()),
160170
("PROTOFETCH_GIT_PROTOCOL".to_owned(), "ssh".to_owned()),
171+
("PROTOFETCH_GIT_BACKEND".to_owned(), "cli".to_owned()),
161172
]);
173+
// Note: `git.executable_path` is a config-file-only setting; the
174+
// `Environment` source's `_` separator would split a two-word key.
162175
let config = RawConfig::load(None, Some(Default::default()), Some(env)).unwrap();
163176
assert_eq!(
164177
config,
@@ -167,7 +180,9 @@ mod tests {
167180
dir: Some("/cache".into())
168181
},
169182
git: GitConfig {
170-
protocol: Some(Protocol::Ssh)
183+
protocol: Some(Protocol::Ssh),
184+
backend: Some(GitBackendType::Cli),
185+
executable_path: None,
171186
},
172187
jobs: None,
173188
copy_jobs: None,
@@ -197,6 +212,8 @@ mod tests {
197212

198213
[git]
199214
protocol = "ssh"
215+
backend = "cli"
216+
executable_path = "/usr/bin/git"
200217
}),
201218
Some(env),
202219
)
@@ -208,7 +225,9 @@ mod tests {
208225
dir: Some("/cache".into())
209226
},
210227
git: GitConfig {
211-
protocol: Some(Protocol::Ssh)
228+
protocol: Some(Protocol::Ssh),
229+
backend: Some(GitBackendType::Cli),
230+
executable_path: Some("/usr/bin/git".to_owned()),
212231
},
213232
jobs: None,
214233
copy_jobs: None,

0 commit comments

Comments
 (0)