Re: [PATCH v9 4/4] branch: let --delete-integrated find branches merged onto changed files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 20, 2026, 20:08 UTC
- Message-ID
- <xmqqv75rnu3v.fsf@gitster.g>
- In-Reply-To
- <ef6570030325b4fe18624c30ad1779552fe46b37.1795184664.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 8 quoted lines
> +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 &&