fast forwarding works now
This commit is contained in:
parent
dc86ad15fe
commit
f86fb79e73
1 changed files with 20 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
|
||||
use git2::{BranchType, Cred, PushOptions, RemoteCallbacks, Repository};
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
use crate::common::{self, Refractr};
|
||||
|
@ -15,6 +15,7 @@ use std::sync::Arc;
|
|||
|
||||
struct OpenedRepository {
|
||||
repo: Repository,
|
||||
path: String,
|
||||
remotes: Vec<String>,
|
||||
cfg: Config,
|
||||
}
|
||||
|
@ -61,11 +62,25 @@ fn get_branches(repo: &Repository, branches: &Option<Vec<String>>, refs: bool) -
|
|||
}
|
||||
}
|
||||
|
||||
fn fast_forward(repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Error> {
|
||||
fn fast_forward(refractr: &Refractr, repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Error> {
|
||||
let repo = Repository::open(repo_dir)?;
|
||||
let branch_list: Vec<String> = get_branches(&repo, branches, false);
|
||||
|
||||
common::verbose(refractr.verbose, 2, format!("Pulling origin"));
|
||||
repo.find_remote("origin")?.fetch(&branch_list, None, None)?;
|
||||
|
||||
for branch in branch_list {
|
||||
let local_branch = repo.find_branch(&branch, BranchType::Local).unwrap();
|
||||
let local_commit = local_branch.get().peel_to_commit().unwrap();
|
||||
|
||||
let origin_branch = repo.find_branch(&format!("origin/{}", branch), BranchType::Remote).unwrap();
|
||||
let origin_commit = origin_branch.get().peel_to_commit().unwrap();
|
||||
|
||||
if local_commit.id() < origin_commit.id() {
|
||||
local_branch.into_reference().set_target(origin_commit.id(), "Fast-forwarding").unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -149,7 +164,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));
|
||||
let _ = fast_forward(&repos[i].repo.path().to_string_lossy(), &repos[i].cfg.branches);
|
||||
let _ = fast_forward(&refractr, &repos[i].path, &repos[i].cfg.branches);
|
||||
push_remotes(&refractr, &repos[i].cfg, &repos[i].repo, &repos[i].remotes);
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +211,7 @@ pub fn run(refractr: Refractr, cfgs: Vec<ConfigFile>) -> std::io::Result<()> {
|
|||
Ok(repo) => repo,
|
||||
Err(_) => {
|
||||
eprintln!("refractr: warning: found existing repo at {}, attempting to use", repo_dir);
|
||||
match fast_forward(repo_dir, &cfg.config.branches) {
|
||||
match fast_forward(&refractr, repo_dir, &cfg.config.branches) {
|
||||
Ok(_) => if let Ok(repo) = Repository::open(Path::new(&repo_dir)) {
|
||||
repo
|
||||
} else {
|
||||
|
@ -214,6 +229,7 @@ pub fn run(refractr: Refractr, cfgs: Vec<ConfigFile>) -> std::io::Result<()> {
|
|||
if cfg.config.schedule.enabled {
|
||||
loop_repos.push(OpenedRepository {
|
||||
repo,
|
||||
path: path_str,
|
||||
remotes,
|
||||
cfg: cfg.config
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue