@@ -3,7 +3,12 @@ use crate::{
3
3
progress:: ProgressPercent ,
4
4
sync:: {
5
5
branch:: branch_set_upstream_after_push,
6
+ config:: {
7
+ push_default_strategy_config_repo,
8
+ PushDefaultStrategyConfig ,
9
+ } ,
6
10
cred:: BasicAuthCredential ,
11
+ get_branch_upstream_merge,
7
12
remotes:: { proxy_auto, Callbacks } ,
8
13
repository:: repo,
9
14
CommitId , RepoPath ,
@@ -92,7 +97,7 @@ impl AsyncProgress for ProgressNotification {
92
97
}
93
98
94
99
///
95
- #[ derive( Copy , Clone , Debug ) ]
100
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
96
101
pub enum PushType {
97
102
///
98
103
Branch ,
@@ -145,6 +150,9 @@ pub fn push_raw(
145
150
let repo = repo ( repo_path) ?;
146
151
let mut remote = repo. find_remote ( remote) ?;
147
152
153
+ let push_default_strategy =
154
+ push_default_strategy_config_repo ( & repo) ?;
155
+
148
156
let mut options = PushOptions :: new ( ) ;
149
157
options. proxy_options ( proxy_auto ( ) ) ;
150
158
@@ -158,14 +166,28 @@ pub fn push_raw(
158
166
( true , false ) => "+" ,
159
167
( false , false ) => "" ,
160
168
} ;
161
- let ref_type = match ref_type {
169
+ let git_ref_type = match ref_type {
162
170
PushType :: Branch => "heads" ,
163
171
PushType :: Tag => "tags" ,
164
172
} ;
165
173
166
- let branch_name =
167
- format ! ( "{branch_modifier}refs/{ref_type}/{branch}" ) ;
168
- remote. push ( & [ branch_name. as_str ( ) ] , Some ( & mut options) ) ?;
174
+ let mut push_ref =
175
+ format ! ( "{branch_modifier}refs/{git_ref_type}/{branch}" ) ;
176
+
177
+ if !delete
178
+ && ref_type == PushType :: Branch
179
+ && push_default_strategy
180
+ == PushDefaultStrategyConfig :: Upstream
181
+ {
182
+ if let Ok ( Some ( branch_upstream_merge) ) =
183
+ get_branch_upstream_merge ( repo_path, branch)
184
+ {
185
+ push_ref. push_str ( & format ! ( ":{branch_upstream_merge}" ) ) ;
186
+ }
187
+ }
188
+
189
+ log:: debug!( "push to: {push_ref}" ) ;
190
+ remote. push ( & [ push_ref] , Some ( & mut options) ) ?;
169
191
170
192
if let Some ( ( reference, msg) ) =
171
193
callbacks. get_stats ( ) ?. push_rejected_msg
0 commit comments