aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Blain <levraiphilippeblain@gmail.com>2023-03-06 13:02:12 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2023-03-10 14:56:18 -0500
commit800dae4b48fbbfb2bd52e0bc2da351b0627659b8 (patch)
tree0beae1b8794a79a943890ebff47a7dc1237e8c0b
parent1f34f802252976549d82338807c75729766653c6 (diff)
downloadb4-800dae4b48fbbfb2bd52e0bc2da351b0627659b8.tar.gz
ez: let ENROLL_BASE default to '@{upstream}'
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. Link: https://msgid.link/20230219-allow-remote-branches-as-base-v2-1-8db83bda1403@gmail.com Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/command.py4
-rw-r--r--b4/ez.py6
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}']