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

It is a common worflow to set 'branch.<name>.merge' and
'branch.<name>.remote' to the remote-tracking branch that corresponds to
the default branch of the canonical repository of the project (say
'upstream/master'), such that 'git rebase -i' automatically "does the
right thing" and rebases only the commits in your feature branch that
are not reachable from 'upstream/master'. The revision syntax
'@{upstream}' (short: '@{u}') can be used to denote the configured
upstream branch of the current branch.

Support that workflow better by allowing the 'ENROLL_BASE' argument to
'b4 prep --enroll' to be ommitted and default to @{upstream}.

To avoid a RuntimeError when enroll_base is @{upstream} (either from the
default or because it was given litterally on the command line) and the
current branch has no configured upstream, add some error-checking to
the 'git rev-parse --verify --abbrev-ref' invocation along with a clear
message. Let other error situations be handled by the second 'git
rev-parse --verify' invocation later on.
---
 b4/command.py | 4 ++--
 b4/ez.py      | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/b4/command.py b/b4/command.py
index e7656a5..1ae73d2 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -290,8 +290,8 @@ def setup_parser() -> argparse.ArgumentParser:
     ag_prepn.add_argument('-F', '--from-thread', metavar='MSGID', dest='msgid',
                           help='When creating a new branch, use this thread')
     ag_prepe = sp_prep.add_argument_group('Enroll existing branch', 'Enroll existing branch for prep work')
-    ag_prepe.add_argument('-e', '--enroll', dest='enroll_base',
-                          help='Enroll current branch, using the passed tag, branch, or commit as fork base')
+    ag_prepe.add_argument('-e', '--enroll', dest='enroll_base', nargs='?', const='@{upstream}',
+                          help='Enroll current branch, using its configured upstream branch as fork base, or the passed tag, branch, or commit')
     sp_prep.set_defaults(func=cmd_prep)
 
     # b4 trailers
diff --git a/b4/ez.py b/b4/ez.py
index 53a4b2f..0a2936a 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -373,7 +373,11 @@ def start_new_series(cmdargs: argparse.Namespace) -> None:
         # 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:
+        if ecode > 0:
+            if enroll_base == '@{upstream}' or enroll_base == '@{u}':
+                logger.critical('CRITICAL: current branch has no configured upstream')
+                sys.exit(1)
+        elif out:
             enroll_base = out.strip()
         # Is it a branch?
         gitargs = ['show-ref', f'refs/heads/{enroll_base}', f'refs/remotes/{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   ` [PATCH v2 3/4] ez: allow '@{upstream}' as ENROLL_BASE Philippe Blain
2023-03-06 18:02   ` Philippe Blain [this message]
2023-03-10 19:59   ` [PATCH v2 0/4] ez: allow remote-tracking branches " 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-4-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.