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 3/4] ez: allow '@{upstream}' as ENROLL_BASE
Date: Mon, 06 Mar 2023 13:02:11 -0500	[thread overview]
Message-ID: <20230219-allow-remote-branches-as-base-v2-3-8db83bda1403@gmail.com> (raw)
In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com>

Invoking 'b4 prep --enroll @{u}' (or @{upstream}) does not work reliably
with the current code. In 'start_new_series', we take the code path that
checks on which branch the object given as ENROLL_BASE lives using 'git
branch --all --contains', so if multiple local branches build on top of
the current branch's upstream branch, they are all listed by this
invocation of 'git branch' and so we error with 'CRITICAL: Multiple
branches contain object @{u}, please pass a branch name as base'.

Fix that by invoking 'git rev-parse --abbrev-ref --verify ENROLL_BASE'
before the 'git show-branch' invocation. That command will convert @{u},
@{upstream} and @{push} [1-2] to an abbreviated ref like
'upstream/master'. If the given revision exist but can't be directly
converted to an abbreviated ref, the command will succeed and not output
anything, so only change ENROLL_BASE when we actually get an output. We
avoid checking the error code as we already invoke 'git rev-parse
--verify' later on to check if the object exists. We could use
'git_get_command_lines' instead, but we will check the error code in a
subsequent commit, so it makes more sense to use 'git_run_command'.

While at it, fix a "CRITICAL" error message that was missing a value for
the '%s' string formatting operator.

[1] https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltbranchnamegtupstreamemegemmasterupstreamememuem
[2] https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltbranchnamegtpushemegemmasterpushemempushem
---
 b4/ez.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/b4/ez.py b/b4/ez.py
index ce080f1..53a4b2f 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -370,6 +370,11 @@ def start_new_series(cmdargs: argparse.Namespace) -> None:
         seriesname = branchname
         slug = re.sub(r'\W+', '-', branchname).strip('-').lower()
         enroll_base = cmdargs.enroll_base
+        # Convert @{upstream}, @{push} to an abbreviated ref
+        gitargs = ['rev-parse', '--abbrev-ref', '--verify', enroll_base]
+        ecode, out = b4.git_run_command(None, gitargs)
+        if out:
+            enroll_base = out.strip()
         # Is it a branch?
         gitargs = ['show-ref', f'refs/heads/{enroll_base}', f'refs/remotes/{enroll_base}']
         lines = b4.git_get_command_lines(None, gitargs)
@@ -377,7 +382,7 @@ def start_new_series(cmdargs: argparse.Namespace) -> None:
             try:
                 forkpoint = get_base_forkpoint(enroll_base, mybranch)
             except RuntimeError as ex:
-                logger.critical('CRITICAL: could not use %s as enrollment base:')
+                logger.critical('CRITICAL: could not use %s as enrollment base:', enroll_base)
                 logger.critical('          %s', ex)
                 sys.exit(1)
             basebranch = enroll_base

-- 
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   ` [PATCH v2 2/4] ez: also check remote-tracking branches when ENROLL_BASE is not a branch Philippe Blain
2023-03-06 18:02   ` Philippe Blain [this message]
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-3-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.