my dumb ass forgot i already had a fast forward function

This commit is contained in:
Bryson Steck 2025-03-04 23:40:21 -07:00
parent 46a5980432
commit dc86ad15fe
Signed by: brysonsteck
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4

View file

@ -1,4 +1,4 @@
use git2::{Cred, FetchOptions, PushOptions, Remote, RemoteCallbacks, Repository};
use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
use sha2::{Sha256, Digest};
use crate::common::{self, Refractr};
@ -69,23 +69,6 @@ fn fast_forward(repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Er
Ok(())
}
fn fetch_origin(repo: &Repository, branches: &Option<Vec<String>>) {
let mut origin = repo.find_remote("origin").unwrap();
let callbacks = RemoteCallbacks::new();
let mut push_options = FetchOptions::new();
push_options.remote_callbacks(callbacks);
let mut refs = Vec::new();
let strings = get_branches(&repo, &branches, true);
for branch in &strings {
refs.push(branch.as_str());
}
if let Err(e) = origin.download(&[] as &[&str], Some(&mut push_options)) {
eprintln!("refractr: failed to fetch origin: {}: {}", origin.url().unwrap(), e)
}
}
fn make_remotes<'a> (refractr: &Refractr, repo: &'a Repository, cfg: &ConfigFile) -> Vec<String> {
// create remotes for each "to" repo
let mut remote_list = Vec::new();
@ -142,7 +125,7 @@ fn looper(refractr: Refractr, repos: Vec<OpenedRepository>) {
for i in 0..repos.len() {
current_ints.push(u64::from(repos[i].cfg.schedule.interval.unwrap().unsigned_abs()));
};
let mut original_ints = current_ints.clone();
let original_ints = current_ints.clone();
ctrlc::set_handler(move || {
r.store(false, Ordering::SeqCst);
@ -166,8 +149,7 @@ fn looper(refractr: Refractr, repos: Vec<OpenedRepository>) {
if i <= 0 {
current_ints[i] = original_ints[i].clone();
common::verbose(refractr.verbose, 2, format!("Interval for {} has arrived, pulling", repos[i].cfg.from));
fetch_origin(&repos[i].repo, &repos[i].cfg.branches);
common::verbose(refractr.verbose, 2, format!("Pushing {}", repos[i].cfg.from));
let _ = fast_forward(&repos[i].repo.path().to_string_lossy(), &repos[i].cfg.branches);
push_remotes(&refractr, &repos[i].cfg, &repos[i].repo, &repos[i].remotes);
}
}