]> git.ipfire.org Git - thirdparty/git.git/commitdiff
branch: let delete_branches skip unmerged branches on bulk refusal
authorHarald Nordgren <haraldnordgren@gmail.com>
Sat, 25 Jul 2026 11:32:12 +0000 (11:32 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Jul 2026 17:15:03 +0000 (10:15 -0700)
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>
builtin/branch.c

index e905a13a953e94b25b180e817bdd529055bdbd00..568ae817d6c2bcc29821527f8dd7450994cadebe 100644 (file)
@@ -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;
                }