pushing works with hard-coded ref
This commit is contained in:
parent
0c5323af9d
commit
c49b076cef
1 changed files with 28 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
use git2::Repository;
|
||||
use git2::{Cred, PushOptions, Remote, RemoteCallbacks, Repository};
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
use crate::common::{self, Refractr};
|
||||
|
@ -16,13 +16,15 @@ fn set_up_work_dir(work_dir: PathBuf) -> String {
|
|||
work_dir.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
fn fast_forward(repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Error> {
|
||||
let repo = Repository::open(repo_dir)?;
|
||||
let branch_list: Vec<String> = match branches {
|
||||
fn get_branches(repo: &Repository, branches: &Option<Vec<String>>) -> Vec<String> {
|
||||
match branches {
|
||||
Some(repo_branches) => repo_branches.to_vec(),
|
||||
None => {
|
||||
let mut strings = Vec::new();
|
||||
let remote_branches = repo.branches(Some(git2::BranchType::Remote))?;
|
||||
let remote_branches = match repo.branches(Some(git2::BranchType::Remote)) {
|
||||
Ok(b) => b,
|
||||
Err(e) => panic!("refractr: failed to get branches: {}", e)
|
||||
};
|
||||
for branch in remote_branches {
|
||||
if let Ok((b, _)) = branch {
|
||||
if let Ok(Some(name)) = b.name() {
|
||||
|
@ -32,7 +34,12 @@ fn fast_forward(repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Er
|
|||
}
|
||||
strings
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn fast_forward(repo_dir: &str, branches: &Option<Vec<String>>) -> Result<(), Error> {
|
||||
let repo = Repository::open(repo_dir)?;
|
||||
let branch_list: Vec<String> = get_branches(&repo, branches);
|
||||
|
||||
repo.find_remote("origin")?.fetch(&branch_list, None, None)?;
|
||||
Ok(())
|
||||
|
@ -82,7 +89,7 @@ pub fn start(refractr: Refractr, cfgs: Vec<ConfigFile>) -> std::io::Result<()> {
|
|||
};
|
||||
|
||||
// create remotes for each "to" repo
|
||||
let mut remote_list = Vec::new();
|
||||
let mut remote_list: Vec<Remote<'_>> = Vec::new();
|
||||
for to in &cfg.config.to {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(to);
|
||||
|
@ -99,6 +106,20 @@ pub fn start(refractr: Refractr, cfgs: Vec<ConfigFile>) -> std::io::Result<()> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for mut remote in remote_list {
|
||||
let mut callbacks = RemoteCallbacks::new();
|
||||
callbacks.credentials(|_,_,_| Cred::ssh_key("git", None, &Path::new(&cfg.config.git.ssh_identity_file), None));
|
||||
let mut push_options = PushOptions::new();
|
||||
push_options.remote_callbacks(callbacks);
|
||||
|
||||
match remote.push::<&str>(&["refs/heads/master"], Some(&mut push_options)) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
eprintln!("refractr: failed to push to remote: {}: {}", remote.url().unwrap(), e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue