multi-branch pushing works, now need to do cleanup
This commit is contained in:
parent
1c09b6a5f9
commit
b4c8fbfa6f
1 changed files with 20 additions and 2 deletions
|
@ -57,16 +57,24 @@ impl Refractr {
|
||||||
let analysis = repo.merge_analysis(&[&fetch_commit])?;
|
let analysis = repo.merge_analysis(&[&fetch_commit])?;
|
||||||
if analysis.0.is_fast_forward() {
|
if analysis.0.is_fast_forward() {
|
||||||
for branch in branches {
|
for branch in branches {
|
||||||
let refname = format!("refs/heads/{}", branch);
|
let refname = format!("refs/remotes/origin/{}", branch);
|
||||||
let mut reference = repo.find_reference(&refname)?;
|
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)?;
|
repo.set_head(&refname)?;
|
||||||
let _ = repo.checkout_head(Some(CheckoutBuilder::default().force()));
|
let _ = repo.checkout_head(Some(CheckoutBuilder::default().force()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_up_refs(&self, repo: &Repository, branches: &Vec<String>) -> 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<Vec<String>, String> {
|
fn make_remotes<'a> (&self, repo: &'a Repository, cfg: &ConfigFile) -> Result<Vec<String>, String> {
|
||||||
|
@ -184,6 +192,15 @@ impl Refractr {
|
||||||
self.verbose,
|
self.verbose,
|
||||||
2,
|
2,
|
||||||
format!("Interval for {} has arrived, pulling", repos[i].cfg.from));
|
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);
|
let _ = self.fast_forward(&repos[i].path, &repos[i].cfg.branches);
|
||||||
if let Err(e) = self.push_remotes(
|
if let Err(e) = self.push_remotes(
|
||||||
&repos[i].cfg,
|
&repos[i].cfg,
|
||||||
|
@ -263,6 +280,7 @@ impl Refractr {
|
||||||
};
|
};
|
||||||
|
|
||||||
let repo_fresh = Repository::open(Path::new(&repo_dir)).unwrap();
|
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 origin = repo_fresh.find_remote("origin").unwrap();
|
||||||
let mut refs = Vec::new();
|
let mut refs = Vec::new();
|
||||||
let strings = self.get_refs(&cfg.config.branches);
|
let strings = self.get_refs(&cfg.config.branches);
|
||||||
|
|
Loading…
Add table
Reference in a new issue