]> git.ipfire.org Git - thirdparty/git.git/commitdiff
branch: make the advice to force-deleting a conditional one
authorRubén Justo <rjusto@gmail.com>
Thu, 11 Jan 2024 12:40:34 +0000 (13:40 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Jan 2024 01:15:54 +0000 (17:15 -0800)
The error message we show when the user tries to delete a not fully
merged branch describes the error and gives a hint to the user:

error: the branch 'foo' is not fully merged.
If you are sure you want to delete it, run 'git branch -D foo'.

Let's move the hint part so that it is displayed using the advice
machinery:

error: the branch 'foo' is not fully merged
hint: If you are sure you want to delete it, run 'git branch -D foo'
hint: Disable this message with "git config advice.forceDeleteBranch false"

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/advice.txt
advice.c
advice.h
builtin/branch.c

index e0deaf314461f15b323bffe5e2c7093d97247c20..25c091752445a820f9ef9849ab3c37673da42bd7 100644 (file)
@@ -45,6 +45,9 @@ advice.*::
                Advice shown when linkgit:git-fetch[1] takes a long time
                to calculate forced updates after ref updates, or to warn
                that the check is disabled.
+       forceDeleteBranch::
+               Advice shown when a user tries to delete a not fully merged
+               branch without the force option set.
        ignoredHook::
                Advice shown if a hook is ignored because the hook is not
                set as executable.
index 03322caba011cd1f1956d38008f6c37ff902cfdc..f6e4c2f302e9e8686ae515446b7bbd9a5827081f 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -47,6 +47,7 @@ static struct {
        [ADVICE_DETACHED_HEAD]                          = { "detachedHead", 1 },
        [ADVICE_DIVERGING]                              = { "diverging", 1 },
        [ADVICE_FETCH_SHOW_FORCED_UPDATES]              = { "fetchShowForcedUpdates", 1 },
+       [ADVICE_FORCE_DELETE_BRANCH]                    = { "forceDeleteBranch", 1 },
        [ADVICE_GRAFT_FILE_DEPRECATED]                  = { "graftFileDeprecated", 1 },
        [ADVICE_IGNORED_HOOK]                           = { "ignoredHook", 1 },
        [ADVICE_IMPLICIT_IDENTITY]                      = { "implicitIdentity", 1 },
index 74d44d115654fdc6cfa72f51ce3f76c3321663b2..9d4f49ae38bcfe3b0bdf9999cf9d66ee6a95739e 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -21,6 +21,7 @@ enum advice_type {
        ADVICE_DETACHED_HEAD,
        ADVICE_DIVERGING,
        ADVICE_FETCH_SHOW_FORCED_UPDATES,
+       ADVICE_FORCE_DELETE_BRANCH,
        ADVICE_GRAFT_FILE_DEPRECATED,
        ADVICE_IGNORED_HOOK,
        ADVICE_IMPLICIT_IDENTITY,
index 0a32d1b6c851d4cf07bb02be9376d61a8d38e5d3..cfb63cce5fb9dff64106907947d0df25a2c25489 100644 (file)
@@ -24,6 +24,7 @@
 #include "ref-filter.h"
 #include "worktree.h"
 #include "help.h"
+#include "advice.h"
 #include "commit-reach.h"
 
 static const char * const builtin_branch_usage[] = {
@@ -190,9 +191,10 @@ static int check_branch_commit(const char *branchname, const char *refname,
                return -1;
        }
        if (!force && !branch_merged(kinds, branchname, rev, head_rev)) {
-               error(_("the branch '%s' is not fully merged.\n"
-                     "If you are sure you want to delete it, "
-                     "run 'git branch -D %s'"), branchname, branchname);
+               error(_("the branch '%s' is not fully merged"), branchname);
+               advise_if_enabled(ADVICE_FORCE_DELETE_BRANCH,
+                                 _("If you are sure you want to delete it, "
+                                 "run 'git branch -D %s'"), branchname);
                return -1;
        }
        return 0;