diff mbox series

[b4] ez: Add a check before returning a commit

Message ID 20240409-check_if_branch_exists-v1-1-136504ad81c2@bootlin.com (mailing list archive)
State Accepted
Headers show
Series [b4] ez: Add a check before returning a commit | expand

Commit Message

Louis Chauvet April 9, 2024, 9:15 a.m. UTC
B4 prep utility only works when a branch is checked out. To avoid
misterious errors at runtime, add a check and a runtime error with an
explicit message when the current branch can't be found.

Cc: thomas.petazzoni@bootlin.com
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 src/b4/ez.py | 4 ++++
 1 file changed, 4 insertions(+)


---
base-commit: cfcbbe6f23943166f11687ecf37252dc20728639
change-id: 20240408-check_if_branch_exists-fbf36b107d0d

Best regards,

Comments

Konstantin Ryabitsev April 9, 2024, 5:06 p.m. UTC | #1
On Tue, 09 Apr 2024 11:15:56 +0200, Louis Chauvet wrote:
> B4 prep utility only works when a branch is checked out. To avoid
> misterious errors at runtime, add a check and a runtime error with an
> explicit message when the current branch can't be found.
> 
> 

Applied, thanks!

[1/1] ez: Add a check before returning a commit
      commit: 3b691d28df6954e8fac742365a08c496f36a3738

Best regards,
diff mbox series

Patch

diff --git a/src/b4/ez.py b/src/b4/ez.py
index eeea0203fea5..a2ed1aa14285 100644
--- a/src/b4/ez.py
+++ b/src/b4/ez.py
@@ -732,6 +732,10 @@  def find_cover_commit(usebranch: Optional[str] = None) -> Optional[str]:
     logger.debug('Looking for the cover letter commit with magic marker "%s"', MAGIC_MARKER)
     if not usebranch:
         usebranch = b4.git_get_current_branch()
+    if usebranch is None:
+        logger.critical("The current repository is not tracking a branch. To use b4, please checkout a branch.")
+        logger.critical("Maybe a rebase is running?")
+        raise RuntimeError("Not currently on a branch, please checkout a b4-tracked branch")
     gitargs = ['log', '--grep', MAGIC_MARKER, '-F', '--pretty=oneline', '--max-count=1', '--since=1.year',
                usebranch]
     lines = b4.git_get_command_lines(None, gitargs)