diff --git a/src/refractr.rs b/src/refractr.rs index 2988c5f..dde7782 100644 --- a/src/refractr.rs +++ b/src/refractr.rs @@ -16,9 +16,19 @@ fn set_up_work_dir(work_dir: PathBuf) -> String { work_dir.to_string_lossy().to_string() } -fn get_branches(repo: &Repository, branches: &Option>) -> Vec { +fn get_branches(repo: &Repository, branches: &Option>, refs: bool) -> Vec { match branches { - Some(repo_branches) => repo_branches.to_vec(), + Some(repo_branches) => { + if refs { + let mut refs_branches = Vec::new(); + for branch in repo_branches { + refs_branches.push(format!("refs/heads/{}", branch)); + } + refs_branches + } else { + repo_branches.to_vec() + } + }, None => { let mut strings = Vec::new(); let remote_branches = match repo.branches(Some(git2::BranchType::Remote)) { @@ -28,7 +38,11 @@ fn get_branches(repo: &Repository, branches: &Option>) -> Vec>) -> Vec>) -> Result<(), Error> { let repo = Repository::open(repo_dir)?; - let branch_list: Vec = get_branches(&repo, branches); + let branch_list: Vec = get_branches(&repo, branches, false); repo.find_remote("origin")?.fetch(&branch_list, None, None)?; Ok(()) @@ -108,12 +122,19 @@ pub fn start(refractr: Refractr, cfgs: Vec) -> std::io::Result<()> { } for mut remote in remote_list { + common::verbose(refractr.verbose, 1, format!("Pushing to remote: {}", remote.url().unwrap())); 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)) { + let mut refs = Vec::new(); + let strings = get_branches(&repo, &cfg.config.branches, true); + for branch in &strings { + refs.push(branch.as_str()); + } + + match remote.push::<&str>(&refs, Some(&mut push_options)) { Ok(_) => (), Err(e) => { eprintln!("refractr: failed to push to remote: {}: {}", remote.url().unwrap(), e)