Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: tools@linux.kernel.org
Subject: [PATCH] ty: Fix git-config regexp in get_branch_info()
Date: Fri, 10 Mar 2023 16:57:53 +1100	[thread overview]
Message-ID: <20230310055753.1609529-1-mpe@ellerman.id.au> (raw)

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


             reply	other threads:[~2023-03-10  6:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  5:57 Michael Ellerman [this message]
2023-03-10 20:11 ` [PATCH] ty: Fix git-config regexp in get_branch_info() Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230310055753.1609529-1-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=tools@linux.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).