Skip to content

Commit 5469357

Browse files
committed
Fix passing ccount=None to template
1 parent e3d8447 commit 5469357

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

docs/changelog/3.0.x.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
3.0.x
22
======
33

4-
3.0.0 (2026-01-15)
4+
3.0.0 (2026-01-16)
55
-------------------
66

77
Breaking
@@ -28,3 +28,4 @@ Bug Fixes
2828
- Fix calling ``get_version(root=...)`` in combination with version-file strategy -
2929
relative file version was resolved against ``os.cwd``, not explicitly passed ``root``.
3030
- Fix epoch versions like ``0!2025.12.3`` were wrongly converted to ``0.2025.12.3`` (:github:issue:`122`).
31+
- Using version_file-based schema with shallow git clone lead to version numbers like ``1.2.3.postNone``, now it is ``1.2.3.post0`` (:github:issue:`104`).

setuptools_git_versioning/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def version_from_git( # noqa: PLR0915, PLR0912, PLR0913, C901
167167
file_sha = get_latest_file_commit(version_file, root=root)
168168
log.log(DEBUG, "File SHA-256: %r", file_sha)
169169

170-
ccount = count_since(file_sha, root=root) if file_sha is not None else None
170+
ccount = count_since(file_sha, root=root) if file_sha else None
171171
log.log(INFO, "Commits count between HEAD and last version file change: %r", ccount)
172172

173173
elif not head_sha:
@@ -208,6 +208,6 @@ def version_from_git( # noqa: PLR0915, PLR0912, PLR0913, C901
208208
t = template
209209

210210
full_sha = head_sha if head_sha is not None else ""
211-
version = resolve_substitutions(t, sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha)
211+
version = resolve_substitutions(t, sha=full_sha[:8], tag=tag, ccount=ccount or 0, branch=branch, full_sha=full_sha)
212212
log.log(INFO, "Version number after resolving substitutions: %r", version)
213213
return sanitize_version(version)

tests/test_integration/test_version_file.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
create_commit,
77
create_file,
88
create_tag,
9+
execute,
910
get_full_sha,
1011
get_sha,
1112
get_version,
@@ -210,6 +211,21 @@ def test_version_file_tagged_head(repo, create_config):
210211
assert get_version(repo) == "1.0.0"
211212

212213

214+
def test_version_file_with_shallow_clone(repo, create_config):
215+
execute(repo, "git", "checkout", "--orphan", "disembed")
216+
create_file(repo, "VERSION.txt", "1.0.0", commit=False)
217+
create_config(
218+
repo,
219+
{
220+
"version_file": "VERSION.txt",
221+
"count_commits_from_version_file": True,
222+
},
223+
commit=False,
224+
)
225+
226+
assert get_version(repo) == "1.0.0.post0+git.dirty"
227+
228+
213229
@pytest.mark.parametrize(("starting_version", "version"), [(None, "0.0.1"), ("1.2.3", "1.2.3")])
214230
@pytest.mark.parametrize("create_version", [True, False])
215231
def test_version_file_missing(repo, create_config, create_version, starting_version, version):

0 commit comments

Comments
 (0)