@@ -290,6 +290,12 @@ static const char message_advice_ref_needs_force[] =
290290 "or update a remote ref to make it point at a non-commit object,\n"
291291 "without using the '--force' option.\n" );
292292
293+ static const char message_advice_ref_needs_update [] =
294+ N_ ("Updates were rejected because the tip of the remote-tracking\n"
295+ "branch has been updated since the last checkout. You may want\n"
296+ "to integrate those changes locally (e.g., 'git pull ...')\n"
297+ "before forcing an update.\n" );
298+
293299static void advise_pull_before_push (void )
294300{
295301 if (!advice_push_non_ff_current || !advice_push_update_rejected )
@@ -325,6 +331,13 @@ static void advise_ref_needs_force(void)
325331 advise (_ (message_advice_ref_needs_force ));
326332}
327333
334+ static void advise_ref_needs_update (void )
335+ {
336+ if (!advice_push_ref_needs_update || !advice_push_update_rejected )
337+ return ;
338+ advise (_ (message_advice_ref_needs_update ));
339+ }
340+
328341static int push_with_options (struct transport * transport , struct refspec * rs ,
329342 int flags )
330343{
@@ -374,6 +387,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
374387 advise_ref_fetch_first ();
375388 } else if (reject_reasons & REJECT_NEEDS_FORCE ) {
376389 advise_ref_needs_force ();
390+ } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE ) {
391+ advise_ref_needs_update ();
377392 }
378393
379394 return 1 ;
@@ -510,6 +525,12 @@ static int git_push_config(const char *k, const char *v, void *cb)
510525 if (!v )
511526 return config_error_nonbool (k );
512527 return color_parse (v , push_colors [slot ]);
528+ } else if (!strcmp (k , "push.useforceifincludes" )) {
529+ if (git_config_bool (k , v ))
530+ * flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES ;
531+ else
532+ * flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES ;
533+ return 0 ;
513534 }
514535
515536 return git_default_config (k , v , NULL );
@@ -541,6 +562,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
541562 OPT_CALLBACK_F (0 , CAS_OPT_NAME , & cas , N_ ("<refname>:<expect>" ),
542563 N_ ("require old value of ref to be at this value" ),
543564 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP , parseopt_push_cas_option ),
565+ OPT_BIT (0 , TRANS_OPT_FORCE_IF_INCLUDES , & flags ,
566+ N_ ("require remote updates to be integrated locally" ),
567+ TRANSPORT_PUSH_FORCE_IF_INCLUDES ),
544568 OPT_CALLBACK (0 , "recurse-submodules" , & recurse_submodules , "(check|on-demand|no)" ,
545569 N_ ("control recursive pushing of submodules" ), option_parse_recurse_submodules ),
546570 OPT_BOOL_F ( 0 , "thin" , & thin , N_ ("use thin pack" ), PARSE_OPT_NOCOMPLETE ),
@@ -625,6 +649,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
625649 if ((flags & TRANSPORT_PUSH_ALL ) && (flags & TRANSPORT_PUSH_MIRROR ))
626650 die (_ ("--all and --mirror are incompatible" ));
627651
652+ if (!is_empty_cas (& cas ) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES ))
653+ cas .use_force_if_includes = 1 ;
654+
628655 for_each_string_list_item (item , push_options )
629656 if (strchr (item -> string , '\n' ))
630657 die (_ ("push options must not have new line characters" ));
0 commit comments