From 5409b55755ff82301002398a761ccb67524c0609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 2 Mar 2022 12:04:45 +0100 Subject: [PATCH] Fix get main branch --- c2cciutils/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/c2cciutils/__init__.py b/c2cciutils/__init__.py index d6309f605..f93b4d05d 100644 --- a/c2cciutils/__init__.py +++ b/c2cciutils/__init__.py @@ -661,11 +661,17 @@ def get_branch(branch: Optional[str]) -> str: Return the branch name """ - return branch or ( + if branch is not None: + return branch + branch = ( subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], check=True, stdout=subprocess.PIPE) .stdout.decode() .strip() ) + if branch == "HEAD": + branch = os.environ.get("GITHUB_HEAD_REF", "master") + assert branch is not None + return branch def get_based_on_master(