From e06bf641651d7dc8017d2b7013f7a79a25fec6f6 Mon Sep 17 00:00:00 2001 From: Guillaume Charbonnier Date: Wed, 21 Feb 2024 00:23:16 +0100 Subject: [PATCH] fix: update git reader to take into account env variable --- src/releaser/infra/git_reader/subprocess.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/releaser/infra/git_reader/subprocess.py b/src/releaser/infra/git_reader/subprocess.py index 29c5c4b..6bd7c59 100644 --- a/src/releaser/infra/git_reader/subprocess.py +++ b/src/releaser/infra/git_reader/subprocess.py @@ -1,9 +1,12 @@ from __future__ import annotations +import os import subprocess from releaser.hexagon.ports import GitReader +GIT_BRANCH_NAME_ENV_VAR = "BUILD_BRANCH_NAME" + class GitSubprocessReader(GitReader): """A git reader that uses subprocesses to read git information.""" @@ -19,6 +22,8 @@ def is_dirty(self) -> bool: return process.returncode != 0 def read_current_branch(self) -> str: + if branch := os.environ.get(GIT_BRANCH_NAME_ENV_VAR): + return branch branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]) return branch.decode().strip()