@@ -186,7 +186,7 @@ static const char message_detached_head_die[] =
186
186
" git push %s HEAD:<name-of-remote-branch>\n" );
187
187
188
188
static void setup_push_upstream (struct remote * remote , struct branch * branch ,
189
- int triangular , int simple )
189
+ int same_remote )
190
190
{
191
191
if (!branch )
192
192
die (_ (message_detached_head_die ), remote -> name );
@@ -201,18 +201,12 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
201
201
if (branch -> merge_nr != 1 )
202
202
die (_ ("The current branch %s has multiple upstream branches, "
203
203
"refusing to push." ), branch -> name );
204
- if (triangular )
204
+ if (! same_remote )
205
205
die (_ ("You are pushing to remote '%s', which is not the upstream of\n"
206
206
"your current branch '%s', without telling me what to push\n"
207
207
"to update which remote branch." ),
208
208
remote -> name , branch -> name );
209
209
210
- if (simple ) {
211
- /* Additional safety */
212
- if (strcmp (branch -> refname , branch -> merge [0 ]-> src ))
213
- die_push_simple (branch , remote );
214
- }
215
-
216
210
refspec_appendf (& rs , "%s:%s" , branch -> refname , branch -> merge [0 ]-> src );
217
211
}
218
212
@@ -223,16 +217,41 @@ static void setup_push_current(struct remote *remote, struct branch *branch)
223
217
refspec_appendf (& rs , "%s:%s" , branch -> refname , branch -> refname );
224
218
}
225
219
226
- static int is_workflow_triangular (struct remote * remote )
220
+ static void setup_push_simple (struct remote * remote , struct branch * branch , int same_remote )
221
+ {
222
+ if (!branch )
223
+ die (_ (message_detached_head_die ), remote -> name );
224
+
225
+ if (same_remote ) {
226
+ if (!branch -> merge_nr || !branch -> merge || !branch -> remote_name )
227
+ die (_ ("The current branch %s has no upstream branch.\n"
228
+ "To push the current branch and set the remote as upstream, use\n"
229
+ "\n"
230
+ " git push --set-upstream %s %s\n" ),
231
+ branch -> name ,
232
+ remote -> name ,
233
+ branch -> name );
234
+ if (branch -> merge_nr != 1 )
235
+ die (_ ("The current branch %s has multiple upstream branches, "
236
+ "refusing to push." ), branch -> name );
237
+
238
+ /* Additional safety */
239
+ if (strcmp (branch -> refname , branch -> merge [0 ]-> src ))
240
+ die_push_simple (branch , remote );
241
+ }
242
+ refspec_appendf (& rs , "%s:%s" , branch -> refname , branch -> refname );
243
+ }
244
+
245
+ static int is_same_remote (struct remote * remote )
227
246
{
228
247
struct remote * fetch_remote = remote_get (NULL );
229
- return (fetch_remote && fetch_remote ! = remote );
248
+ return (! fetch_remote || fetch_remote = = remote );
230
249
}
231
250
232
251
static void setup_default_push_refspecs (struct remote * remote )
233
252
{
234
253
struct branch * branch = branch_get (NULL );
235
- int triangular = is_workflow_triangular (remote );
254
+ int same_remote = is_same_remote (remote );
236
255
237
256
switch (push_default ) {
238
257
default :
@@ -242,14 +261,11 @@ static void setup_default_push_refspecs(struct remote *remote)
242
261
243
262
case PUSH_DEFAULT_UNSPECIFIED :
244
263
case PUSH_DEFAULT_SIMPLE :
245
- if (triangular )
246
- setup_push_current (remote , branch );
247
- else
248
- setup_push_upstream (remote , branch , triangular , 1 );
264
+ setup_push_simple (remote , branch , same_remote );
249
265
break ;
250
266
251
267
case PUSH_DEFAULT_UPSTREAM :
252
- setup_push_upstream (remote , branch , triangular , 0 );
268
+ setup_push_upstream (remote , branch , same_remote );
253
269
break ;
254
270
255
271
case PUSH_DEFAULT_CURRENT :
0 commit comments