Re: [PATCH v9 3/4] branch: add --delete-integrated to delete rebase and squash merged branches
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 20, 2026, 20:02 UTC
- Message-ID
- <xmqqzev3nue9.fsf@gitster.g>
- In-Reply-To
- <1f922a00344f6b86dcc0054b3117f1bbad247810.1795184664.git.gitgitgadget@gmail.com>
"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"?
Show 16 quoted lines
> 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.
Show 184 quoted lines
> 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?
Show 6 quoted lines
> 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?
Show 5 quoted lines
> +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.