🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
17 messages
17 total messages Started by "Harald Nordgren via GitGitGadge... Fri, 20 Nov 2026 14:24
[PATCH v9 0/4] branch: let --delete-merged find squash merged branches
#3449
Author: "Harald Nordgren via GitGitGadge...
Date: Fri, 20 Nov 2026 14:24
194 lines
18537 bytes
Branches merged on GitHub with "Squash and merge" or "Rebase and merge" are
never deleted by git branch --delete-merged, because their tips are not
reachable from the upstream. This adds git branch --delete-integrated
<pattern>, which works like --delete-merged and also deletes such a branch
when some upstream commit contains all of its changes. It names that commit
in the output:

Deleted branch topic (was 1a2b3c4, landed as 9f8e7d6).


Changes in v9:

 * Fix --delete-integrated dying with "unable to read blob object" when a
   path was a submodule at the fork point and both the branch and upstream
   replaced it with different regular files. Such a branch is now kept.
 * Add a test for that case.

Changes in v8:

 * Reword commit messages.

Changes in v7:

 * Added a test that --delete-integrated keeps a branch whose changes did
   not land.
 * Read the index once before the walk in find_landed_commits(), instead of
   for every file merge at every candidate commit.
 * The commit message now says the merge uses this repository's attributes
   from the working tree and the index.

Changes in v6:

 * Read the index before the file merge, so .gitattributes that are only in
   the index are honored too.
 * Renamed the diff_options variables from opt to diffopt.

Changes in v5:

 * git branch -h lists --delete-integrated in the usage lines
 * Giving both --delete-merged and --delete-integrated dies with a short
   "cannot be used together" message instead of the full usage text

Changes in v4:

 * --delete-merged works as it does on master again: it only deletes
   branches whose tip is reachable from their upstream
 * New --delete-integrated <pattern> also deletes branches that were rebase
   or squash merged, including those squashed after upstream changed the
   same files. It replaces --squashed
 * New prep commit lets delete_branches() take a map of where each branch
   landed, so "landed as" is printed there
 * Added Junio's test that --delete-merged keeps a branch when an unrelated
   upstream commit adds an identical file
 * --dry-run works with either option, and the two options can't be combined

Changes in v3:

 * Split into multiple commits, one for rebase merges and one for squash
   merges.
 * By default a branch counts as merged when an upstream commit has its
   exact version of every file it changed. This never reads file contents,
   so it stays cheap in a partial clone. It finds rebase merges, and squash
   merges where upstream left those files alone.
 * Replace --no-squashed with an opt-in --squashed, which also finds
   branches merged after upstream changed the same files by merging those
   files.
 * Add a test for a rebase merge, and check that a squash onto changed files
   is kept without --squashed and deleted with it.

Changes in v2:

 * Diff each upstream commit once and share the result between all branches,
   faster than v1.
 * Fix a branch merged with a merge commit being reported as "landed as" the
   merge when another branch was searched first, and add a test for it. Show
   the topic commit itself in "landed as" for work that arrived through a
   merge.
 * Use git merge --squash as the example in the commit message and mention
   GitHub's squash and rebase buttons.
 * Add --no-squashed to skip the squash search.

Harald Nordgren (4):
  branch: move the deleteMerged opt-out check into a helper
  branch: let delete_branches() name where a branch landed
  branch: add --delete-integrated to delete rebase and squash merged
    branches
  branch: let --delete-integrated find branches merged onto changed
    files

 Documentation/config/branch.adoc |   8 +-
 Documentation/git-branch.adoc    |  23 +-
 builtin/branch.c                 | 363 +++++++++++++++++++++++++++++--
 t/t3200-branch.sh                | 315 +++++++++++++++++++++++++++
 4 files changed, 679 insertions(+), 30 deletions(-)


base-commit: f7de81456940dd6f3274e461149bba12965de609
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2425%2FHaraldNordgren%2Fbranch-delete-squashed-v9
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2425/HaraldNordgren/branch-delete-squashed-v9
Pull-Request: https://github.com/git/git/pull/2425

Range-diff vs v8:

 1:  25d2441ce7 = 1:  37ef7636e0 branch: move the deleteMerged opt-out check into a helper
 2:  18c3edb6e3 = 2:  c4513f9ec1 branch: let delete_branches() name where a branch landed
 3:  7bc634c794 = 3:  1f922a0034 branch: add --delete-integrated to delete rebase and squash merged branches
 4:  22658105ed ! 4:  ef65700303 branch: let --delete-integrated find branches merged onto changed files
     @@ builtin/branch.c: static int branch_pushes_to_upstream(struct branch *branch,
       struct branch_change {
       	char *path;
      -	struct object_id branch_oid;
     +-	unsigned short branch_mode;
      +	struct object_id base_oid, branch_oid, upstream_oid;
     - 	unsigned short branch_mode;
     ++	unsigned short base_mode, branch_mode;
      +	enum change_state state;
       };
       
     @@ builtin/branch.c: static void collect_branch_changes(struct landing_search *sear
      +		       &p->one->oid : null_oid(the_hash_algo));
       		oidcpy(&change->branch_oid, DIFF_FILE_VALID(p->two) ?
       		       &p->two->oid : null_oid(the_hash_algo));
     ++		change->base_mode = p->one->mode;
       		change->branch_mode = p->two->mode;
     -@@ builtin/branch.c: static void collect_branch_changes(struct landing_search *search,
     + 	}
       	diff_flush(&diffopt);
       }
       
     @@ builtin/branch.c: static void collect_branch_changes(struct landing_search *sear
      +	if (is_null_oid(&change->base_oid) ||
      +	    is_null_oid(&change->branch_oid) ||
      +	    oideq(&change->upstream_oid, &change->base_oid) ||
     -+	    mode != change->branch_mode || !S_ISREG(mode))
     ++	    mode != change->branch_mode || !S_ISREG(mode) ||
     ++	    !S_ISREG(change->base_mode))
      +		return CHANGE_MISSING;
      +	return CHANGE_NEEDS_MERGE;
       }
     @@ t/t3200-branch.sh: test_expect_success '--delete-integrated deletes a squash mer
      +		EOF
      +	)
      +'
     ++
     ++test_expect_success '--delete-integrated keeps a branch that replaced a submodule with a file' '
     ++	(
     ++		cd upstream &&
     ++		git checkout next &&
     ++		git init lib &&
     ++		test_commit -C lib in-lib &&
     ++		git add lib &&
     ++		git commit -m "add lib as a submodule" &&
     ++		git checkout main
     ++	) &&
     ++	setup_repo_for_delete_merged &&
     ++	(
     ++		cd repo &&
     ++		git checkout -b replaces-lib --track origin/next &&
     ++		rmdir lib &&
     ++		echo "from the branch" >lib &&
     ++		git add lib &&
     ++		git commit -m "replace lib with a file" &&
     ++		git push origin replaces-lib &&
     ++		git checkout --detach
     ++	) &&
     ++	(
     ++		cd upstream &&
     ++		git checkout next &&
     ++		rm -rf lib &&
     ++		echo "from upstream" >lib &&
     ++		git add lib &&
     ++		git commit -m "replace lib with another file" &&
     ++		git checkout main
     ++	) &&
     ++	(
     ++		cd repo &&
     ++		git fetch origin &&
     ++
     ++		git branch --delete-integrated origin/next >actual 2>&1 &&
     ++		test_must_be_empty actual &&
     ++
     ++		check_branches <<-\EOF
     ++		main
     ++		replaces-lib
     ++		EOF
     ++	)
     ++'
      +
       test_expect_success '--delete-integrated reports a merge plainly next to an unmerged branch' '
       	setup_repo_for_delete_merged &&

