* [PATCH] ty: Fix git-config regexp in get_branch_info()
@ 2023-03-10 5:57 Michael Ellerman
2023-03-10 20:11 ` Konstantin Ryabitsev
0 siblings, 1 reply; 2+ messages in thread
From: Michael Ellerman @ 2023-03-10 5:57 UTC (permalink / raw)
To: tools
The regexp used to get the branch configuration in get_branch_info()
is subtly wrong. If there are multiple branches starting with the same
prefix, the configuration for all of them will be returned, which can
lead to the wrong branch info being used.
eg. Running b4 -d ty, with extra logging of every line in
get_config_from_git() shows:
Running git --no-pager config -z --get-regexp branch\.foo\.*
branch.foo.remote .
branch.foo.merge refs/heads/foo-test
branch.foo-test.remote .
branch.foo-test.merge refs/heads/foo-base
Although the regexp has two escaped dots, the 2nd one is seemingly
consumed by the '*', leading to the regexp matching "foo" and
"foo-test".
This can be observed on the command line:
$ git branch -t foo origin/master
$ git branch -t foo-test origin/master
$ git --no-pager config --get-regexp "branch\.foo\.*"
branch.foo.remote .
branch.foo.merge refs/heads/foo-test
branch.foo-test.remote .
branch.foo-test.merge refs/heads/foo-base
The real problem is that we meant to pass a regexp of
"branch\.foo\..*", so change the code to use that, which fixes the
problem:
$ git --no-pager config --get-regexp "branch\.foo\..*"
branch.foo.remote origin
branch.foo.merge refs/heads/master
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
b4/ty.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/b4/ty.py b/b4/ty.py
index 6da1a15..165afd9 100644
--- a/b4/ty.py
+++ b/b4/ty.py
@@ -665,7 +665,7 @@ BRANCH_INFO = None
BRANCH_INFO = dict()
- remotecfg = b4.get_config_from_git('branch\\.%s\\.*' % branch)
+ remotecfg = b4.get_config_from_git('branch\\.%s\\..*' % branch)
if remotecfg is None or 'remote' not in remotecfg:
# Did not find a matching branch entry, so look at remotes
gitargs = ['remote', 'show']
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ty: Fix git-config regexp in get_branch_info()
2023-03-10 5:57 [PATCH] ty: Fix git-config regexp in get_branch_info() Michael Ellerman
@ 2023-03-10 20:11 ` Konstantin Ryabitsev
0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Ryabitsev @ 2023-03-10 20:11 UTC (permalink / raw)
To: tools, Michael Ellerman
On Fri, 10 Mar 2023 16:57:53 +1100, Michael Ellerman wrote:
> The regexp used to get the branch configuration in get_branch_info()
> is subtly wrong. If there are multiple branches starting with the same
> prefix, the configuration for all of them will be returned, which can
> lead to the wrong branch info being used.
>
> eg. Running b4 -d ty, with extra logging of every line in
> get_config_from_git() shows:
>
> [...]
Applied, thanks!
[1/1] ty: Fix git-config regexp in get_branch_info()
commit: 4f90eab09937e78f27e63a01076af72f8d45e3f3
Best regards,
--
Konstantin Ryabitsev <konstantin@linuxfoundation.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-10 20:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 5:57 [PATCH] ty: Fix git-config regexp in get_branch_info() Michael Ellerman
2023-03-10 20:11 ` Konstantin Ryabitsev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).