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 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"));
|
||||
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() {
|
||||
repo.set_head(format!("origin/{}", branch).as_str())?;
|
||||
let fetch_head = repo.find_reference("FETCH_HEAD")?;
|
||||
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)?;
|
||||
let analysis = repo.merge_analysis(&[&fetch_commit])?;
|
||||
if analysis.0.is_fast_forward() {
|
||||
for branch in branch_list {
|
||||
let refname = format!("refs/heads/{}", branch);
|
||||
let mut reference = repo.find_reference(&refname)?;
|
||||
reference.set_target(fetch_commit.id(), "Fast-forward")?;
|
||||
repo.set_head(&refname)?;
|
||||
let _ = repo.checkout_head(Some(CheckoutBuilder::default().force()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
fn make_remotes<'a> (refractr: &Refractr, repo: &'a Repository, cfg: &ConfigFile) -> Vec<String> {
|
||||
|
|
Loading…
Add table
Reference in a new issue