Skip to content

Commit

Permalink
Adds branch_name to SCM information
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Jun 23, 2023
1 parent 9d965e5 commit 173be1a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion bumpversion/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docsrc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ In this example (in TOML):
serialize = [
"{major}.{minor}.{patch}",
"{major}.{minor}",
"{major}"
"{major}"
]
```

Expand Down
2 changes: 1 addition & 1 deletion docsrc/search-and-replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 173be1a

Please sign in to comment.