From b4c8fbfa6f1800276c5af486e1cf01a81280f791 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Tue, 11 Mar 2025 21:49:13 -0600 Subject: [PATCH] multi-branch pushing works, now need to do cleanup --- src/refractr.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/refractr.rs b/src/refractr.rs index 7bd2f99..1f89495 100644 --- a/src/refractr.rs +++ b/src/refractr.rs @@ -57,16 +57,24 @@ impl Refractr { let analysis = repo.merge_analysis(&[&fetch_commit])?; if analysis.0.is_fast_forward() { for branch in branches { - let refname = format!("refs/heads/{}", branch); + let refname = format!("refs/remotes/origin/{}", branch); let mut reference = repo.find_reference(&refname)?; - reference.set_target(fetch_commit.id(), "Fast-forward")?; + reference.rename(format!("refs/heads/{}", branch).as_str(), false, "")?; repo.set_head(&refname)?; let _ = repo.checkout_head(Some(CheckoutBuilder::default().force())); } } Ok(()) + } + fn set_up_refs(&self, repo: &Repository, branches: &Vec) -> Result<(), Error> { + for branch in branches { + let mut fetch_head = repo.find_reference(format!("refs/remotes/origin/{}", branch).as_str())?; + fetch_head.rename(format!("refs/heads/{}", branch).as_str(), true, "")?; + } + + Ok(()) } fn make_remotes<'a> (&self, repo: &'a Repository, cfg: &ConfigFile) -> Result, String> { @@ -184,6 +192,15 @@ impl Refractr { self.verbose, 2, format!("Interval for {} has arrived, pulling", repos[i].cfg.from)); + let mut origin = repos[i].repo.find_remote("origin").unwrap(); + let mut refs = Vec::new(); + let strings = self.get_refs(&repos[i].cfg.branches); + for branch in &strings { + refs.push(branch.as_str()); + } + origin.fetch(&refs, None, None).unwrap(); + self.set_up_refs(&repos[i].repo, &repos[i].cfg.branches); + let _ = self.fast_forward(&repos[i].path, &repos[i].cfg.branches); if let Err(e) = self.push_remotes( &repos[i].cfg, @@ -263,6 +280,7 @@ impl Refractr { }; let repo_fresh = Repository::open(Path::new(&repo_dir)).unwrap(); + self.set_up_refs(&repo_fresh, &cfg.config.branches); let mut origin = repo_fresh.find_remote("origin").unwrap(); let mut refs = Vec::new(); let strings = self.get_refs(&cfg.config.branches);