All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Blain <levraiphilippeblain@gmail.com>
To: "Kernel.org Tools" <tools@linux.kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: [PATCH v2 2/4] ez: also check remote-tracking branches when ENROLL_BASE is not a branch
Date: Mon, 06 Mar 2023 13:02:10 -0500	[thread overview]
Message-ID: <20230219-allow-remote-branches-as-base-v2-2-8db83bda1403@gmail.com> (raw)
In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com>

When invoking 'b4 prep --enroll ENROLL_BASE' with a revision ENROLL_BASE
that does not correspond to a branch, ez.py::start_new_series tries to
find branches where the commit corresponding to the given revision is
found. If there is only one such branch, it is used as the
'base-branch'.

The function 'git_branch_contains' used to find where the commit lives
invokes 'git branch --contains', so only local branches are checked.
This means that if the given revision corresponds to a remote-tracking
branch, git_branch_contains won't recognize it and we will hit:

    CRITICAL: No other branch contains %s: cannot use as fork base

Ensure that remote-tracking branches are also checked by adding an
optional 'checkall' argument to 'git_branch_contains', that in turns
adds a '--all' argument to the 'git branch' invocation, such that both
local and remote-tracking branches are checked. Add that argument to the
call in 'start_new_series'.

An alternative would be to unconditionnally invoke 'git branch' with
'--all' in 'git_branch_contains', but this function is also called in
pr.py::main and ty.py::auto_locate_pr to check if the tip commit of the
given pull requests already exists in a local branch, and it seems safer
to not change behaviour for these two functions.
---
 b4/__init__.py | 4 +++-
 b4/ez.py       | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/b4/__init__.py b/b4/__init__.py
index 3138f3c..78418c1 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2986,8 +2986,10 @@ def git_revparse_tag(gitdir: Optional[str], tagname: str) -> Optional[str]:
     return out.strip()
 
 
-def git_branch_contains(gitdir: Optional[str], commit_id: str) -> List[str]:
+def git_branch_contains(gitdir: Optional[str], commit_id: str, checkall: bool = False) -> List[str]:
     gitargs = ['branch', '--format=%(refname:short)', '--contains', commit_id]
+    if checkall:
+        gitargs.append('--all')
     lines = git_get_command_lines(gitdir, gitargs)
     return lines
 
diff --git a/b4/ez.py b/b4/ez.py
index c3b0237..ce080f1 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -390,7 +390,7 @@ def start_new_series(cmdargs: argparse.Namespace) -> None:
                 raise RuntimeError('Object %s not found' % enroll_base)
             forkpoint = out.strip()
             # check branches where this object lives
-            heads = b4.git_branch_contains(None, forkpoint)
+            heads = b4.git_branch_contains(None, forkpoint, checkall=True)
             if mybranch not in heads:
                 logger.critical('CRITICAL: object %s does not exist on current branch', enroll_base)
                 sys.exit(1)

-- 
2.34.1


  parent reply	other threads:[~2023-03-06 18:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-20  0:45 [PATCH] ez: allow remote-tracking branches as 'base-branch' Philippe Blain
2023-02-24 14:57 ` Philippe Blain
2023-03-06 18:02 ` [PATCH v2 0/4] ez: allow remote-tracking branches as ENROLL_BASE Philippe Blain
2023-03-06 18:02   ` [PATCH v2 1/4] " Philippe Blain
2023-03-06 18:02   ` Philippe Blain [this message]
2023-03-06 18:02   ` [PATCH v2 3/4] ez: allow '@{upstream}' " Philippe Blain
2023-03-06 18:02   ` [PATCH v2 4/4] ez: let ENROLL_BASE default to '@{upstream}' Philippe Blain
2023-03-10 19:59   ` [PATCH v2 0/4] ez: allow remote-tracking branches as ENROLL_BASE 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=20230219-allow-remote-branches-as-base-v2-2-8db83bda1403@gmail.com \
    --to=levraiphilippeblain@gmail.com \
    --cc=konstantin@linuxfoundation.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.