advice: add diverging advice for novices

The user might not necessarily know why ff only was configured, maybe an admin did it, or the installer (Git for Windows), or perhaps they just followed some online advice. This can happen not only on pull.ff=only, but merge.ff=only too. Even worse if the user has configured pull.rebase=false and merge.ff=only, because in those cases a diverging merge will constantly keep failing. There's no trivial way to get out of this other than `git merge --no-ff`. Let's not assume our users are experts in git who completely understand all their configurations. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Mar 7, 2023 at 20:48 UTC 765071a8f27fcaae27ce940b3a784b9d586faa12
3 files changed +12
Documentation/config/advice.txt
+2
@@ -136,4 +136,6 @@ advice.*::
136 Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1]
137 is asked to update index entries outside the current sparse
138 checkout.
139 + diverging::
140 + Advice shown when a fast-forward is not possible.
141 --
advice.c
+9
@@ -44,6 +44,7 @@ static struct {
44 [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 },
45 [ADVICE_DETACHED_HEAD] = { "detachedHead", 1 },
46 [ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead", 1 },
47 + [ADVICE_DIVERGING] = { "diverging", 1 },
48 [ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 },
49 [ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
50 [ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
@@ -217,6 +218,14 @@ void NORETURN die_conclude_merge(void)
218
219 void NORETURN die_ff_impossible(void)
220 {
221 + advise_if_enabled(ADVICE_DIVERGING,
222 + _("Diverging branches can't be fast-forwarded, you need to either:\n"
223 + "\n"
224 + "\tgit merge --no-ff\n"
225 + "\n"
226 + "or:\n"
227 + "\n"
228 + "\tgit rebase\n"));
229 die(_("Not possible to fast-forward, aborting."));
230 }
231
advice.h
+1
@@ -21,6 +21,7 @@ struct string_list;
21 ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
22 ADVICE_COMMIT_BEFORE_MERGE,
23 ADVICE_DETACHED_HEAD,
24 + ADVICE_DIVERGING,
25 ADVICE_SUGGEST_DETACHING_HEAD,
26 ADVICE_FETCH_SHOW_FORCED_UPDATES,
27 ADVICE_GRAFT_FILE_DEPRECATED,