Skip to content

Commit

Permalink
Move git deps to optional
Browse files Browse the repository at this point in the history
Virviil committed Dec 27, 2023
1 parent 6ba2116 commit 5a4f2c3
Showing 2 changed files with 34 additions and 6 deletions.
6 changes: 5 additions & 1 deletion loco-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@ required-features = []

[features]
default = []
gix = ["dep:gix"]
git2 = ["dep:git2"]

[dependencies]
clap = { version = "4.4.7", features = ["derive"] }
@@ -35,12 +37,14 @@ eyre = { version = "0.6.9" }
rand = { version = "0.8.5" }
requestty = "0.5.0"
regex = { version = "1.10.2" }
git2 = { version = "0.18.1" }
ignore = "0.4.21"
fs_extra = "1.3.0"
lazy_static = "1.4.0"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
git2 = { version = "0.18.1", optional = true }
gix = {version = "0.56.0", features = ["blocking-network-client", "blocking-http-transport-reqwest-rust-tls-trust-dns"], optional = true}
cfg-if = "1.0.0"

[dev-dependencies]
trycmd = "0.14.19"
34 changes: 29 additions & 5 deletions loco-cli/src/git.rs
Original file line number Diff line number Diff line change
@@ -120,11 +120,15 @@ fn clone_repo() -> eyre::Result<PathBuf> {
.arg(&temp_clone_dir)
.output()?;
} else {
let mut opt = git2::FetchOptions::new();
opt.depth(1);
git2::build::RepoBuilder::new()
.fetch_options(opt)
.clone(BASE_REPO_URL, &temp_clone_dir)?;
cfg_if::cfg_if! {
if #[cfg(feature = "git2")] {
clone_repo_with_git2(&temp_clone_dir)?;
} else if #[cfg(feature = "gix")] {
clone_repo_with_gix(&temp_clone_dir)?;
} else {
eyre::bail!("git command is not found. Either install it, or enable git2 or gix feature for this CLI.");
}
}
}

Ok(temp_clone_dir)
@@ -139,3 +143,23 @@ fn git_exists() -> bool {
}
}
}

#[cfg(feature = "git2")]
fn clone_repo_with_git2(temp_clone_dir: &Path) -> eyre::Result<()> {
let mut fetch_options = git2::FetchOptions::new();
fetch_options.depth(1);
git2::build::RepoBuilder::new()
.fetch_options(fetch_options)
.clone(BASE_REPO_URL, temp_clone_dir)?;
Ok(())
}

#[cfg(feature = "gix")]
fn clone_repo_with_gix(temp_clone_dir: &Path) -> eyre::Result<()> {
let mut prepare_clone = gix::prepare_clone(BASE_REPO_URL, temp_clone_dir)?;
let (mut prepare_checkout, _outcome) = prepare_clone
.fetch_then_checkout(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)?;
let (_repo, _outcome) =
prepare_checkout.main_worktree(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)?;
Ok(())
}

0 comments on commit 5a4f2c3

Please sign in to comment.