diff --git a/src/cli/init.rs b/src/cli/init.rs index 98279df..ad48f66 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -167,7 +167,7 @@ pub async fn execute(args: Args) { "{} Pushing changes to remote...", style("[4/4]").bold().dim(), ); - common::git_push("origin", "main").unwrap_or_else(|err| { + common::git_push("origin", &["refs/heads/main"]).unwrap_or_else(|err| { eprintln!("Unable to push to remote: {err}"); exit(1); }); diff --git a/src/cli/push.rs b/src/cli/push.rs index 966a9c4..bad7eb4 100644 --- a/src/cli/push.rs +++ b/src/cli/push.rs @@ -1,5 +1,4 @@ use clap::Parser; -use git2::{Cred, PushOptions, RemoteCallbacks}; use std::process::exit; use crate::common; @@ -12,31 +11,15 @@ pub struct Args { } pub fn execute(args: Args) { - let repo = common::get_araki_git_repo().unwrap_or_else(|err| { - eprintln!("Couldn't recognize the araki repo: {err}"); + common::git_push( + "origin", + &[ + "refs/heads/main", + format!("refs/tags/{}", args.tag).as_str(), + ], + ) + .unwrap_or_else(|err| { + eprintln!("Unable to push to remote: {err}"); exit(1); - }); - let mut remote = repo.find_remote("origin").unwrap(); - - let mut callbacks = RemoteCallbacks::new(); - // TODO: allow user to configure their ssh key - callbacks.credentials(|_url, username_from_url, _allowed_types| { - Cred::ssh_key_from_agent(username_from_url.unwrap()) - }); - - let mut push_opts = PushOptions::new(); - push_opts.remote_callbacks(callbacks); - - // Push changes - remote - .push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) - .expect("Unable to push changes"); - - // Push all tags - remote - .push( - &[format!("refs/tags/{}:refs/tags/{}", args.tag, args.tag)], - Some(&mut push_opts), - ) - .expect("Unable to push tags"); + }) } diff --git a/src/common.rs b/src/common.rs index 358f9c0..d166764 100644 --- a/src/common.rs +++ b/src/common.rs @@ -141,7 +141,7 @@ fn generate_remote_callbacks() -> RemoteCallbacks<'static> { callbacks } -pub fn git_push(remote: &str, branch: &str) -> Result<(), git2::Error> { +pub fn git_push(remote: &str, refs: &[&str]) -> Result<(), git2::Error> { let callbacks = generate_remote_callbacks(); let mut push_options = PushOptions::new(); @@ -149,7 +149,7 @@ pub fn git_push(remote: &str, branch: &str) -> Result<(), git2::Error> { let repo = get_araki_git_repo().map_err(|err| git2::Error::from_str(format!("{err}").as_str()))?; let mut origin = repo.find_remote(remote)?; - origin.push(&[format!("refs/heads/{branch}")], Some(&mut push_options))?; + origin.push(refs, Some(&mut push_options))?; Ok(()) }