mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 11:47:01 +05:30
Implement thawing for frozen repos
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
parent
1bcbccf30b
commit
15b143cbf6
1 changed files with 42 additions and 4 deletions
46
src/main.rs
46
src/main.rs
|
@ -1,6 +1,10 @@
|
||||||
use git2::Repository;
|
use git2::{Cred, RemoteCallbacks, Repository};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fs, path::Path};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
@ -73,6 +77,40 @@ fn freeze_repos(dir: String) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn thaw_repos(_dir: String) -> anyhow::Result<()> {
|
fn thaw_repos(dir: String) -> anyhow::Result<()> {
|
||||||
|
let lockfile = fs::read_to_string("gitice.lock").expect("unable to read 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 {
|
||||||
|
match builder.clone(&repo.remote_url, PathBuf::from(&dir).join(&name).as_path()) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Thawed {}", name);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error thawing {}: {}. Continuing...", name, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue