Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
37 changes: 10 additions & 27 deletions src/cli/push.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::Parser;
use git2::{Cred, PushOptions, RemoteCallbacks};
use std::process::exit;

use crate::common;
Expand All @@ -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");
})
}
4 changes: 2 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ 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();
push_options.remote_callbacks(callbacks);
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(())
}

Expand Down