summaryrefslogtreecommitdiffstats
path: root/src/repo.rs
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2023-11-27 01:39:25 +0100
committerCyborus <cyborus@cyborus.xyz>2023-11-27 01:39:25 +0100
commit3a62e2d5c8f9dfa133fb48e3de04c8416f82bcbc (patch)
treeb9fab8dddd303e614332c8150b4cf16eb19fc07d /src/repo.rs
parentset private flag to `-P` instead of `-p` to not conflict with push flag (diff)
downloadforgejo-cli-3a62e2d5c8f9dfa133fb48e3de04c8416f82bcbc.tar.xz
forgejo-cli-3a62e2d5c8f9dfa133fb48e3de04c8416f82bcbc.zip
fix repo create push
Diffstat (limited to 'src/repo.rs')
-rw-r--r--src/repo.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/repo.rs b/src/repo.rs
index 0a2c5c1..8ca89e0 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -120,10 +120,22 @@ impl RepoCommand {
if set_upstream.is_some() || push {
let repo = git2::Repository::open(".")?;
+
let upstream = set_upstream.as_deref().unwrap_or("origin");
let mut remote = repo.remote(upstream, new_repo.clone_url.as_str())?;
+
if push {
- remote.push::<&str>(&[], None)?;
+ let head = repo.head()?;
+ if !head.is_branch() {
+ eyre::bail!("HEAD is not on a branch; cannot push to remote");
+ }
+ let branch_shorthand = head.shorthand().ok_or_else(|| eyre!("branch name invalid utf-8"))?.to_owned();
+ let branch_name = std::str::from_utf8(head.name_bytes())?.to_owned();
+ let mut current_branch = git2::Branch::wrap(head);
+ current_branch.set_upstream(Some(&dbg!(format!("{upstream}/{branch_shorthand}"))))?;
+
+ let auth = auth_git2::GitAuthenticator::new();
+ auth.push(&repo, &mut remote, &[&branch_name])?;
}
}
}