branch: let delete_branches skip unmerged branches on bulk refusal
Add a skip-unmerged mode to delete_branches() and check_branch_commit() so a bulk caller can silently skip branches that are not fully merged and carry on, rather than erroring with the "use 'git branch -D'" advice that the plain "git branch -d" path emits. Existing callers are unaffected. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>next
parent
271c047f1b
commit
3b329696f9
|
|
@ -192,6 +192,7 @@ static int branch_merged(int kind, const char *name,
|
|||
enum delete_branch_flags {
|
||||
DELETE_BRANCH_FORCE = (1 << 0),
|
||||
DELETE_BRANCH_QUIET = (1 << 1),
|
||||
DELETE_BRANCH_SKIP_UNMERGED = (1 << 2),
|
||||
};
|
||||
|
||||
static int check_branch_commit(const char *branchname, const char *refname,
|
||||
|
|
@ -205,10 +206,13 @@ static int check_branch_commit(const char *branchname, const char *refname,
|
|||
}
|
||||
if (!(flags & DELETE_BRANCH_FORCE) &&
|
||||
!branch_merged(kinds, branchname, rev, head_rev)) {
|
||||
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);
|
||||
if (!(flags & DELETE_BRANCH_SKIP_UNMERGED)) {
|
||||
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;
|
||||
|
|
@ -315,7 +319,8 @@ static int delete_branches(int argc, const char **argv, int kinds,
|
|||
if (!(ref_flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
|
||||
check_branch_commit(bname.buf, name, &oid, head_rev, kinds,
|
||||
flags)) {
|
||||
ret = 1;
|
||||
if (!(flags & DELETE_BRANCH_SKIP_UNMERGED))
|
||||
ret = 1;
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue