Skip to content

Commit

Permalink
fix: update git reader to take into account env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Charbonnier authored and charbonnierg committed Feb 21, 2024
1 parent abea214 commit e06bf64
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/releaser/infra/git_reader/subprocess.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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()

Expand Down

0 comments on commit e06bf64

Please sign in to comment.