Re: [PATCH b4] Prevent interpreting usebranch as a path in find_cover_commit

Jacob Keller <[email protected]> Thu, 4 Jun 2026 12:14:29 -0700
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
On 5/13/2026 2:30 PM, Jacob Keller wrote:
> b4 can become very confused if the current branch name happens to also be
> the same as a file in the root of the repository. When that happens, the
> find_cover_commit() function will execute a git log command that can
> accidentally interpret the usebranch value as the path. This results in b4
> being unable to identify the cover commit, and assuming the branch is
> unmanaged.
> 
> Fix this by adding an explicit '--' argument which ensures that git will
> disambiguate and never interpret the branch argument as a file name.
> 
> This addition is sufficient to resolve my case where I had exported the
> patch series using b4 send -o to a directory with the same name as the
> branch. It is likely that other git invocation sin the b4 codebase could
> benefit from explicit separators, but I did not go digging.
> 
> Signed-off-by: Jacob Keller <[email protected]>
> ---
>  src/b4/ez.py | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/b4/ez.py b/src/b4/ez.py
> index 3e81138e2dfe..d1e2fba76ea9 100644
> --- a/src/b4/ez.py
> +++ b/src/b4/ez.py
> @@ -902,6 +902,7 @@ def find_cover_commit(usebranch: Optional[str] = None) -> Optional[str]:
>          '--no-mailmap',
>          f'--committer={limit_committer}',
>          usebranch,
> +        '--',
>      ]
>      lines = b4.git_get_command_lines(None, gitargs)
>      if not lines:
> 

I didn't see any reply to this change. The fix is minor and helped me in
the case where my local branch happened to conflict with a directory in
the root of the repository. I'd like to have this (or some other
solution) applied so that no one else runs into the same gotcha, however
unlikely it might seem. Without '--' git doesn't always disambiguate as
you expect and in this specific case it doesn't even fail, it succeeds
and causes b4 to act as if there is no cover commit.

Thanks,
Jake

> ---
> base-commit: d5d981426ead3f490713ef5d2fd1aa3d0f13b005
> change-id: 20260513-jk-dont-interpret-branch-as-filename-e4cbba6f400f
> 
> Best regards,
> --  
> Jacob Keller <[email protected]>
>