diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2024-02-13 12:07:35 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2024-02-13 12:07:35 -0500 |
commit | 1d8c58b15facf490336e0146aaabb1c5194bf733 (patch) | |
tree | 76d09c4d10b04a41dfc5c5022b97d2bb3d371477 | |
parent | bc83b76296315abd62fdfcec2276d96e3b611f7a (diff) | |
download | b4-1d8c58b15facf490336e0146aaabb1c5194bf733.tar.gz |
ez: don't crash if prep is starting on detached head
If we're on a detached head, allow creating a new prep branch anyway.
Reported-by: Marcos Paulo de Souza <me@mpdesouza.com>
Closes: https://github.com/mricon/b4/issues/19
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/__init__.py | 2 | ||||
-rw-r--r-- | b4/ez.py | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index 6ab9b94..7c803fa 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -3892,7 +3892,7 @@ def git_get_current_branch(gitdir: Optional[str] = None, short: bool = True) -> gitargs = ['symbolic-ref', '-q', 'HEAD'] ecode, out = git_run_command(gitdir, gitargs) if ecode > 0: - logger.critical('Not able to get current branch (git symbolic-ref HEAD)') + logger.debug('Not able to get current branch (git symbolic-ref HEAD)') return None mybranch = out.strip() if short: @@ -332,7 +332,10 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: basebranch = None if not cmdargs.fork_point: cmdargs.fork_point = 'HEAD' - basebranch = mybranch + if mybranch: + basebranch = mybranch + else: + basebranch = 'HEAD' else: # if our strategy is not "commit", then we need to know which branch we're using as base if strategy != 'commit': @@ -655,6 +658,13 @@ def is_prep_branch(mustbe: bool = False, usebranch: Optional[str] = None) -> boo mybranch = usebranch else: mybranch = b4.git_get_current_branch() + if mybranch is None: + # Not on any branch? + if mustbe: + logger.critical(mustmsg) + sys.exit(1) + return False + strategy = get_cover_strategy(mybranch) if strategy in {'commit', 'tip-commit'}: if find_cover_commit(usebranch=mybranch) is None: |