Re: [PATCH v18 1/7] branch: add --forked filter for --list mode
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jul 10, 2026, 15:18 UTC
- Message-ID
- <8ee46e33-4eb8-4e01-800a-82cc7cefa3f9@gmail.com>
- In-Reply-To
- <3e29ff17bd703d8333c2d65d36b15c69ddfc2ab9.1782338106.git.gitgitgadget@gmail.com>
Hi Harald
On 24/06/2026 22:55, Harald Nordgren via GitGitGadget wrote:
Show 17 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com> > > Add a --forked option to "git branch" list mode that lists only > branches whose configured upstream matches <branch>. The argument > can be a ref (e.g. "origin/main", "master"), a remote name like > "origin" for the branch its origin/HEAD points at, or a shell glob > (e.g. "origin/*"), and may be repeated to widen the filter. > > It is an ordinary list filter, so it combines with the others: > > git branch --merged origin/main --forked 'origin/*' > > lists branches forked from origin that are already merged into > origin/main, and --no-merged inverts the question. > > This is the building block for --delete-merged, which deletes the > listed branches once they have landed on their upstream.
The implementation looks good, I've left a couple of small comments on the tests. One thought I had was whether we want a mode which recurses so that if the upstream of topic2 is topic1 which has an upstream of origin/main --forked=recurse origin/main would list topic1 and topic2. So long as we don't think that is a sensible default we can add it in the future if we want.
Show 29 quoted lines
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh > index e7829c2c4b..3104c555f6 100755 > --- a/t/t3200-branch.sh > +++ b/t/t3200-branch.sh > @@ -1717,4 +1717,126 @@ test_expect_success 'errors if given a bad branch name' ' > test_cmp expect actual > ' > > +test_expect_success '--forked: setup' ' > + test_create_repo forked-upstream && > + ( > + cd forked-upstream && > + test_commit base && > + git branch one base && > + git branch two base > + ) && > + > + test_create_repo forked-other && > + ( > + cd forked-other && > + test_commit other-base && > + git branch foreign other-base > + ) && > + > + git clone forked-upstream forked && > + ( > + cd forked && > + git remote add -f other ../forked-other && > + git remote set-head origin one &&
This is a bit strange because it does not match HEAD in the remote repository but it is necessary for '--forked <remote> uses the branch <remote>/HEAD'. I wonder if that test could be written to use main instead but I guess this doesn't do any harm.
Show 11 quoted lines
> + git branch local-base && > + git branch --track local-one origin/one && > + git branch --track local-two origin/two && > + git branch --track local-foreign other/foreign && > + git branch --track local-onbase local-base && > + > + git checkout local-one && > + test_commit --no-tag local-one-work local-one.t && > + git checkout local-foreign && > + test_commit --no-tag local-foreign-work local-foreign.t && > + git checkout --detach
Why do we need a detached HEAD?
Show 5 quoted lines
> [...] > +test_expect_success '--forked composes with --no-merged' ' > + test_when_finished "git -C forked checkout --detach" && > + git -C forked checkout local-one && > + test_commit -C forked local-only &&
The branch "local-one" already has a local commit so why do we need this?
Show 15 quoted lines
> + git -C forked branch --forked "origin/*" --no-merged origin/one \ > + --format="%(refname:short)" >actual && > + echo local-one >expect && > + test_cmp expect actual > +' > + > +test_expect_success '--forked rejects unknown branch/pattern' ' > + test_must_fail git -C forked branch --forked nope 2>err && > + test_grep "not a valid branch or pattern" err > +' > + > +test_expect_success '--forked requires a value' ' > + test_must_fail git -C forked branch --forked 2>err && > + test_grep "requires a value" err > +'
It is a bit odd to have these two tests in the middle of the ones that check the functionality works.
Show 15 quoted lines
> +test_expect_success '--forked <remote> uses the branch <remote>/HEAD points at' ' > + git -C forked branch --forked origin --format="%(refname:short)" >actual && > + echo local-one >expect && > + test_cmp expect actual > +' > + > +test_expect_success '--forked narrows a <pattern> argument' ' > + git -C forked branch --forked "origin/*" "local-*" \ > + --format="%(refname:short)" >actual && > + cat >expect <<-\EOF && > + local-one > + local-two > + EOF > + test_cmp expect actual > +'
This is looking good
Thanks
Phillip