]> git.ipfire.org Git - thirdparty/git.git/commitdiff
advice: add diverging advice for novices
authorFelipe Contreras <felipe.contreras@gmail.com>
Wed, 8 Mar 2023 02:48:33 +0000 (20:48 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Mar 2023 17:28:42 +0000 (09:28 -0800)
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>
Documentation/config/advice.txt
advice.c
advice.h

index a00d0100a82ba710ea52470764b047e2aeb38d56..c96b5b2e5d2160c3f6b1147fc6500f22acf06a55 100644 (file)
@@ -136,4 +136,6 @@ advice.*::
                Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1]
                is asked to update index entries outside the current sparse
                checkout.
+       diverging::
+               Advice shown when a fast-forward is not possible.
 --
index fd189689437c7512e549482fe696f7a2d2400cd2..fbc59f9c6d6fabc9bfb014ee5062d95b9411d5e0 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -44,6 +44,7 @@ static struct {
        [ADVICE_COMMIT_BEFORE_MERGE]                    = { "commitBeforeMerge", 1 },
        [ADVICE_DETACHED_HEAD]                          = { "detachedHead", 1 },
        [ADVICE_SUGGEST_DETACHING_HEAD]                 = { "suggestDetachingHead", 1 },
+       [ADVICE_DIVERGING]                              = { "diverging", 1 },
        [ADVICE_FETCH_SHOW_FORCED_UPDATES]              = { "fetchShowForcedUpdates", 1 },
        [ADVICE_GRAFT_FILE_DEPRECATED]                  = { "graftFileDeprecated", 1 },
        [ADVICE_IGNORED_HOOK]                           = { "ignoredHook", 1 },
@@ -217,6 +218,14 @@ void NORETURN die_conclude_merge(void)
 
 void NORETURN die_ff_impossible(void)
 {
+       advise_if_enabled(ADVICE_DIVERGING,
+               _("Diverging branches can't be fast-forwarded, you need to either:\n"
+               "\n"
+               "\tgit merge --no-ff\n"
+               "\n"
+               "or:\n"
+               "\n"
+               "\tgit rebase\n"));
        die(_("Not possible to fast-forward, aborting."));
 }
 
index 07e0f76833e78070a26ec288db929ec966024d7e..41b5bc127ce24753cc763924ac0be4cdb9324165 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -21,6 +21,7 @@ struct string_list;
        ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
        ADVICE_COMMIT_BEFORE_MERGE,
        ADVICE_DETACHED_HEAD,
+       ADVICE_DIVERGING,
        ADVICE_SUGGEST_DETACHING_HEAD,
        ADVICE_FETCH_SHOW_FORCED_UPDATES,
        ADVICE_GRAFT_FILE_DEPRECATED,