mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 11:47:01 +05:30
Shell out to git for thawing repos
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
parent
15b143cbf6
commit
f035df8153
1 changed files with 16 additions and 29 deletions
45
src/main.rs
45
src/main.rs
|
@ -1,9 +1,10 @@
|
||||||
use git2::{Cred, RemoteCallbacks, Repository};
|
use git2::Repository;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
};
|
};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
@ -81,35 +82,21 @@ fn thaw_repos(dir: String) -> anyhow::Result<()> {
|
||||||
let lockfile = fs::read_to_string("gitice.lock").expect("unable to read lockfile!");
|
let lockfile = fs::read_to_string("gitice.lock").expect("unable to read lockfile!");
|
||||||
let repos: HashMap<String, PersistableRepo> = toml::from_str(&lockfile)?;
|
let repos: HashMap<String, PersistableRepo> = toml::from_str(&lockfile)?;
|
||||||
|
|
||||||
let mut callbacks = RemoteCallbacks::new();
|
|
||||||
callbacks.credentials(|_url, username_from_url, _allowed_types| {
|
|
||||||
Cred::ssh_key(
|
|
||||||
username_from_url.unwrap(),
|
|
||||||
None,
|
|
||||||
Path::new(&format!(
|
|
||||||
"{}/.ssh/id_rsa",
|
|
||||||
std::env::var("HOME").expect("unable to find homedir!")
|
|
||||||
)),
|
|
||||||
// TODO: implement for keys that require a passphrase
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut fo = git2::FetchOptions::new();
|
|
||||||
fo.remote_callbacks(callbacks);
|
|
||||||
|
|
||||||
let mut builder = git2::build::RepoBuilder::new();
|
|
||||||
builder.fetch_options(fo);
|
|
||||||
|
|
||||||
for (name, repo) in repos {
|
for (name, repo) in repos {
|
||||||
match builder.clone(&repo.remote_url, PathBuf::from(&dir).join(&name).as_path()) {
|
let output = Command::new("git")
|
||||||
Ok(_) => {
|
.args(&[
|
||||||
println!("Thawed {}", name);
|
"clone",
|
||||||
}
|
&repo.remote_url,
|
||||||
Err(e) => {
|
PathBuf::from(&dir).join(&name).to_str().unwrap(),
|
||||||
println!("Error thawing {}: {}. Continuing...", name, e);
|
])
|
||||||
}
|
.output()
|
||||||
};
|
.expect("Failed to run `git clone`. Perhaps git is not installed?");
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
println!("Thawed {} successfully.", name)
|
||||||
|
} else {
|
||||||
|
println!("{}", std::str::from_utf8(&output.stderr)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue