Skip to content

Commit 7539fdc

Browse files
committed
pull: correct condition to trigger non-ff advice
Refactor the advise() call that teaches users how they can choose between merge and rebase into a helper function. This revealed that the caller's logic needs to be further clarified to allow future actions (like "erroring out" instead of the current "go ahead and merge anyway") that should happen whether the advice message is squelched out. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b044db9 commit 7539fdc

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

builtin/pull.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,22 @@ static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_
925925
return ret;
926926
}
927927

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+
928944
int cmd_pull(int argc, const char **argv, const char *prefix)
929945
{
930946
const char *repo, **refspecs;
@@ -1028,19 +1044,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10281044
if (opt_rebase && merge_heads.nr > 1)
10291045
die(_("Cannot rebase onto multiple branches."));
10301046

1031-
if (rebase_unspecified && opt_verbosity >= 0 && !opt_ff) {
1032-
advise(_("Pulling without specifying how to reconcile divergent branches is\n"
1033-
"discouraged. You can squelch this message by running one of the following\n"
1034-
"commands sometime before your next pull:\n"
1035-
"\n"
1036-
" git config pull.rebase false # merge (the default strategy)\n"
1037-
" git config pull.rebase true # rebase\n"
1038-
" git config pull.ff only # fast-forward only\n"
1039-
"\n"
1040-
"You can replace \"git config\" with \"git config --global\" to set a default\n"
1041-
"preference for all repositories. You can also pass --rebase, --no-rebase,\n"
1042-
"or --ff-only on the command line to override the configured default per\n"
1043-
"invocation.\n"));
1047+
if (rebase_unspecified && !opt_ff) {
1048+
if (opt_verbosity >= 0)
1049+
show_advice_pull_non_ff();
10441050
}
10451051

10461052
if (opt_rebase) {

0 commit comments

Comments
 (0)