Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .git_archival.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe)$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ and copy-paste this into it::

node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true)$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$

Create the ``.gitattributes`` file in the root directory of your repository
Expand Down
2 changes: 1 addition & 1 deletion src/setuptools_scm/.git_archival.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe)$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
17 changes: 14 additions & 3 deletions src/setuptools_scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,29 @@ def _git_parse_inner(
)


def _git_parse_describe(describe_output: str) -> tuple[str, int, str, bool]:
def _git_parse_describe(
describe_output: str,
) -> tuple[str, int | None, str | None, bool]:
# 'describe_output' looks e.g. like 'v1.5.0-0-g4060507' or
# 'v1.15.1rc1-37-g9bd1298-dirty'.
# It may also just be a bare tag name if this is a tagged commit and we are
# parsing a .git_archival.txt file.

if describe_output.endswith("-dirty"):
dirty = True
describe_output = describe_output[:-6]
else:
dirty = False

tag, number, node = describe_output.rsplit("-", 2)
return tag, int(number), node, dirty
split = describe_output.rsplit("-", 2)
if len(split) < 3: # probably a tagged commit
tag = describe_output
number = None
node = None
else:
tag, number_, node = split
number = int(number_)
return tag, number, node, dirty


def search_parent(dirname: _t.PathT) -> GitWorkdir | None:
Expand Down
1 change: 1 addition & 0 deletions testing/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ def test_git_getdate_signed_commit(signed_commit_wd: WorkDir) -> None:
("0.0", {"node": "0" * 20}),
("1.2.2", {"describe-name": "release-1.2.2-0-g00000"}),
("1.2.2.dev0", {"ref-names": "tag: release-1.2.2.dev"}),
("1.2.2", {"describe-name": "v1.2.2"}),
],
)
@pytest.mark.filterwarnings("ignore:git archive did not support describe output")
Expand Down