mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-17 13:47:01 +05:30
feat(thaw): clone repos using gitoxide (#34)
This commit is contained in:
parent
3b78e69d90
commit
7a64002820
3 changed files with 527 additions and 40 deletions
33
src/git.rs
33
src/git.rs
|
@ -5,7 +5,6 @@ use std::{
|
|||
collections::HashMap,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
|
@ -91,22 +90,26 @@ pub fn thaw_repos(dir: &str, lockfile: &str) -> anyhow::Result<()> {
|
|||
let lockfile = fs::read_to_string(lockfile).context(format!("Failed to read {lockfile}"))?;
|
||||
let repos: HashMap<String, PersistableRepo> = toml::from_str(&lockfile)?;
|
||||
|
||||
// Clone each repo
|
||||
for (name, repo) in repos {
|
||||
let local_path = PathBuf::from(&dir).join(&name);
|
||||
|
||||
let mut prepare_clone = gix::prepare_clone(repo.remote_url.clone(), local_path)
|
||||
.context(format!("Failed to prepare cloning of repository {name}"))?;
|
||||
|
||||
tracing::info!("Cloning {name} from {}", &repo.remote_url);
|
||||
let output = Command::new("git")
|
||||
.args([
|
||||
"clone",
|
||||
&repo.remote_url,
|
||||
PathBuf::from(&dir).join(&name).to_str().expect("msg"),
|
||||
])
|
||||
.output()
|
||||
.context("Failed to run `git clone`. Perhaps git is not installed?")?;
|
||||
|
||||
if output.status.success() {
|
||||
tracing::info!("Thawed {name} successfully.");
|
||||
} else {
|
||||
tracing::error!("{}", std::str::from_utf8(&output.stderr)?);
|
||||
}
|
||||
|
||||
let (mut prepare_checkout, _) = prepare_clone
|
||||
.fetch_then_checkout(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
|
||||
.context("Failed to clone repository")?;
|
||||
|
||||
tracing::info!("Checking out main worktree...");
|
||||
|
||||
prepare_checkout
|
||||
.main_worktree(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
|
||||
.context("Failed to checkout main worktree")?;
|
||||
|
||||
tracing::info!("Thawed {name} successfully.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue