Skip to content

Commit bec9bb4

Browse files
rjustogitster
authored andcommitted
branch: make the advice to force-deleting a conditional one
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eddd134 commit bec9bb4

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

Documentation/config/advice.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ advice.*::
4545
Advice shown when linkgit:git-fetch[1] takes a long time
4646
to calculate forced updates after ref updates, or to warn
4747
that the check is disabled.
48+
forceDeleteBranch::
49+
Advice shown when a user tries to delete a not fully merged
50+
branch without the force option set.
4851
ignoredHook::
4952
Advice shown if a hook is ignored because the hook is not
5053
set as executable.

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static struct {
4747
[ADVICE_DETACHED_HEAD] = { "detachedHead", 1 },
4848
[ADVICE_DIVERGING] = { "diverging", 1 },
4949
[ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 },
50+
[ADVICE_FORCE_DELETE_BRANCH] = { "forceDeleteBranch", 1 },
5051
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
5152
[ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
5253
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity", 1 },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum advice_type {
2121
ADVICE_DETACHED_HEAD,
2222
ADVICE_DIVERGING,
2323
ADVICE_FETCH_SHOW_FORCED_UPDATES,
24+
ADVICE_FORCE_DELETE_BRANCH,
2425
ADVICE_GRAFT_FILE_DEPRECATED,
2526
ADVICE_IGNORED_HOOK,
2627
ADVICE_IMPLICIT_IDENTITY,

builtin/branch.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ref-filter.h"
2525
#include "worktree.h"
2626
#include "help.h"
27+
#include "advice.h"
2728
#include "commit-reach.h"
2829

2930
static const char * const builtin_branch_usage[] = {
@@ -190,9 +191,10 @@ static int check_branch_commit(const char *branchname, const char *refname,
190191
return -1;
191192
}
192193
if (!force && !branch_merged(kinds, branchname, rev, head_rev)) {
193-
error(_("the branch '%s' is not fully merged.\n"
194-
"If you are sure you want to delete it, "
195-
"run 'git branch -D %s'"), branchname, branchname);
194+
error(_("the branch '%s' is not fully merged"), branchname);
195+
advise_if_enabled(ADVICE_FORCE_DELETE_BRANCH,
196+
_("If you are sure you want to delete it, "
197+
"run 'git branch -D %s'"), branchname);
196198
return -1;
197199
}
198200
return 0;

0 commit comments

Comments
 (0)