diff --git a/asyncgit/src/sync/branch.rs b/asyncgit/src/sync/branch.rs index 01426ca1..871958bc 100644 --- a/asyncgit/src/sync/branch.rs +++ b/asyncgit/src/sync/branch.rs @@ -4,7 +4,7 @@ use crate::{ error::{Error, Result}, sync::{utils, CommitId}, }; -use git2::BranchType; +use git2::{BranchType, Repository}; use scopetime::scope_time; use utils::get_head_repo; @@ -87,6 +87,25 @@ pub struct BranchCompare { pub behind: usize, } +/// +pub(crate) fn branch_set_upstream( + repo: &Repository, + branch_name: &str, +) -> Result<()> { + scope_time!("branch_set_upstream"); + + let mut branch = + repo.find_branch(branch_name, BranchType::Local)?; + + if branch.upstream().is_err() { + //TODO: what about other remote names + let upstream_name = format!("origin/{}", branch_name); + branch.set_upstream(Some(upstream_name.as_str()))?; + } + + Ok(()) +} + /// pub fn branch_compare_upstream( repo_path: &str, @@ -97,6 +116,7 @@ pub fn branch_compare_upstream( let repo = utils::repo(repo_path)?; let branch = repo.find_branch(branch, BranchType::Local)?; + let upstream = branch.upstream()?; let branch_commit = diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 67b889f7..c2134b0e 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -1,6 +1,6 @@ //! -use super::CommitId; +use super::{branch::branch_set_upstream, CommitId}; use crate::{ error::Result, sync::cred::BasicAuthCredential, sync::utils, }; @@ -90,7 +90,7 @@ pub fn push( basic_credential: Option, progress_sender: Sender, ) -> Result<()> { - scope_time!("push_origin"); + scope_time!("push"); let repo = utils::repo(repo_path)?; let mut remote = repo.find_remote(remote)?; @@ -103,7 +103,11 @@ pub fn push( )); options.packbuilder_parallelism(0); - remote.push(&[branch], Some(&mut options))?; + let branch_name = format!("refs/heads/{}", branch); + + remote.push(&[branch_name.as_str()], Some(&mut options))?; + + branch_set_upstream(&repo, branch)?; Ok(()) } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index b1c544df..2a61ee07 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -377,8 +377,6 @@ impl Status { fn push(&self) { if let Some(branch) = self.git_branch_name.last() { - let branch = format!("refs/heads/{}", branch); - self.queue .borrow_mut() .push_back(InternalEvent::Push(branch));