mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 00:14:52 +03:00
Set tracking branch on push (#452)
set upstream on each push (if not already defined). closes #275
This commit is contained in:
parent
44ba5a83c9
commit
2b7d7f467b
@ -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 =
|
||||
|
@ -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<BasicAuthCredential>,
|
||||
progress_sender: Sender<ProgressNotification>,
|
||||
) -> 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(())
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user