From 173be1a7a107639be912d0fb76149accb54b0332 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Fri, 23 Jun 2023 14:19:51 -0500 Subject: [PATCH] Adds `branch_name` to SCM information --- bumpversion/scm.py | 7 ++++++- docsrc/configuration.md | 2 +- docsrc/search-and-replace.md | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bumpversion/scm.py b/bumpversion/scm.py index 467bf78f..ed41869b 100644 --- a/bumpversion/scm.py +++ b/bumpversion/scm.py @@ -24,6 +24,7 @@ class SCMInfo: commit_sha: Optional[str] = None distance_to_latest_tag: Optional[int] = None current_version: Optional[str] = None + branch_name: Optional[str] = None dirty: Optional[bool] = None def __str__(self): @@ -240,11 +241,15 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo: ] result = subprocess.run(git_cmd, text=True, check=True, capture_output=True) # noqa: S603 describe_out = result.stdout.strip().split("-") + + git_cmd = ["git", "rev-parse", "--abbrev-ref", "HEAD"] + result = subprocess.run(git_cmd, text=True, check=True, capture_output=True) # noqa: S603 + branch_name = result.stdout.strip() except subprocess.CalledProcessError as e: logger.debug("Error when running git describe: %s", e.stderr) return SCMInfo(tool=cls) - info = SCMInfo(tool=cls) + info = SCMInfo(tool=cls, branch_name=branch_name) if describe_out[-1].strip() == "dirty": info.dirty = True diff --git a/docsrc/configuration.md b/docsrc/configuration.md index 8b0df58c..9b4d3599 100644 --- a/docsrc/configuration.md +++ b/docsrc/configuration.md @@ -262,7 +262,7 @@ In this example (in TOML): serialize = [ "{major}.{minor}.{patch}", "{major}.{minor}", - "{major}" + "{major}" ] ``` diff --git a/docsrc/search-and-replace.md b/docsrc/search-and-replace.md index d5ff6948..62ac354b 100644 --- a/docsrc/search-and-replace.md +++ b/docsrc/search-and-replace.md @@ -110,7 +110,7 @@ You can use bump-my-version to maintain the major version number within the `go. ```toml [tool.bumpversion] -current_version = 2.21.4 +current_version = "2.21.4" [[tool.bumpversion.files]] filename = "go.mod"