File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use crate::{
4
4
error:: { Error , Result } ,
5
5
sync:: { utils, CommitId } ,
6
6
} ;
7
- use git2:: BranchType ;
7
+ use git2:: { BranchType , Repository } ;
8
8
use scopetime:: scope_time;
9
9
use utils:: get_head_repo;
10
10
@@ -87,6 +87,25 @@ pub struct BranchCompare {
87
87
pub behind : usize ,
88
88
}
89
89
90
+ ///
91
+ pub ( crate ) fn branch_set_upstream (
92
+ repo : & Repository ,
93
+ branch_name : & str ,
94
+ ) -> Result < ( ) > {
95
+ scope_time ! ( "branch_set_upstream" ) ;
96
+
97
+ let mut branch =
98
+ repo. find_branch ( branch_name, BranchType :: Local ) ?;
99
+
100
+ if branch. upstream ( ) . is_err ( ) {
101
+ //TODO: what about other remote names
102
+ let upstream_name = format ! ( "origin/{}" , branch_name) ;
103
+ branch. set_upstream ( Some ( upstream_name. as_str ( ) ) ) ?;
104
+ }
105
+
106
+ Ok ( ( ) )
107
+ }
108
+
90
109
///
91
110
pub fn branch_compare_upstream (
92
111
repo_path : & str ,
@@ -97,6 +116,7 @@ pub fn branch_compare_upstream(
97
116
let repo = utils:: repo ( repo_path) ?;
98
117
99
118
let branch = repo. find_branch ( branch, BranchType :: Local ) ?;
119
+
100
120
let upstream = branch. upstream ( ) ?;
101
121
102
122
let branch_commit =
Original file line number Diff line number Diff line change 1
1
//!
2
2
3
- use super :: CommitId ;
3
+ use super :: { branch :: branch_set_upstream , CommitId } ;
4
4
use crate :: {
5
5
error:: Result , sync:: cred:: BasicAuthCredential , sync:: utils,
6
6
} ;
@@ -90,7 +90,7 @@ pub fn push(
90
90
basic_credential : Option < BasicAuthCredential > ,
91
91
progress_sender : Sender < ProgressNotification > ,
92
92
) -> Result < ( ) > {
93
- scope_time ! ( "push_origin " ) ;
93
+ scope_time ! ( "push " ) ;
94
94
95
95
let repo = utils:: repo ( repo_path) ?;
96
96
let mut remote = repo. find_remote ( remote) ?;
@@ -103,7 +103,11 @@ pub fn push(
103
103
) ) ;
104
104
options. packbuilder_parallelism ( 0 ) ;
105
105
106
- remote. push ( & [ branch] , Some ( & mut options) ) ?;
106
+ let branch_name = format ! ( "refs/heads/{}" , branch) ;
107
+
108
+ remote. push ( & [ branch_name. as_str ( ) ] , Some ( & mut options) ) ?;
109
+
110
+ branch_set_upstream ( & repo, branch) ?;
107
111
108
112
Ok ( ( ) )
109
113
}
Original file line number Diff line number Diff line change @@ -377,8 +377,6 @@ impl Status {
377
377
378
378
fn push ( & self ) {
379
379
if let Some ( branch) = self . git_branch_name . last ( ) {
380
- let branch = format ! ( "refs/heads/{}" , branch) ;
381
-
382
380
self . queue
383
381
. borrow_mut ( )
384
382
. push_back ( InternalEvent :: Push ( branch) ) ;
You can’t perform that action at this time.
0 commit comments