-- 
gitgitgadget
[PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
#3448
Author: "Harald Nordgren via GitGitGadge...
Date: Fri, 20 Nov 2026 14:24
74 lines
13387 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>

A later commit adds "git branch --delete-integrated", which deletes
branches whose tips are not reachable from their upstream. Those must
honor branch.<name>.deleteMerged=false as well. Move the check into a
helper so it can be used in both places.

No change in behavior.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/branch.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index b536b619bb..2c1a8b8395 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -824,6 +824,23 @@ static int branch_pushes_to_upstream(struct branch *branch,
 	return ret;
 }
 
+static bool branch_opted_out(struct strbuf *key, const char *branch_name,
+			     unsigned int flags)
+{
+	int opt_out;
+
+	strbuf_reset(key);
+	strbuf_addf(key, "branch.%s.deletemerged", branch_name);
+	if (repo_config_get_bool(the_repository, key->buf, &opt_out) ||
+	    opt_out)
+		return false;
+	if (!(flags & DELETE_BRANCH_QUIET))
+		fprintf(stderr,
+			_("Skipping '%s' (branch.%s.deleteMerged is false)\n"),
+			branch_name, branch_name);
+	return true;
+}
+
 static int delete_merged_branches(const struct strvec *upstreams,
 				 const char **argv, unsigned int flags)
 {
@@ -852,7 +869,6 @@ static int delete_merged_branches(const struct strvec *upstreams,
 		const char *branch_name;
 		struct branch *branch;
 		const char *upstream_refname;
-		int opt_out;
 
 		if (!skip_prefix(branch_refname, "refs/heads/", &branch_name))
 			BUG("filter returned non-branch ref '%s'", branch_refname);
@@ -870,18 +886,8 @@ static int delete_merged_branches(const struct strvec *upstreams,
 					FILTER_REFS_BRANCHES, DELETE_BRANCH_SKIP_UNMERGED))
 			continue;
 
-		strbuf_reset(&key);
-		strbuf_addf(&key, "branch.%s.deletemerged", branch_name);
-		if (!repo_config_get_bool(the_repository, key.buf, &opt_out) &&
-		    !opt_out) {
-			if (!(flags & DELETE_BRANCH_QUIET))
-				fprintf(stderr,
-					_("Skipping '%s' (branch.%s.deleteMerged is false)\n"),
-					branch_name, branch_name);
-			continue;
-		}
-
-		strset_add(&deletable_branch_names, branch_name);
+		if (!branch_opted_out(&key, branch_name, flags))
+			strset_add(&deletable_branch_names, branch_name);
 	}
 
 	protect_stacked_branch_bases(refs, &deletable_branch_names,
-- 
gitgitgadget
[PATCH v9 2/4] branch: let delete_branches() name where a branch landed
#3450
Author: "Harald Nordgren via GitGitGadge...
Date: Fri, 20 Nov 2026 14:24
100 lines
14551 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>

A later commit lets "git branch" delete branches whose commits are not
in their upstream but whose changes are, such as after a squash merge.
Their tips are not reachable from the upstream, so the merge check in
delete_branches() would refuse to delete them, and the output should
say where their changes went.

Let delete_branches() take a map from branch names to the upstream
commit where each branch landed. A branch in the map skips the merge
check and is reported as

    Deleted branch topic (was 1a2b3c4, landed as 9f8e7d6).

No caller passes a map yet, so there is no change in behavior.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/branch.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 2c1a8b8395..6e6b04b11d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -236,7 +236,7 @@ static void delete_branch_config(const char *branchname)
 }
 
 static int delete_branches(int argc, const char **argv, int kinds,
-			   unsigned int flags)
+			   unsigned int flags, struct strmap *landed_commits)
 {
 	struct commit *head_rev = NULL;
 	struct object_id oid;
@@ -334,6 +334,8 @@ static int delete_branches(int argc, const char **argv, int kinds,
 		}
 
 		if (!(ref_flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
+		    !(landed_commits &&
+		      strmap_contains(landed_commits, bname.buf)) &&
 		    check_branch_commit(bname.buf, name, &oid, head_rev, kinds,
 					flags)) {
 			if (!(flags & DELETE_BRANCH_SKIP_UNMERGED))
@@ -357,15 +359,33 @@ static int delete_branches(int argc, const char **argv, int kinds,
 	for_each_string_list_item(item, &refs_to_delete) {
 		char *describe_ref = item->util;
 		char *name = item->string;
+		struct commit *landed = landed_commits ?
+			strmap_get(landed_commits, name + branch_name_pos) : NULL;
+		const char *landed_abbrev = landed ?
+			repo_find_unique_abbrev(the_repository,
+						&landed->object.oid,
+						DEFAULT_ABBREV) : NULL;
+
 		if (flags & DELETE_BRANCH_DRY_RUN) {
-			if (!(flags & DELETE_BRANCH_QUIET))
+			if (flags & DELETE_BRANCH_QUIET)
+				;
+			else if (landed)
+				printf(_("Would delete branch %s (was %s, landed as %s).\n"),
+				       name + branch_name_pos, describe_ref,
+				       landed_abbrev);
+			else
 				printf(remote_branch
 					? _("Would delete remote-tracking branch %s (was %s).\n")
 					: _("Would delete branch %s (was %s).\n"),
 					name + branch_name_pos, describe_ref);
 		} else if (!refs_ref_exists(get_main_ref_store(the_repository), name)) {
 			char *refname = name + branch_name_pos;
-			if (!(flags & DELETE_BRANCH_QUIET))
+			if (flags & DELETE_BRANCH_QUIET)
+				;
+			else if (landed)
+				printf(_("Deleted branch %s (was %s, landed as %s).\n"),
+				       refname, describe_ref, landed_abbrev);
+			else
 				printf(remote_branch
 					? _("Deleted remote-tracking branch %s (was %s).\n")
 					: _("Deleted branch %s (was %s).\n"),
@@ -901,7 +921,7 @@ static int delete_merged_branches(const struct strvec *upstreams,
 				      FILTER_REFS_BRANCHES,
 				      DELETE_BRANCH_SKIP_UNMERGED |
 				      DELETE_BRANCH_NO_HEAD_FALLBACK |
-				      flags);
+				      flags, NULL);
 
 	if (!ret && !(flags & DELETE_BRANCH_DRY_RUN))
 		clear_deleted_upstreams(&protected_branch_names,
@@ -1141,7 +1161,7 @@ int cmd_branch(int argc,
 			die(_("branch name required"));
 		ret = delete_branches(argc, argv, filter.kind,
 				      (delete > 1 ? DELETE_BRANCH_FORCE : 0) |
-				      (quiet ? DELETE_BRANCH_QUIET : 0));
+				      (quiet ? DELETE_BRANCH_QUIET : 0), NULL);
 		goto out;
 	} else if (delete_merged.nr) {
 		ret = delete_merged_branches(&delete_merged, argv,
-- 
gitgitgadget
[PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches
#3452
Author: "Harald Nordgren via GitGitGadge...
Date: Fri, 20 Nov 2026 14:24
669 lines
33232 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>

A branch that upstream integrated with

    git rebase main topic
    git checkout main
    git merge --ff-only topic

or with

    git merge --squash topic
    git commit

is never deleted by "git branch --delete-merged". This is what the
"Rebase and merge" and "Squash and merge" buttons on GitHub do. The
upstream holds rewritten copies of the branch's work, so its tip is not
reachable from it and it looks unmerged forever.

Add --delete-integrated, which does what --delete-merged does and also
deletes a branch when some upstream commit since the fork point has the
branch's version of every file the branch changed. That commit is named
in the output so the user can see where the work went:

    Deleted branch topic (was 1a2b3c4, landed as 9f8e7d6).

The first such commit is used, so the branch is deleted even if
upstream later reverted or reworked the changes. Nothing is lost, since
that commit keeps them in the upstream history. Who made that commit
does not matter, since the local branch is no longer needed either way.
A branch whose changes only partly landed is kept.

--delete-merged keeps deleting only branches whose own commits are in
the upstream, so it never removes a branch because somebody else made
the same change.

The check never reads file contents, so it stays cheap in a partial
clone.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 Documentation/config/branch.adoc |   8 +-
 Documentation/git-branch.adoc    |  19 ++-
 builtin/branch.c                 | 253 ++++++++++++++++++++++++++++++-
 t/t3200-branch.sh                | 176 +++++++++++++++++++++
 4 files changed, 441 insertions(+), 15 deletions(-)

diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
index c2acd89c99..be9b296bda 100644
--- a/Documentation/config/branch.adoc
+++ b/Documentation/config/branch.adoc
@@ -106,7 +106,7 @@ for details).
 
 `branch.<name>.deleteMerged`::
 	If set to `false`, branch _<name>_ is exempt from
-	`git branch --delete-merged`.  Useful for a topic branch you
-	intend to develop further after an initial round has been
-	merged upstream.  Defaults to true.  Explicit deletion via
-	`git branch -d` is unaffected.
+	`git branch --delete-merged` and `--delete-integrated`.  Useful
+	for a topic branch you intend to develop further after an
+	initial round has been merged upstream.  Defaults to true.
+	Explicit deletion via `git branch -d` is unaffected.
diff --git a/Documentation/git-branch.adoc b/Documentation/git-branch.adoc
index a803c24858..b6d9cd01a4 100644
--- a/Documentation/git-branch.adoc
+++ b/Documentation/git-branch.adoc
@@ -26,6 +26,7 @@ git branch (-c|-C) [<old-branch>] <new-branch>
 git branch (-d|-D) [-r] <branch-name>...
 git branch --edit-description [<branch-name>]
 git branch [--dry-run] (--delete-merged <pattern>)... [<branch-pattern>...]
+git branch [--dry-run] (--delete-integrated <pattern>)... [<branch-pattern>...]
 
 DESCRIPTION
 -----------
@@ -235,11 +236,21 @@ A branch whose work has not yet been merged into its upstream is
 silently skipped. Delete it with `git branch -D` if you want to
 remove it anyway.
 
+`--delete-integrated <pattern>`::
+	Like `--delete-merged`, but also delete a branch whose changes
+	the upstream already has even though its commits are not there,
+	as happens after a squash or rebase merge. Such a branch is
+	deleted when some upstream commit since the fork point has its
+	version of every file it changed, even if those changes were
+	later reverted, and the message names the first such commit.
+	It does not matter who made that commit. The same rules for
+	which branches are kept apply as for `--delete-merged`.
+
 `--dry-run`::
-	With `--delete-merged`, print which branches would be
-	deleted and exit without touching any ref.  Useful for
-	sanity-checking a wide pattern like `'origin/*'` before
-	committing to the deletion.
+	With `--delete-merged` or `--delete-integrated`, print which
+	branches would be deleted and exit without touching any ref.
+	Useful for sanity-checking a wide pattern like `'origin/*'`
+	before committing to the deletion.
 
 `-v`::
 `-vv`::
diff --git a/builtin/branch.c b/builtin/branch.c
index 6e6b04b11d..ee92e71f51 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -29,6 +29,12 @@
 #include "help.h"
 #include "advice.h"
 #include "commit-reach.h"
+#include "commit-slab.h"
+#include "diff.h"
+#include "diffcore.h"
+#include "hex.h"
+#include "revision.h"
+#include "tree-walk.h"
 
 static const char * const builtin_branch_usage[] = {
 	N_("git branch [<options>] [-r | -a] [--merged] [--no-merged] [(--forked <branch>)...]"),
@@ -41,6 +47,8 @@ static const char * const builtin_branch_usage[] = {
 	N_("git branch [<options>] [-r | -a] [--format]"),
 	N_("git branch [<options>] (--delete-merged <pattern>)... "
 	   "[<branch-pattern>...]"),
+	N_("git branch [<options>] (--delete-integrated <pattern>)... "
+	   "[<branch-pattern>...]"),
 	NULL
 };
 
@@ -201,6 +209,7 @@ enum delete_branch_flags {
 	DELETE_BRANCH_SKIP_UNMERGED = (1 << 2),
 	DELETE_BRANCH_NO_HEAD_FALLBACK = (1 << 3),
 	DELETE_BRANCH_DRY_RUN = (1 << 4),
+	DELETE_BRANCH_INTEGRATED = (1 << 5),
 };
 
 static int check_branch_commit(const char *branchname, const char *refname,
@@ -844,6 +853,185 @@ static int branch_pushes_to_upstream(struct branch *branch,
 	return ret;
 }
 
+struct branch_change {
+	char *path;
+	struct object_id branch_oid;
+	unsigned short branch_mode;
+};
+
+struct landing_search {
+	const char *branch_name;
+	struct commit *rev;
+	struct commit *upstream;
+	struct branch_change *changes;
+	size_t changes_nr, changes_alloc;
+};
+
+define_commit_slab(changed_paths, struct string_list *);
+
+static void collect_branch_changes(struct landing_search *search,
+				   struct commit *base)
+{
+	struct diff_options diffopt;
+
+	repo_diff_setup(the_repository, &diffopt);
+	diffopt.flags.recursive = 1;
+	diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
+	diff_setup_done(&diffopt);
+	diff_tree_oid(get_commit_tree_oid(base),
+		      get_commit_tree_oid(search->rev), "", &diffopt);
+	for (int i = 0; i < diff_queued_diff.nr; i++) {
+		struct diff_filepair *p = diff_queued_diff.queue[i];
+		struct branch_change *change;
+
+		ALLOC_GROW(search->changes, search->changes_nr + 1,
+			   search->changes_alloc);
+		change = &search->changes[search->changes_nr++];
+		change->path = xstrdup(p->two->path);
+		oidcpy(&change->branch_oid, DIFF_FILE_VALID(p->two) ?
+		       &p->two->oid : null_oid(the_hash_algo));
+		change->branch_mode = p->two->mode;
+	}
+	diff_flush(&diffopt);
+}
+
+static int change_landed(const struct branch_change *change,
+			 struct commit *commit)
+{
+	struct object_id oid;
+	unsigned short mode;
+
+	if (get_tree_entry(the_repository, get_commit_tree_oid(commit),
+			   change->path, &oid, &mode))
+		return is_null_oid(&change->branch_oid);
+	return oideq(&oid, &change->branch_oid) &&
+	       mode == change->branch_mode;
+}
+
+static int changes_landed(struct landing_search *search,
+			  struct commit *commit)
+{
+	for (size_t i = 0; i < search->changes_nr; i++)
+		if (!change_landed(&search->changes[i], commit))
+			return 0;
+	return 1;
+}
+
+static struct string_list *changed_paths_of(struct changed_paths *cache,
+					    struct diff_options *diffopt,
+					    struct commit *commit)
+{
+	struct string_list **paths = changed_paths_at(cache, commit);
+	struct commit *parent;
+
+	if (*paths)
+		return *paths;
+
+	CALLOC_ARRAY(*paths, 1);
+	string_list_init_dup(*paths);
+	parent = commit->parents ? commit->parents->item : NULL;
+	if (parent && repo_parse_commit(the_repository, parent))
+		die(_("could not parse commit %s"),
+		    oid_to_hex(&parent->object.oid));
+	diff_tree_oid(parent ? get_commit_tree_oid(parent) : NULL,
+		      get_commit_tree_oid(commit), "", diffopt);
+	for (int i = 0; i < diff_queued_diff.nr; i++) {
+		struct diff_filepair *p = diff_queued_diff.queue[i];
+
+		string_list_append(*paths, p->two->path);
+	}
+	diff_flush(diffopt);
+	string_list_sort(*paths);
+	return *paths;
+}
+
+static void free_changed_paths(struct string_list **paths)
+{
+	if (!*paths)
+		return;
+	string_list_clear(*paths, 0);
+	free(*paths);
+}
+
+static int touches_changes(struct string_list *paths,
+			   const struct landing_search *search)
+{
+	for (size_t i = 0; i < search->changes_nr; i++)
+		if (string_list_has_string(paths, search->changes[i].path))
+			return 1;
+	return 0;
+}
+
+static struct commit *find_landed_commit(struct landing_search *search,
+					 struct changed_paths *cache,
+					 struct diff_options *diffopt)
+{
+	struct commit *commit, *landed = NULL;
+	struct strvec args = STRVEC_INIT;
+	struct rev_info revs;
+
+	strvec_pushl(&args, "rev-list", "--reverse",
+		     oid_to_hex(&search->upstream->object.oid), NULL);
+	strvec_pushf(&args, "^%s", oid_to_hex(&search->rev->object.oid));
+
+	repo_init_revisions(the_repository, &revs, NULL);
+	setup_revisions_from_strvec(&args, &revs, NULL);
+	if (prepare_revision_walk(&revs))
+		die(_("revision walk setup failed"));
+	while (!landed && (commit = get_revision(&revs)))
+		if (touches_changes(changed_paths_of(cache, diffopt, commit),
+				    search) &&
+		    changes_landed(search, commit))
+			landed = commit;
+	release_revisions(&revs);
+	clear_commit_marks(search->upstream, ALL_REV_FLAGS);
+	clear_commit_marks(search->rev, ALL_REV_FLAGS);
+	strvec_clear(&args);
+	return landed;
+}
+
+static void find_landed_commits(struct landing_search *searches,
+				size_t searches_nr,
+				struct strmap *landed_commits)
+{
+	struct changed_paths cache;
+	struct diff_options diffopt;
+
+	for (size_t i = 0; i < searches_nr; i++) {
+		struct landing_search *search = &searches[i];
+		struct commit_list *merge_bases = NULL;
+
+		if (repo_get_merge_bases(the_repository, search->upstream,
+					 search->rev, &merge_bases) < 0)
+			exit(128);
+		if (merge_bases)
+			collect_branch_changes(search, merge_bases->item);
+		commit_list_free(merge_bases);
+	}
+
+	repo_diff_setup(the_repository, &diffopt);
+	diffopt.flags.recursive = 1;
+	diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
+	diffopt.no_free = 1;
+	diff_setup_done(&diffopt);
+	init_changed_paths(&cache);
+
+	for (size_t i = 0; i < searches_nr; i++) {
+		struct commit *landed;
+
+		if (!searches[i].changes_nr)
+			continue;
+		landed = find_landed_commit(&searches[i], &cache, &diffopt);
+		if (landed)
+			strmap_put(landed_commits, searches[i].branch_name,
+				   landed);
+	}
+
+	deep_clear_changed_paths(&cache, free_changed_paths);
+	diffopt.no_free = 0;
+	diff_free(&diffopt);
+}
+
 static bool branch_opted_out(struct strbuf *key, const char *branch_name,
 			     unsigned int flags)
 {
@@ -869,6 +1057,9 @@ static int delete_merged_branches(const struct strvec *upstreams,
 	struct ref_array candidates = { 0 };
 	struct strset deletable_branch_names = STRSET_INIT;
 	struct strset protected_branch_names = STRSET_INIT;
+	struct strmap landed_commits = STRMAP_INIT;
+	struct landing_search *searches = NULL;
+	size_t searches_nr = 0, searches_alloc = 0;
 	struct strvec branches_to_delete = STRVEC_INIT;
 	struct strbuf key = STRBUF_INIT;
 	struct hashmap_iter iter;
@@ -903,13 +1094,39 @@ static int delete_merged_branches(const struct strvec *upstreams,
 			continue;
 		if (check_branch_commit(branch_name, branch_name,
 					&candidates.items[i]->objectname, NULL,
-					FILTER_REFS_BRANCHES, DELETE_BRANCH_SKIP_UNMERGED))
+					FILTER_REFS_BRANCHES,
+					DELETE_BRANCH_SKIP_UNMERGED)) {
+			struct commit *rev, *upstream;
+
+			if (!(flags & DELETE_BRANCH_INTEGRATED))
+				continue;
+			rev = lookup_commit_reference(
+				the_repository, &candidates.items[i]->objectname);
+			upstream = lookup_commit_reference_by_name(upstream_refname);
+			if (!rev || !upstream)
+				continue;
+			ALLOC_GROW(searches, searches_nr + 1, searches_alloc);
+			searches[searches_nr++] = (struct landing_search) {
+				.branch_name = branch_name,
+				.rev = rev,
+				.upstream = upstream,
+			};
 			continue;
+		}
 
 		if (!branch_opted_out(&key, branch_name, flags))
 			strset_add(&deletable_branch_names, branch_name);
 	}
 
+	find_landed_commits(searches, searches_nr, &landed_commits);
+	for (size_t i = 0; i < searches_nr; i++) {
+		const char *branch_name = searches[i].branch_name;
+
+		if (strmap_contains(&landed_commits, branch_name) &&
+		    !branch_opted_out(&key, branch_name, flags))
+			strset_add(&deletable_branch_names, branch_name);
+	}
+
 	protect_stacked_branch_bases(refs, &deletable_branch_names,
 				     &protected_branch_names);
 
@@ -921,7 +1138,7 @@ static int delete_merged_branches(const struct strvec *upstreams,
 				      FILTER_REFS_BRANCHES,
 				      DELETE_BRANCH_SKIP_UNMERGED |
 				      DELETE_BRANCH_NO_HEAD_FALLBACK |
-				      flags, NULL);
+				      flags, &landed_commits);
 
 	if (!ret && !(flags & DELETE_BRANCH_DRY_RUN))
 		clear_deleted_upstreams(&protected_branch_names,
@@ -929,6 +1146,13 @@ static int delete_merged_branches(const struct strvec *upstreams,
 
 	strbuf_release(&key);
 	strvec_clear(&branches_to_delete);
+	for (size_t i = 0; i < searches_nr; i++) {
+		for (size_t j = 0; j < searches[i].changes_nr; j++)
+			free(searches[i].changes[j].path);
+		free(searches[i].changes);
+	}
+	free(searches);
+	strmap_clear(&landed_commits, 0);
 	strset_clear(&protected_branch_names);
 	strset_clear(&deletable_branch_names);
 	ref_array_clear(&candidates);
@@ -1001,6 +1225,7 @@ int cmd_branch(int argc,
 	int delete = 0, rename = 0, copy = 0, list = 0,
 	    unset_upstream = 0, show_current = 0, edit_description = 0;
 	struct strvec delete_merged = STRVEC_INIT;
+	struct strvec delete_integrated = STRVEC_INIT;
 	int dry_run = 0;
 	const char *new_upstream = NULL;
 	int noncreate_actions = 0;
@@ -1058,8 +1283,11 @@ int cmd_branch(int argc,
 		OPT_CALLBACK_F(0, "delete-merged", &delete_merged, N_("pattern"),
 			N_("delete merged branches whose upstream matches <pattern> (repeatable)"),
 			PARSE_OPT_NONEG, parse_opt_strvec),
+		OPT_CALLBACK_F(0, "delete-integrated", &delete_integrated, N_("pattern"),
+			N_("like --delete-merged, but also delete branches whose changes landed upstream (repeatable)"),
+			PARSE_OPT_NONEG, parse_opt_strvec),
 		OPT_BOOL(0, "dry-run", &dry_run,
-			N_("with --delete-merged, only print which branches would be deleted")),
+			N_("with --delete-merged or --delete-integrated, only print which branches would be deleted")),
 		OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE),
 		OPT_MERGED(&filter, N_("print only branches that are merged")),
 		OPT_NO_MERGED(&filter, N_("print only branches that are not merged")),
@@ -1108,7 +1336,7 @@ int cmd_branch(int argc,
 
 	if (!delete && !rename && !copy && !edit_description && !new_upstream &&
 	    !show_current && !unset_upstream && !delete_merged.nr &&
-	    argc == 0)
+	    !delete_integrated.nr && argc == 0)
 		list = 1;
 
 	if (filter.with_commit || filter.no_commit ||
@@ -1116,14 +1344,18 @@ int cmd_branch(int argc,
 	    filter.points_at.nr || filter.forked.nr)
 		list = 1;
 
+	die_for_incompatible_opt2(!!delete_merged.nr, "--delete-merged",
+				  !!delete_integrated.nr, "--delete-integrated");
+
 	noncreate_actions = !!delete + !!rename + !!copy + !!new_upstream +
 			    !!show_current + !!list + !!edit_description +
-			    !!unset_upstream + !!delete_merged.nr;
+			    !!unset_upstream + !!delete_merged.nr +
+			    !!delete_integrated.nr;
 	if (noncreate_actions > 1)
 		usage_with_options(builtin_branch_usage, options);
 
-	if (dry_run && !delete_merged.nr)
-		die(_("--dry-run requires --delete-merged"));
+	if (dry_run && !delete_merged.nr && !delete_integrated.nr)
+		die(_("--dry-run requires --delete-merged or --delete-integrated"));
 
 	if (recurse_submodules_explicit) {
 		if (!submodule_propagate_branches)
@@ -1168,6 +1400,12 @@ int cmd_branch(int argc,
 					     (quiet ? DELETE_BRANCH_QUIET : 0) |
 					     (dry_run ? DELETE_BRANCH_DRY_RUN : 0));
 		goto out;
+	} else if (delete_integrated.nr) {
+		ret = delete_merged_branches(&delete_integrated, argv,
+					     (quiet ? DELETE_BRANCH_QUIET : 0) |
+					     (dry_run ? DELETE_BRANCH_DRY_RUN : 0) |
+					     DELETE_BRANCH_INTEGRATED);
+		goto out;
 	} else if (show_current) {
 		print_current_branch_name();
 		ret = 0;
@@ -1347,6 +1585,7 @@ int cmd_branch(int argc,
 
 out:
 	strvec_clear(&delete_merged);
+	strvec_clear(&delete_integrated);
 	string_list_clear(&sorting_options, 0);
 	return ret;
 }
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 44336eef81..54461e90b3 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1963,6 +1963,39 @@ check_branches () {
 	test_cmp expect actual
 }
 
+test_expect_success '--delete-merged does not delete unrelated branches' '
+	setup_repo_for_delete_merged &&
+	(
+		cd repo &&
+		git checkout -b unrelated-topic --track origin/next &&
+		test_write_lines 1 2 3 4 >file &&
+		git add file &&
+		git commit -m "add file" &&
+		git push origin unrelated-topic &&
+		git checkout --detach
+	) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		test_write_lines 1 2 3 4 >file &&
+		test_write_lines 5 6 7 >elif &&
+		git add file elif &&
+		git commit --author="unrelated user <uu@example.com>" \
+			-m "unrelated commit adding an identical file" &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		git branch --delete-merged origin/next >actual 2>&1 &&
+		test_must_be_empty actual &&
+		check_branches <<-\EOF
+		main
+		unrelated-topic
+		EOF
+	)
+'
+
 test_expect_success '--delete-merged keeps cloned main without explicit push configuration' '
 	setup_repo_for_delete_merged &&
 	(
@@ -2017,6 +2050,143 @@ test_expect_success '--delete-merged deletes only selected merged branches' '
 	)
 '
 
+push_topic () {
+	branch=$1 &&
+	shift &&
+	(
+		cd repo &&
+		git checkout -b "$branch" --track origin/next &&
+		for commit in "$@"
+		do
+			test_commit "$commit" || return 1
+		done &&
+		git push origin "$branch" &&
+		git checkout --detach
+	)
+}
+
+squash_merge_upstream () {
+	(
+		cd upstream &&
+		git checkout next &&
+		git merge --squash "$1" &&
+		git commit -m "Squash merge of $1" &&
+		git checkout main
+	)
+}
+
+rebase_merge_upstream () {
+	(
+		cd upstream &&
+		git rebase next "$1" &&
+		git checkout next &&
+		git merge --ff-only "$1" &&
+		git checkout main
+	)
+}
+
+test_expect_success '--delete-integrated deletes a rebase merged branch' '
+	setup_repo_for_delete_merged &&
+	push_topic rebased rebased-one rebased-two &&
+	(
+		cd upstream &&
+		git checkout next &&
+		test_commit before-rebase &&
+		git checkout main
+	) &&
+	rebase_merge_upstream rebased &&
+	landed=$(git -C upstream rev-parse --short next) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		sha=$(git rev-parse --short rebased) &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		echo "Deleted branch rebased (was $sha, landed as $landed)." >expect &&
+		test_cmp expect actual &&
+
+		check_branches <<-\EOF
+		main
+		EOF
+	)
+'
+
+test_expect_success '--delete-integrated deletes a squash merged branch' '
+	setup_repo_for_delete_merged &&
+	push_topic squashed squashed-one squashed-two &&
+	push_topic partial lands-upstream stays-local &&
+	squash_merge_upstream partial~1 &&
+	squash_merge_upstream squashed &&
+	squash=$(git -C upstream rev-parse --short next) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		sha=$(git rev-parse --short squashed) &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		echo "Deleted branch squashed (was $sha, landed as $squash)." >expect &&
+		test_cmp expect actual &&
+
+		check_branches <<-\EOF
+		main
+		partial
+		EOF
+	)
+'
+
+test_expect_success '--delete-integrated deletes a squash merged branch that was reverted' '
+	setup_repo_for_delete_merged &&
+	push_topic reverted reverted-work &&
+	squash_merge_upstream reverted &&
+	squash=$(git -C upstream rev-parse --short next) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		git revert --no-edit HEAD &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		sha=$(git rev-parse --short reverted) &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		echo "Deleted branch reverted (was $sha, landed as $squash)." >expect &&
+		test_cmp expect actual &&
+
+		check_branches <<-\EOF
+		main
+		EOF
+	)
+'
+
+test_expect_success '--delete-integrated reports a merge plainly next to an unmerged branch' '
+	setup_repo_for_delete_merged &&
+	push_topic a-unmerged unmerged-work &&
+	push_topic b-merged merged-work &&
+	(
+		cd upstream &&
+		git checkout next &&
+		test_commit upstream-work &&
+		git merge --no-ff b-merged &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		sha=$(git rev-parse --short b-merged) &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		echo "Deleted branch b-merged (was $sha)." >expect &&
+		test_cmp expect actual &&
+
+		check_branches <<-\EOF
+		a-unmerged
+		main
+		EOF
+	)
+'
+
 test_expect_success '--delete-merged keeps main despite a different default push remote' '
 	setup_repo_for_delete_merged &&
 	create_merged_branch on-next &&
@@ -2216,4 +2386,10 @@ test_expect_success '--dry-run without --delete-merged is rejected' '
 	test_grep "requires --delete-merged" err
 '
 
+test_expect_success '--delete-integrated cannot be combined with --delete-merged' '
+	test_must_fail git -C forked branch --delete-merged origin/next \
+		--delete-integrated origin/next 2>err &&
+	test_grep "cannot be used together" err
+'
+
 test_done
-- 
gitgitgadget
[PATCH v9 4/4] branch: let --delete-integrated find branches merged onto changed files
#3451
Author: "Harald Nordgren via GitGitGadge...
Date: Fri, 20 Nov 2026 14:24
340 lines
22162 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>

A branch that upstream integrated with

    git merge --squash topic
    git commit

after upstream had also changed the files the branch touches is still
kept by "git branch --delete-integrated". The squash commit has neither
the branch's version of those files nor the fork point's, so the
previous check cannot see that the work landed. This happens all the
time on hosting services such as GitHub, where the "Squash and merge"
button lands pull requests this way, and other pull requests often
touch the same files first. A rebase merge onto such changes looks the
same.

For each such file, merge the branch's version into the upstream one
and treat the change as landed when that leaves the upstream version
unchanged. This has to read the files, so in a partial clone it may
download blobs.

The merge uses the attributes of this repository, from the working tree
and the index, the same as a merge run here would. A merge driver that
only the upstream repository has is not seen. In a bare repository only
info/attributes and the global file apply.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 Documentation/git-branch.adoc |  14 ++--
 builtin/branch.c              |  76 ++++++++++++++++---
 t/t3200-branch.sh             | 139 ++++++++++++++++++++++++++++++++++
 3 files changed, 213 insertions(+), 16 deletions(-)

diff --git a/Documentation/git-branch.adoc b/Documentation/git-branch.adoc
index b6d9cd01a4..814395d223 100644
--- a/Documentation/git-branch.adoc
+++ b/Documentation/git-branch.adoc
@@ -240,11 +240,15 @@ remove it anyway.
 	Like `--delete-merged`, but also delete a branch whose changes
 	the upstream already has even though its commits are not there,
 	as happens after a squash or rebase merge. Such a branch is
-	deleted when some upstream commit since the fork point has its
-	version of every file it changed, even if those changes were
-	later reverted, and the message names the first such commit.
-	It does not matter who made that commit. The same rules for
-	which branches are kept apply as for `--delete-merged`.
+	deleted when some upstream commit since the fork point has all
+	of its changes, even if they were later reverted, and the
+	message names the first such commit. It does not matter who made
+	that commit. A file counts when the commit has the branch's
+	version of it. It also counts when merging the branch's version
+	into the commit's version leaves the commit's version unchanged.
+	That merge reads the file, and in a partial clone it may download
+	blobs. The same rules for which branches are kept apply as for
+	`--delete-merged`.
 
 `--dry-run`::
 	With `--delete-merged` or `--delete-integrated`, print which
diff --git a/builtin/branch.c b/builtin/branch.c
index ee92e71f51..262cd82272 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -33,8 +33,10 @@
 #include "diff.h"
 #include "diffcore.h"
 #include "hex.h"
+#include "merge-ll.h"
 #include "revision.h"
 #include "tree-walk.h"
+#include "xdiff-interface.h"
 
 static const char * const builtin_branch_usage[] = {
 	N_("git branch [<options>] [-r | -a] [--merged] [--no-merged] [(--forked <branch>)...]"),
@@ -853,10 +855,17 @@ static int branch_pushes_to_upstream(struct branch *branch,
 	return ret;
 }
 
+enum change_state {
+	CHANGE_MISSING,
+	CHANGE_LANDED,
+	CHANGE_NEEDS_MERGE,
+};
+
 struct branch_change {
 	char *path;
-	struct object_id branch_oid;
-	unsigned short branch_mode;
+	struct object_id base_oid, branch_oid, upstream_oid;
+	unsigned short base_mode, branch_mode;
+	enum change_state state;
 };
 
 struct landing_search {
@@ -888,32 +897,76 @@ static void collect_branch_changes(struct landing_search *search,
 			   search->changes_alloc);
 		change = &search->changes[search->changes_nr++];
 		change->path = xstrdup(p->two->path);
+		oidcpy(&change->base_oid, DIFF_FILE_VALID(p->one) ?
+		       &p->one->oid : null_oid(the_hash_algo));
 		oidcpy(&change->branch_oid, DIFF_FILE_VALID(p->two) ?
 		       &p->two->oid : null_oid(the_hash_algo));
+		change->base_mode = p->one->mode;
 		change->branch_mode = p->two->mode;
 	}
 	diff_flush(&diffopt);
 }
 
-static int change_landed(const struct branch_change *change,
-			 struct commit *commit)
+static int merge_keeps_upstream(const struct branch_change *change)
+{
+	mmfile_t base, upstream, branch;
+	mmfile_t result = { 0 };
+	int ret;
+
+	read_mmblob(&base, the_repository->objects, &change->base_oid);
+	read_mmblob(&upstream, the_repository->objects, &change->upstream_oid);
+	read_mmblob(&branch, the_repository->objects, &change->branch_oid);
+	ret = ll_merge(&result, change->path, &base, "base",
+		       &upstream, "upstream", &branch, "branch",
+		       the_repository->index, NULL) == LL_MERGE_OK &&
+	      result.size == upstream.size &&
+	      !memcmp(result.ptr, upstream.ptr, upstream.size);
+
+	free(base.ptr);
+	free(upstream.ptr);
+	free(branch.ptr);
+	free(result.ptr);
+	return ret;
+}
+
+static enum change_state change_state_at(struct branch_change *change,
+					 struct commit *commit)
 {
-	struct object_id oid;
 	unsigned short mode;
 
 	if (get_tree_entry(the_repository, get_commit_tree_oid(commit),
-			   change->path, &oid, &mode))
-		return is_null_oid(&change->branch_oid);
-	return oideq(&oid, &change->branch_oid) &&
-	       mode == change->branch_mode;
+			   change->path, &change->upstream_oid, &mode))
+		return is_null_oid(&change->branch_oid) ?
+			CHANGE_LANDED : CHANGE_MISSING;
+	if (oideq(&change->upstream_oid, &change->branch_oid))
+		return mode == change->branch_mode ?
+			CHANGE_LANDED : CHANGE_MISSING;
+	if (is_null_oid(&change->base_oid) ||
+	    is_null_oid(&change->branch_oid) ||
+	    oideq(&change->upstream_oid, &change->base_oid) ||
+	    mode != change->branch_mode || !S_ISREG(mode) ||
+	    !S_ISREG(change->base_mode))
+		return CHANGE_MISSING;
+	return CHANGE_NEEDS_MERGE;
 }
 
 static int changes_landed(struct landing_search *search,
 			  struct commit *commit)
 {
-	for (size_t i = 0; i < search->changes_nr; i++)
-		if (!change_landed(&search->changes[i], commit))
+	for (size_t i = 0; i < search->changes_nr; i++) {
+		struct branch_change *change = &search->changes[i];
+
+		change->state = change_state_at(change, commit);
+		if (change->state == CHANGE_MISSING)
 			return 0;
+	}
+	for (size_t i = 0; i < search->changes_nr; i++) {
+		struct branch_change *change = &search->changes[i];
+
+		if (change->state == CHANGE_NEEDS_MERGE &&
+		    !merge_keeps_upstream(change))
+			return 0;
+	}
 	return 1;
 }
 
@@ -1015,6 +1068,7 @@ static void find_landed_commits(struct landing_search *searches,
 	diffopt.no_free = 1;
 	diff_setup_done(&diffopt);
 	init_changed_paths(&cache);
+	repo_read_index(the_repository);
 
 	for (size_t i = 0; i < searches_nr; i++) {
 		struct commit *landed;
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 54461e90b3..ed62164a95 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -2160,6 +2160,145 @@ test_expect_success '--delete-integrated deletes a squash merged branch that was
 	)
 '
 
+test_expect_success '--delete-integrated deletes a squash merged branch after upstream changed the same file' '
+	(
+		cd upstream &&
+		git checkout next &&
+		test_write_lines 1 2 3 4 5 6 7 8 9 10 >shared &&
+		git add shared &&
+		git commit -m "add shared" &&
+		git checkout main
+	) &&
+	setup_repo_for_delete_merged &&
+	(
+		cd repo &&
+		git checkout -b edits-shared --track origin/next &&
+		test_write_lines 1 two 3 4 5 6 7 8 9 10 >shared &&
+		git commit -a -m "edit line 2" &&
+		git push origin edits-shared &&
+		git checkout --detach
+	) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		test_write_lines 1 2 3 4 five 6 7 8 9 10 >shared &&
+		git commit -a -m "edit line 5" &&
+		git checkout main
+	) &&
+	squash_merge_upstream edits-shared &&
+	squash=$(git -C upstream rev-parse --short next) &&
+	(
+		cd repo &&
+		git fetch origin &&
+		sha=$(git rev-parse --short edits-shared) &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		echo "Deleted branch edits-shared (was $sha, landed as $squash)." >expect &&
+		test_cmp expect actual &&
+
+		check_branches <<-\EOF
+		main
+		EOF
+	)
+'
+
+test_expect_success '--delete-integrated keeps branches whose changes did not land' '
+	(
+		cd upstream &&
+		git checkout next &&
+		test_write_lines 1 2 3 4 5 6 7 8 9 10 >doc &&
+		git add doc &&
+		git commit -m "add doc" &&
+		git checkout main
+	) &&
+	setup_repo_for_delete_merged &&
+	(
+		cd repo &&
+		git checkout -b unmerged --track origin/next &&
+		test_write_lines 1 2 3 4 5 6 7 eight 9 10 >doc &&
+		git commit -a -m "edit line 8" &&
+		git push origin unmerged &&
+		git checkout -b half-landed --track origin/next &&
+		test_write_lines one 2 3 4 5 6 7 8 9 ten >doc &&
+		git commit -a -m "edit lines 1 and 10" &&
+		git push origin half-landed &&
+		git checkout -b conflicting --track origin/next &&
+		test_write_lines 1 2 three 4 5 6 7 8 9 10 >doc &&
+		git commit -a -m "edit line 3" &&
+		git push origin conflicting &&
+		git checkout --detach
+	) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		test_write_lines 1 2 3 4 five 6 7 8 9 10 >doc &&
+		git commit -a -m "edit line 5" &&
+		test_write_lines one 2 3 4 five 6 7 8 9 10 >doc &&
+		git commit -a -m "take line 1 from half-landed" &&
+		test_write_lines one 2 THREE 4 five 6 7 8 9 10 >doc &&
+		git commit -a -m "edit line 3 differently" &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		test_must_be_empty actual &&
+
+		check_branches <<-\EOF
+		conflicting
+		half-landed
+		main
+		unmerged
+		EOF
+	)
+'
+
+test_expect_success '--delete-integrated keeps a branch that replaced a submodule with a file' '
+	(
+		cd upstream &&
+		git checkout next &&
+		git init lib &&
+		test_commit -C lib in-lib &&
+		git add lib &&
+		git commit -m "add lib as a submodule" &&
+		git checkout main
+	) &&
+	setup_repo_for_delete_merged &&
+	(
+		cd repo &&
+		git checkout -b replaces-lib --track origin/next &&
+		rmdir lib &&
+		echo "from the branch" >lib &&
+		git add lib &&
+		git commit -m "replace lib with a file" &&
+		git push origin replaces-lib &&
+		git checkout --detach
+	) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		rm -rf lib &&
+		echo "from upstream" >lib &&
+		git add lib &&
+		git commit -m "replace lib with another file" &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		test_must_be_empty actual &&
+
+		check_branches <<-\EOF
+		main
+		replaces-lib
+		EOF
+	)
+'
+
 test_expect_success '--delete-integrated reports a merge plainly next to an unmerged branch' '
 	setup_repo_for_delete_merged &&
 	push_topic a-unmerged unmerged-work &&
-- 
gitgitgadget
Re: [PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
#3484
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 18:57
70 lines
15636 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> A later commit adds "git branch --delete-integrated", which deletes
> branches whose tips are not reachable from their upstream. Those must
> honor branch.<name>.deleteMerged=false as well. Move the check into a
> helper so it can be used in both places.
>
> No change in behavior.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>  builtin/branch.c | 32 +++++++++++++++++++-------------
>  1 file changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index b536b619bb..2c1a8b8395 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -824,6 +824,23 @@ static int branch_pushes_to_upstream(struct branch *branch,
>  	return ret;
>  }
>  
> +static bool branch_opted_out(struct strbuf *key, const char *branch_name,
> +			     unsigned int flags)

I am afraid that this is a somewhat selfish choice of a name that we
would regret later, as it assumes that "delete once it is merged
elsewhere" will continue to be the only destructive operation that
people may want to exempt some branches from.  The configuration key
is named very specifically for that destructive operation (i.e.,
setting branch.<name>.deleteMerged to false is a way to say "no,
even if it is merged, do not delete it"), so there is an impedance
mismatch.

Either

 (1) naming this function to make it clear that this is about
     opting out of the deleteMerged operation, or

 (2) naming this function to make it clear that this is about opting
     out of ANY destructive operation, and renaming the
     configuration key to something less specific than deleteMerged
     so that the user will be saved from any new destructive
     operation we may add in the future, e.g., "force update to what
     upstream says", by setting the same configuration variable to
     opt out of it (e.g., branch.<name>.noClobber=true)

would work better, perhaps?

> +{
> +	int opt_out;
> +
> +	strbuf_reset(key);
> +	strbuf_addf(key, "branch.%s.deletemerged", branch_name);
> +	if (repo_config_get_bool(the_repository, key->buf, &opt_out) ||
> +	    opt_out)
> +		return false;

The lack of a key, or the key explicitly set to true, will cause
this function to say "no, this branch is not opted out", which
smells like a risky default to me.

Putting the devil's advocate hat on (because I understand why the
inventor of a feature wants it to apply as widely as possible),
shouldn't this be the other way around?  If the user does not
explicitly say "I am fine losing this once we are done", shouldn't
we be treating it as precious?
Re: [PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
#3488
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 19:10
41 lines
14627 bytes
Junio C Hamano <gitster@pobox.com> writes:

>> +static bool branch_opted_out(struct strbuf *key, const char *branch_name,
>> +			     unsigned int flags)
>
> I am afraid that this is a somewhat selfish choice of a name that we
> would regret later, as it assumes that "delete once it is merged
> elsewhere" will continue to be the only destructive operation that
> people may want to exempt some branches from.  The configuration key
> is named very specifically for that destructive operation (i.e.,
> setting branch.<name>.deleteMerged to false is a way to say "no,
> even if it is merged, do not delete it"), so there is an impedance
> mismatch.
>
> Either
>
>  (1) naming this function to make it clear that this is about
>      opting out of the deleteMerged operation, or
>
>  (2) naming this function to make it clear that this is about opting
>      out of ANY destructive operation, and renaming the
>      configuration key to something less specific than deleteMerged
>      so that the user will be saved from any new destructive
>      operation we may add in the future, e.g., "force update to what
>      upstream says", by setting the same configuration variable to
>      opt out of it (e.g., branch.<name>.noClobber=true)
>
> would work better, perhaps?

I forgot that there is a third option.  

branch_opted_out("main", "deleteMerged") can be a boolean function
that asks if the user is OK with subjecting the "main" branch to the
"deleteMerged" operation (and the implementation may be done by
checking the "branch.<name>.deleteMerged" configuration variable).
The function must continue to be purely about "is the branch opted
out of operation X" without adding X-specific side effects, if we go
that route.

Thanks.
Re: [PATCH v9 2/4] branch: let delete_branches() name where a branch landed
#3490
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 19:32
85 lines
16140 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> @@ -357,15 +359,33 @@ static int delete_branches(int argc, const char **argv, int kinds,
>  	for_each_string_list_item(item, &refs_to_delete) {
>  		char *describe_ref = item->util;
>  		char *name = item->string;
> +		struct commit *landed = landed_commits ?
> +			strmap_get(landed_commits, name + branch_name_pos) : NULL;
> +		const char *landed_abbrev = landed ?
> +			repo_find_unique_abbrev(the_repository,
> +						&landed->object.oid,
> +						DEFAULT_ABBREV) : NULL;
> +
>  		if (flags & DELETE_BRANCH_DRY_RUN) {
> -			if (!(flags & DELETE_BRANCH_QUIET))
> +			if (flags & DELETE_BRANCH_QUIET)
> +				;
> +			else if (landed)
> +				printf(_("Would delete branch %s (was %s, landed as %s).\n"),
> +				       name + branch_name_pos, describe_ref,
> +				       landed_abbrev);
> +			else
>  				printf(remote_branch
>  					? _("Would delete remote-tracking branch %s (was %s).\n")
>  					: _("Would delete branch %s (was %s).\n"),
>  					name + branch_name_pos, describe_ref);

The use of an empty "if" statement body is a clean way to express
that nothing will be emitted under "--quiet" without making the code
too deeply nested.  Nicely done.

This is not a new issue, but this makes me wonder if giving the
"--dry-run" and the "--quiet" options together makes sense.  Would
users really gain much information from "--quiet" when they are so
paranoid as to want a preview of what would happen with "--dry-run"?

>  		} else if (!refs_ref_exists(get_main_ref_store(the_repository), name)) {
>  			char *refname = name + branch_name_pos;
> -			if (!(flags & DELETE_BRANCH_QUIET))
> +			if (flags & DELETE_BRANCH_QUIET)
> +				;
> +			else if (landed)
> +				printf(_("Deleted branch %s (was %s, landed as %s).\n"),
> +				       refname, describe_ref, landed_abbrev);
> +			else
>  				printf(remote_branch
>  					? _("Deleted remote-tracking branch %s (was %s).\n")
>  					: _("Deleted branch %s (was %s).\n"),

Likewise.

I wonder if it makes the code structure cleaner to follow if we swap
the order of checks between "are we doing dry-run" (which is on the
outside in the current code structure) and "what is the reason we
remove this branch" (which is the inner if/elseif cascade) by having
these different message templates (currently a pair of three-message
sets) in an array and choosing which set to use based on
"--dry-run".  There are of course a few things that are done only in
the non-dry-run mode (like removing the branch configuration and the
branch itself).  In other words, a code structure like this

	const char *msg_templates[2][3] = {
		{ "Would delete branch %s ...", ..., ..., },
		{ "Deleted branch %s ...", ..., ..., },
	};
	const char *use_msg[3] = msg_templates[!dry_run];

	for-each-branch-to-be-deleted {
		compute if branch has landed;
		if (quiet)
			;
		else if (landed)
			printf(_(use_msg[0]), ...);
		else if (remote_branch)
			printf(_(use_msg[1]), ...);
		else
			printf(_(use_msg[2]), ...);
		if (!dry_run)
			remove branch and its configuration;
		else
			what is only done in dry-run mode (if exists)
	}
		
may make it easier to follow for readers?
Re: [PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches
#3493
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 20:02
267 lines
21370 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Subject: Re: [PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches

The title is on a tad overlong side.

"rebase and squash merged branches" sounds awkward.  If a branch got
intergrated by squash merging is called "squash-merged branch",
shouldn't a branch that underwent "git rebase" to sit on top of the
upstream be called "rebased branch"?

IOW, "rebased or squash-merged branches"?

> diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
> index c2acd89c99..be9b296bda 100644
> --- a/Documentation/config/branch.adoc
> +++ b/Documentation/config/branch.adoc
> @@ -106,7 +106,7 @@ for details).
>  
>  `branch.<name>.deleteMerged`::
>  	If set to `false`, branch _<name>_ is exempt from
> -	`git branch --delete-merged`.  Useful for a topic branch you
> -	intend to develop further after an initial round has been
> -	merged upstream.  Defaults to true.  Explicit deletion via
> -	`git branch -d` is unaffected.
> +	`git branch --delete-merged` and `--delete-integrated`.  Useful
> +	for a topic branch you intend to develop further after an
> +	initial round has been merged upstream.  Defaults to true.
> +	Explicit deletion via `git branch -d` is unaffected.

Does the deleteMerged configuration variable affect the behavior of
the "--delete-integrated" option?  Knowing how the feature evolved,
it is understandable to me, but I suspect it won't be natural for
mere mortals.

Perhaps a single .deleteDone variable that governs both would be
more future-proof, as it anticipates that we may find other ways a
branch becomes "done", other than by getting merged or otherwise
integrated, and when that happens this variable will also deal with
such a new destructive operation.

> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 44336eef81..54461e90b3 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -1963,6 +1963,39 @@ check_branches () {
>  	test_cmp expect actual
>  }
>  
> +test_expect_success '--delete-merged does not delete unrelated branches' '
> +	setup_repo_for_delete_merged &&
> +	(
> +		cd repo &&
> +		git checkout -b unrelated-topic --track origin/next &&
> +		test_write_lines 1 2 3 4 >file &&
> +		git add file &&
> +		git commit -m "add file" &&
> +		git push origin unrelated-topic &&
> +		git checkout --detach
> +	) &&
> +	(
> +		cd upstream &&
> +		git checkout next &&
> +		test_write_lines 1 2 3 4 >file &&
> +		test_write_lines 5 6 7 >elif &&
> +		git add file elif &&
> +		git commit --author="unrelated user <uu@example.com>" \
> +			-m "unrelated commit adding an identical file" &&
> +		git checkout main
> +	) &&
> +	(
> +		cd repo &&
> +		git fetch origin &&
> +		git branch --delete-merged origin/next >actual 2>&1 &&
> +		test_must_be_empty actual &&
> +		check_branches <<-\EOF
> +		main
> +		unrelated-topic
> +		EOF
> +	)
> +'
> +
>  test_expect_success '--delete-merged keeps cloned main without explicit push configuration' '
>  	setup_repo_for_delete_merged &&
>  	(
> @@ -2017,6 +2050,143 @@ test_expect_success '--delete-merged deletes only selected merged branches' '
>  	)
>  '
>  
> +push_topic () {
> +	branch=$1 &&
> +	shift &&
> +	(
> +		cd repo &&
> +		git checkout -b "$branch" --track origin/next &&
> +		for commit in "$@"
> +		do
> +			test_commit "$commit" || return 1
> +		done &&
> +		git push origin "$branch" &&
> +		git checkout --detach
> +	)
> +}
> +
> +squash_merge_upstream () {
> +	(
> +		cd upstream &&
> +		git checkout next &&
> +		git merge --squash "$1" &&
> +		git commit -m "Squash merge of $1" &&
> +		git checkout main
> +	)
> +}
> +
> +rebase_merge_upstream () {
> +	(
> +		cd upstream &&
> +		git rebase next "$1" &&
> +		git checkout next &&
> +		git merge --ff-only "$1" &&
> +		git checkout main
> +	)
> +}
> +
> +test_expect_success '--delete-integrated deletes a rebase merged branch' '
> +	setup_repo_for_delete_merged &&
> +	push_topic rebased rebased-one rebased-two &&
> +	(
> +		cd upstream &&
> +		git checkout next &&
> +		test_commit before-rebase &&
> +		git checkout main
> +	) &&
> +	rebase_merge_upstream rebased &&
> +	landed=$(git -C upstream rev-parse --short next) &&
> +	(
> +		cd repo &&
> +		git fetch origin &&
> +		sha=$(git rev-parse --short rebased) &&
> +
> +		git branch --delete-integrated origin/next >actual 2>&1 &&
> +		echo "Deleted branch rebased (was $sha, landed as $landed)." >expect &&
> +		test_cmp expect actual &&
> +
> +		check_branches <<-\EOF
> +		main
> +		EOF
> +	)
> +'
> +
> +test_expect_success '--delete-integrated deletes a squash merged branch' '
> +	setup_repo_for_delete_merged &&
> +	push_topic squashed squashed-one squashed-two &&
> +	push_topic partial lands-upstream stays-local &&
> +	squash_merge_upstream partial~1 &&
> +	squash_merge_upstream squashed &&
> +	squash=$(git -C upstream rev-parse --short next) &&
> +	(
> +		cd repo &&
> +		git fetch origin &&
> +		sha=$(git rev-parse --short squashed) &&
> +
> +		git branch --delete-integrated origin/next >actual 2>&1 &&
> +		echo "Deleted branch squashed (was $sha, landed as $squash)." >expect &&
> +		test_cmp expect actual &&
> +
> +		check_branches <<-\EOF
> +		main
> +		partial
> +		EOF
> +	)
> +'
> +
> +test_expect_success '--delete-integrated deletes a squash merged branch that was reverted' '
> +	setup_repo_for_delete_merged &&
> +	push_topic reverted reverted-work &&
> +	squash_merge_upstream reverted &&
> +	squash=$(git -C upstream rev-parse --short next) &&
> +	(
> +		cd upstream &&
> +		git checkout next &&
> +		git revert --no-edit HEAD &&
> +		git checkout main
> +	) &&
> +	(
> +		cd repo &&
> +		git fetch origin &&
> +		sha=$(git rev-parse --short reverted) &&
> +
> +		git branch --delete-integrated origin/next >actual 2>&1 &&
> +		echo "Deleted branch reverted (was $sha, landed as $squash)." >expect &&
> +		test_cmp expect actual &&
> +
> +		check_branches <<-\EOF
> +		main
> +		EOF
> +	)
> +'
> +
> +test_expect_success '--delete-integrated reports a merge plainly next to an unmerged branch' '
> +	setup_repo_for_delete_merged &&
> +	push_topic a-unmerged unmerged-work &&
> +	push_topic b-merged merged-work &&
> +	(
> +		cd upstream &&
> +		git checkout next &&
> +		test_commit upstream-work &&
> +		git merge --no-ff b-merged &&
> +		git checkout main
> +	) &&
> +	(
> +		cd repo &&
> +		git fetch origin &&
> +		sha=$(git rev-parse --short b-merged) &&
> +
> +		git branch --delete-integrated origin/next >actual 2>&1 &&
> +		echo "Deleted branch b-merged (was $sha)." >expect &&
> +		test_cmp expect actual &&
> +
> +		check_branches <<-\EOF
> +		a-unmerged
> +		main
> +		EOF
> +	)
> +'

Does "--dry-run --delete-integrated" combination have test coverage?
If not shouldn't it?

Does opting out of "--delete-integrated" feature by setting
branch.<name>.deleteMerged to false have test coverage?
If not shouldn't it?

>  test_expect_success '--delete-merged keeps main despite a different default push remote' '
>  	setup_repo_for_delete_merged &&
>  	create_merged_branch on-next &&
> @@ -2216,4 +2386,10 @@ test_expect_success '--dry-run without --delete-merged is rejected' '
>  	test_grep "requires --delete-merged" err
>  '

It now requires either --delete-merged or --delete-integrated.
At least, updating the expected message in the test we can see would
be helpful.  

Having said that, I do not agree with the design to make "--dry-run"
require anything.

If "git branch delete master" is run, and 'master' is checked out,
it would error out.  "git branch delete --dry-run master" should say
"we would not let you delete the currently checked out branch" the
same way and exit, no?


> +test_expect_success '--delete-integrated cannot be combined with --delete-merged' '
> +	test_must_fail git -C forked branch --delete-merged origin/next \
> +		--delete-integrated origin/next 2>err &&
> +	test_grep "cannot be used together" err
> +'

Good.  You added die-for-incompatible-opt to make them incompatible.

Also do we want to ensure "--quiet" does what it is designed to do?
I do not think I saw anything added to t3200 by this series that
mentioned the option.

Thanks.
Re: [PATCH v9 4/4] branch: let --delete-integrated find branches merged onto changed files
#3494
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 20:08
108 lines
16169 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +test_expect_success '--delete-integrated keeps a branch that replaced a submodule with a file' '
> +	(
> +		cd upstream &&
> +		git checkout next &&
> ...
> +		EOF
> +	)
> +'

This test looks somewhat familiar.

Was this the only corner case that needed a fix?  From the code
change (below), it seems to be the case, and I was hoping that since
reviewers are doing a lot of work finding corner cases, the original
author would be finding three times as many corner cases to make the
topic better, instead of just reacting to a case that was reported
;-)


diff --git c/builtin/branch.c w/builtin/branch.c
index 7b1048b583..a225c591b8 100644
--- c/builtin/branch.c
+++ w/builtin/branch.c
@@ -864,7 +864,7 @@ enum change_state {
 struct branch_change {
 	char *path;
 	struct object_id base_oid, branch_oid, upstream_oid;
-	unsigned short branch_mode;
+	unsigned short base_mode, branch_mode;
 	enum change_state state;
 };
 
@@ -901,6 +901,7 @@ static void collect_branch_changes(struct landing_search *search,
 		       &p->one->oid : null_oid(the_hash_algo));
 		oidcpy(&change->branch_oid, DIFF_FILE_VALID(p->two) ?
 		       &p->two->oid : null_oid(the_hash_algo));
+		change->base_mode = p->one->mode;
 		change->branch_mode = p->two->mode;
 	}
 	diff_flush(&diffopt);
@@ -943,7 +944,8 @@ static enum change_state change_state_at(struct branch_change *change,
 	if (is_null_oid(&change->base_oid) ||
 	    is_null_oid(&change->branch_oid) ||
 	    oideq(&change->upstream_oid, &change->base_oid) ||
-	    mode != change->branch_mode || !S_ISREG(mode))
+	    mode != change->branch_mode || !S_ISREG(mode) ||
+	    !S_ISREG(change->base_mode))
 		return CHANGE_MISSING;
 	return CHANGE_NEEDS_MERGE;
 }
diff --git c/t/t3200-branch.sh w/t/t3200-branch.sh
index 78b7d395e2..41b31c8f67 100755
--- c/t/t3200-branch.sh
+++ w/t/t3200-branch.sh
@@ -2217,6 +2217,50 @@ test_expect_success '--delete-integrated keeps branches whose changes did not la
 	)
 '
 
+test_expect_success '--delete-integrated keeps a branch that replaced a submodule with a file' '
+	(
+		cd upstream &&
+		git checkout next &&
+		git init lib &&
+		test_commit -C lib in-lib &&
+		git add lib &&
+		git commit -m "add lib as a submodule" &&
+		git checkout main
+	) &&
+	setup_repo_for_delete_merged &&
+	(
+		cd repo &&
+		git checkout -b replaces-lib --track origin/next &&
+		rmdir lib &&
+		echo "from the branch" >lib &&
+		git add lib &&
+		git commit -m "replace lib with a file" &&
+		git push origin replaces-lib &&
+		git checkout --detach
+	) &&
+	(
+		cd upstream &&
+		git checkout next &&
+		rm -rf lib &&
+		echo "from upstream" >lib &&
+		git add lib &&
+		git commit -m "replace lib with another file" &&
+		git checkout main
+	) &&
+	(
+		cd repo &&
+		git fetch origin &&
+
+		git branch --delete-integrated origin/next >actual 2>&1 &&
+		test_must_be_empty actual &&
+
+		check_branches <<-\EOF
+		main
+		replaces-lib
+		EOF
+	)
+'
+
 test_expect_success '--delete-integrated reports a merge plainly next to an unmerged branch' '
 	setup_repo_for_delete_merged &&
 	push_topic a-unmerged unmerged-work &&
Re: [PATCH v9 0/4] branch: let --delete-merged find squash merged branches
#3506
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 23:02
15 lines
13339 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Changes in v9:
>
>  * Fix --delete-integrated dying with "unable to read blob object" when a
>    path was a submodule at the fork point and both the branch and upstream
>    replaced it with different regular files. Such a branch is now kept.
>  * Add a test for that case.

The changes between v8 and v9 looked OK (that does not say anything
about the changes up to v8, or the --delete-merged that was added to
serve as a base of this series, though).

Thanks.
Re: [PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
#3551
Author: Harald Nordgren
Date: Sat, 21 Nov 2026 20:34
20 lines
12692 bytes
> > I am afraid that this is a somewhat selfish choice of a name that we
> > would regret later, as it assumes that "delete once it is merged
> > elsewhere" will continue to be the only destructive operation that
> > people may want to exempt some branches from.  The configuration key
> > is named very specifically for that destructive operation (i.e.,
> > setting branch.<name>.deleteMerged to false is a way to say "no,
> > even if it is merged, do not delete it"), so there is an impedance
> > mismatch.

Good point.

> >  (1) naming this function to make it clear that this is about
> >      opting out of the deleteMerged operation, or

Went with (1), it is now opted_out_of_delete_merged().



Harald
Re: [PATCH v9 2/4] branch: let delete_branches() name where a branch landed
#3552
Author: Harald Nordgren
Date: Sat, 21 Nov 2026 20:36
39 lines
13530 bytes
> I wonder if it makes the code structure cleaner to follow if we swap
> the order of checks between "are we doing dry-run" (which is on the
> outside in the current code structure) and "what is the reason we
> remove this branch" (which is the inner if/elseif cascade) by having
> these different message templates (currently a pair of three-message
> sets) in an array and choosing which set to use based on
> "--dry-run".  There are of course a few things that are done only in
> the non-dry-run mode (like removing the branch configuration and the
> branch itself).  In other words, a code structure like this
>
>         const char *msg_templates[2][3] = {
>                 { "Would delete branch %s ...", ..., ..., },
>                 { "Deleted branch %s ...", ..., ..., },
>         };
>         const char *use_msg[3] = msg_templates[!dry_run];
>
>         for-each-branch-to-be-deleted {
>                 compute if branch has landed;
>                 if (quiet)
>                         ;
>                 else if (landed)
>                         printf(_(use_msg[0]), ...);
>                 else if (remote_branch)
>                         printf(_(use_msg[1]), ...);
>                 else
>                         printf(_(use_msg[2]), ...);
>                 if (!dry_run)
>                         remove branch and its configuration;
>                 else
>                         what is only done in dry-run mode (if exists)
>         }
>
> may make it easier to follow for readers?

Good idea.


Harald
Re: [PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
#3565
Author: Junio C Hamano
Date: Sun, 22 Nov 2026 00:57
21 lines
13927 bytes
Harald Nordgren <haraldnordgren@gmail.com> writes:

>> > I am afraid that this is a somewhat selfish choice of a name that we
>> > would regret later, as it assumes that "delete once it is merged
>> > elsewhere" will continue to be the only destructive operation that
>> > people may want to exempt some branches from.  The configuration key
>> > is named very specifically for that destructive operation (i.e.,
>> > setting branch.<name>.deleteMerged to false is a way to say "no,
>> > even if it is merged, do not delete it"), so there is an impedance
>> > mismatch.
>
> Good point.
>
>> >  (1) naming this function to make it clear that this is about
>> >      opting out of the deleteMerged operation, or
>
> Went with (1), it is now opted_out_of_delete_merged().

Hmph, wouldn't it mean we also need to allow people optiong out of
delete_integrated() as well?  I am not sure if we want to go there.
Re: [PATCH v9 2/4] branch: let delete_branches() name where a branch landed
#4141
Author: "D. Ben Knoble"
Date: Mon, 30 Nov 2026 16:18
52 lines
14510 bytes
On Fri, Nov 20, 2026 at 2:32 PM Junio C Hamano <gitster@pobox.com> wrote:

> I wonder if it makes the code structure cleaner to follow if we swap
> the order of checks between "are we doing dry-run" (which is on the
> outside in the current code structure) and "what is the reason we
> remove this branch" (which is the inner if/elseif cascade) by having
> these different message templates (currently a pair of three-message
> sets) in an array and choosing which set to use based on
> "--dry-run".  There are of course a few things that are done only in
> the non-dry-run mode (like removing the branch configuration and the
> branch itself).  In other words, a code structure like this
>
>         const char *msg_templates[2][3] = {
>                 { "Would delete branch %s ...", ..., ..., },
>                 { "Deleted branch %s ...", ..., ..., },
>         };
>         const char *use_msg[3] = msg_templates[!dry_run];
>
>         for-each-branch-to-be-deleted {
>                 compute if branch has landed;
>                 if (quiet)
>                         ;
>                 else if (landed)
>                         printf(_(use_msg[0]), ...);
>                 else if (remote_branch)
>                         printf(_(use_msg[1]), ...);
>                 else
>                         printf(_(use_msg[2]), ...);
>                 if (!dry_run)
>                         remove branch and its configuration;
>                 else
>                         what is only done in dry-run mode (if exists)
>         }
>
> may make it easier to follow for readers?

I see this approach in subsequent versions, but: doesn't this mean we
print "deleted…" before actually carrying out the delete? If the
delete is interrupted midway (or after the print-out but before
starting the delete), we inform the user of an operation that hasn't
occurred.

Now, that might be less confusing than deleting and not informing the
user (if the print is interrupted in a hypothetical reverse-order
code), I'm not sure. But I find it a bit odd to say we've done
something we haven't actually done yet. I suppose we could move the
!dry_run conditional actions *before* the messaging?

-- 
D. Ben Knoble
Re: [PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches
#4164
Author: Harald Nordgren
Date: Mon, 30 Nov 2026 20:21
39 lines
13776 bytes
> > diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
> > index c2acd89c99..be9b296bda 100644
> > --- a/Documentation/config/branch.adoc
> > +++ b/Documentation/config/branch.adoc
> > @@ -106,7 +106,7 @@ for details).
> >
> >  `branch.<name>.deleteMerged`::
> >       If set to `false`, branch _<name>_ is exempt from
> > -     `git branch --delete-merged`.  Useful for a topic branch you
> > -     intend to develop further after an initial round has been
> > -     merged upstream.  Defaults to true.  Explicit deletion via
> > -     `git branch -d` is unaffected.
> > +     `git branch --delete-merged` and `--delete-integrated`.  Useful
> > +     for a topic branch you intend to develop further after an
> > +     initial round has been merged upstream.  Defaults to true.
> > +     Explicit deletion via `git branch -d` is unaffected.
>
> Does the deleteMerged configuration variable affect the behavior of
> the "--delete-integrated" option?  Knowing how the feature evolved,
> it is understandable to me, but I suspect it won't be natural for
> mere mortals.
>
> Perhaps a single .deleteDone variable that governs both would be
> more future-proof, as it anticipates that we may find other ways a
> branch becomes "done", other than by getting merged or otherwise
> integrated, and when that happens this variable will also deal with
> such a new destructive operation.

I thought about this some more, because I'm sketching out a
'--delete-merged --remove-worktrees' follow-up, and realized that this
will need to be added to two places as well, '--delete-merged' and
'--delete-integrated'.

So it seems maybe it's better to not have '--delete-integrated' as a
separate thing? Should we unify it now when we still have the chance?


Harald
Re: [PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches
#4176
Author: Ben Knoble
Date: Mon, 30 Nov 2026 23:41
62 lines
13918 bytes
> Le 30 nov. 2026 à 15:22, Harald Nordgren <haraldnordgren@gmail.com> a écrit :
> 
> 
>> 
>>> diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
>>> index c2acd89c99..be9b296bda 100644
>>> --- a/Documentation/config/branch.adoc
>>> +++ b/Documentation/config/branch.adoc
>>> @@ -106,7 +106,7 @@ for details).
>>> 
>>> `branch.<name>.deleteMerged`::
>>>      If set to `false`, branch _<name>_ is exempt from
>>> -     `git branch --delete-merged`.  Useful for a topic branch you
>>> -     intend to develop further after an initial round has been
>>> -     merged upstream.  Defaults to true.  Explicit deletion via
>>> -     `git branch -d` is unaffected.
>>> +     `git branch --delete-merged` and `--delete-integrated`.  Useful
>>> +     for a topic branch you intend to develop further after an
>>> +     initial round has been merged upstream.  Defaults to true.
>>> +     Explicit deletion via `git branch -d` is unaffected.
>> 
>> Does the deleteMerged configuration variable affect the behavior of
>> the "--delete-integrated" option?  Knowing how the feature evolved,
>> it is understandable to me, but I suspect it won't be natural for
>> mere mortals.
>> 
>> Perhaps a single .deleteDone variable that governs both would be
>> more future-proof, as it anticipates that we may find other ways a
>> branch becomes "done", other than by getting merged or otherwise
>> integrated, and when that happens this variable will also deal with
>> such a new destructive operation.
> 
> I thought about this some more, because I'm sketching out a
> '--delete-merged --remove-worktrees' follow-up, and realized that this
> will need to be added to two places as well, '--delete-merged' and
> '--delete-integrated'.
> 
> So it seems maybe it's better to not have '--delete-integrated' as a
> separate thing? Should we unify it now when we still have the chance?

With context well paged out of my working memory, I cannot recall
the distinction between the 2 already. I *guess* one is merged and
the other is non-merge integrations (squash, rebase). But I still find that
more complex than

    --delete-integrated[=merged,squashed,rebased]

where we accept more than one comma-separated modifier,
and « all » is an alias for all 3. And possibly the default if none are
specified ?

We could (later) support ^merged or -merged as negatives so that
« all,-merged » means the same as « squashed,rebased ».
And we could *maybe* shoehorn remove-worktrees there, too,
or make it a separate modifier flag.

Anyway, yes, I’m in favor of simplifying and unifying related concepts. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads