Skip to content

Commit 765071a

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 725f570 commit 765071a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Documentation/config/advice.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,6 @@ advice.*::
136136
Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1]
137137
is asked to update index entries outside the current sparse
138138
checkout.
139+
diverging::
140+
Advice shown when a fast-forward is not possible.
139141
--

advice.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static struct {
4444
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 },
4545
[ADVICE_DETACHED_HEAD] = { "detachedHead", 1 },
4646
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead", 1 },
47+
[ADVICE_DIVERGING] = { "diverging", 1 },
4748
[ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 },
4849
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
4950
[ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
@@ -217,6 +218,14 @@ void NORETURN die_conclude_merge(void)
217218

218219
void NORETURN die_ff_impossible(void)
219220
{
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"));
220229
die(_("Not possible to fast-forward, aborting."));
221230
}
222231

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct string_list;
2121
ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
2222
ADVICE_COMMIT_BEFORE_MERGE,
2323
ADVICE_DETACHED_HEAD,
24+
ADVICE_DIVERGING,
2425
ADVICE_SUGGEST_DETACHING_HEAD,
2526
ADVICE_FETCH_SHOW_FORCED_UPDATES,
2627
ADVICE_GRAFT_FILE_DEPRECATED,

0 commit comments

Comments
 (0)