this should work every time now fr
This commit is contained in:
parent
ba14ce1d81
commit
3b7d30f492
1 changed files with 13 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use git2::build::CheckoutBuilder;
|
||||||
use git2::{BranchType, Cred, PushOptions, RemoteCallbacks, Repository};
|
use git2::{BranchType, Cred, PushOptions, RemoteCallbacks, Repository};
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Sha256, Digest};
|
||||||
|
|
||||||
|
@ -69,19 +70,21 @@ fn fast_forward(refractr: &Refractr, repo_dir: &str, branches: &Option<Vec<Strin
|
||||||
common::verbose(refractr.verbose, 2, format!("Pulling origin"));
|
common::verbose(refractr.verbose, 2, format!("Pulling origin"));
|
||||||
repo.find_remote("origin")?.fetch(&branch_list, None, None)?;
|
repo.find_remote("origin")?.fetch(&branch_list, None, None)?;
|
||||||
|
|
||||||
for branch in branch_list {
|
let fetch_head = repo.find_reference("FETCH_HEAD")?;
|
||||||
let local_branch = repo.find_branch(&branch, BranchType::Local).unwrap();
|
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)?;
|
||||||
let local_commit = local_branch.get().peel_to_commit().unwrap();
|
let analysis = repo.merge_analysis(&[&fetch_commit])?;
|
||||||
|
if analysis.0.is_fast_forward() {
|
||||||
let origin_branch = repo.find_branch(&format!("origin/{}", branch), BranchType::Remote).unwrap();
|
for branch in branch_list {
|
||||||
let origin_commit = origin_branch.get().peel_to_commit().unwrap();
|
let refname = format!("refs/heads/{}", branch);
|
||||||
|
let mut reference = repo.find_reference(&refname)?;
|
||||||
if local_commit.id() < origin_commit.id() {
|
reference.set_target(fetch_commit.id(), "Fast-forward")?;
|
||||||
repo.set_head(format!("origin/{}", branch).as_str())?;
|
repo.set_head(&refname)?;
|
||||||
|
let _ = repo.checkout_head(Some(CheckoutBuilder::default().force()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_remotes<'a> (refractr: &Refractr, repo: &'a Repository, cfg: &ConfigFile) -> Vec<String> {
|
fn make_remotes<'a> (refractr: &Refractr, repo: &'a Repository, cfg: &ConfigFile) -> Vec<String> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue