@@ -324,7 +324,7 @@ static const char *config_get_ff(void)
324
324
* looks for the value of "pull.rebase". If both configuration keys do not
325
325
* exist, returns REBASE_FALSE.
326
326
*/
327
- static enum rebase_type config_get_rebase (void )
327
+ static enum rebase_type config_get_rebase (int * rebase_unspecified )
328
328
{
329
329
struct branch * curr_branch = branch_get ("HEAD" );
330
330
const char * value ;
@@ -344,20 +344,7 @@ static enum rebase_type config_get_rebase(void)
344
344
if (!git_config_get_value ("pull.rebase" , & value ))
345
345
return parse_config_rebase ("pull.rebase" , value , 1 );
346
346
347
- if (opt_verbosity >= 0 && !opt_ff ) {
348
- advise (_ ("Pulling without specifying how to reconcile divergent branches is\n"
349
- "discouraged. You can squelch this message by running one of the following\n"
350
- "commands sometime before your next pull:\n"
351
- "\n"
352
- " git config pull.rebase false # merge (the default strategy)\n"
353
- " git config pull.rebase true # rebase\n"
354
- " git config pull.ff only # fast-forward only\n"
355
- "\n"
356
- "You can replace \"git config\" with \"git config --global\" to set a default\n"
357
- "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
358
- "or --ff-only on the command line to override the configured default per\n"
359
- "invocation.\n" ));
360
- }
347
+ * rebase_unspecified = 1 ;
361
348
362
349
return REBASE_FALSE ;
363
350
}
@@ -924,13 +911,45 @@ static int run_rebase(const struct object_id *newbase,
924
911
return ret ;
925
912
}
926
913
914
+ static int get_can_ff (struct object_id * orig_head , struct object_id * orig_merge_head )
915
+ {
916
+ int ret ;
917
+ struct commit_list * list = NULL ;
918
+ struct commit * merge_head , * head ;
919
+
920
+ head = lookup_commit_reference (the_repository , orig_head );
921
+ commit_list_insert (head , & list );
922
+ merge_head = lookup_commit_reference (the_repository , orig_merge_head );
923
+ ret = repo_is_descendant_of (the_repository , merge_head , list );
924
+ free_commit_list (list );
925
+ return ret ;
926
+ }
927
+
928
+ static void show_advice_pull_non_ff (void )
929
+ {
930
+ advise (_ ("Pulling without specifying how to reconcile divergent branches is\n"
931
+ "discouraged. You can squelch this message by running one of the following\n"
932
+ "commands sometime before your next pull:\n"
933
+ "\n"
934
+ " git config pull.rebase false # merge (the default strategy)\n"
935
+ " git config pull.rebase true # rebase\n"
936
+ " git config pull.ff only # fast-forward only\n"
937
+ "\n"
938
+ "You can replace \"git config\" with \"git config --global\" to set a default\n"
939
+ "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
940
+ "or --ff-only on the command line to override the configured default per\n"
941
+ "invocation.\n" ));
942
+ }
943
+
927
944
int cmd_pull (int argc , const char * * argv , const char * prefix )
928
945
{
929
946
const char * repo , * * refspecs ;
930
947
struct oid_array merge_heads = OID_ARRAY_INIT ;
931
948
struct object_id orig_head , curr_head ;
932
949
struct object_id rebase_fork_point ;
933
950
int autostash ;
951
+ int rebase_unspecified = 0 ;
952
+ int can_ff ;
934
953
935
954
if (!getenv ("GIT_REFLOG_ACTION" ))
936
955
set_reflog_message (argc , argv );
@@ -952,7 +971,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
952
971
opt_ff = xstrdup_or_null (config_get_ff ());
953
972
954
973
if (opt_rebase < 0 )
955
- opt_rebase = config_get_rebase ();
974
+ opt_rebase = config_get_rebase (& rebase_unspecified );
956
975
957
976
if (read_cache_unmerged ())
958
977
die_resolve_conflict ("pull" );
@@ -1026,6 +1045,13 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1026
1045
if (opt_rebase && merge_heads .nr > 1 )
1027
1046
die (_ ("Cannot rebase onto multiple branches." ));
1028
1047
1048
+ can_ff = get_can_ff (& orig_head , & merge_heads .oid [0 ]);
1049
+
1050
+ if (rebase_unspecified && !opt_ff && !can_ff ) {
1051
+ if (opt_verbosity >= 0 )
1052
+ show_advice_pull_non_ff ();
1053
+ }
1054
+
1029
1055
if (opt_rebase ) {
1030
1056
int ret = 0 ;
1031
1057
int ran_ff = 0 ;
@@ -1040,22 +1066,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1040
1066
submodule_touches_in_range (the_repository , & upstream , & curr_head ))
1041
1067
die (_ ("cannot rebase with locally recorded submodule modifications" ));
1042
1068
if (!autostash ) {
1043
- struct commit_list * list = NULL ;
1044
- struct commit * merge_head , * head ;
1045
-
1046
- head = lookup_commit_reference (the_repository ,
1047
- & orig_head );
1048
- commit_list_insert (head , & list );
1049
- merge_head = lookup_commit_reference (the_repository ,
1050
- & merge_heads .oid [0 ]);
1051
- if (repo_is_descendant_of (the_repository ,
1052
- merge_head , list )) {
1069
+ if (can_ff ) {
1053
1070
/* we can fast-forward this without invoking rebase */
1054
1071
opt_ff = "--ff-only" ;
1055
1072
ran_ff = 1 ;
1056
1073
ret = run_merge ();
1057
1074
}
1058
- free_commit_list (list );
1059
1075
}
1060
1076
if (!ran_ff )
1061
1077
ret = run_rebase (& newbase , & upstream );
0 commit comments