mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-15 12:17:18 +02:00
Move a bunch of git ops to use the git binary (#302)
This commit is contained in:
@@ -1,37 +1,20 @@
|
||||
use crate::callbacks::default_callbacks;
|
||||
use crate::binary::new_binary_command;
|
||||
use crate::error::Error::GenericError;
|
||||
use crate::error::Result;
|
||||
use crate::repository::open_repo;
|
||||
use git2::{FetchOptions, ProxyOptions, Repository};
|
||||
use std::path::Path;
|
||||
|
||||
pub(crate) fn git_fetch_all(dir: &Path) -> Result<()> {
|
||||
let repo = open_repo(dir)?;
|
||||
let remotes = repo.remotes()?.iter().flatten().map(String::from).collect::<Vec<_>>();
|
||||
let out = new_binary_command(dir)?
|
||||
.args(["fetch", "--all", "--prune", "--tags"])
|
||||
.output()
|
||||
.map_err(|e| GenericError(format!("failed to run git pull: {e}")))?;
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
let combined = stdout + stderr;
|
||||
|
||||
for (_idx, remote) in remotes.into_iter().enumerate() {
|
||||
fetch_from_remote(&repo, &remote)?;
|
||||
if !out.status.success() {
|
||||
return Err(GenericError(format!("Failed to fetch: {}", combined)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch_from_remote(repo: &Repository, remote: &str) -> Result<()> {
|
||||
let mut remote = repo.find_remote(remote)?;
|
||||
|
||||
let mut options = FetchOptions::new();
|
||||
let callbacks = default_callbacks();
|
||||
|
||||
options.prune(git2::FetchPrune::On);
|
||||
let mut proxy = ProxyOptions::new();
|
||||
proxy.auto();
|
||||
|
||||
options.proxy_options(proxy);
|
||||
options.download_tags(git2::AutotagOption::All);
|
||||
options.remote_callbacks(callbacks);
|
||||
|
||||
remote.fetch(&[] as &[&str], Some(&mut options), None)?;
|
||||
// fetch tags (also removing remotely deleted ones)
|
||||
remote.fetch(&["refs/tags/*:refs/tags/*"], Some(&mut options), None)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user