Skip to content

Commit abb67b1

Browse files
Merge pull request #538 from RonnyPfannschmidt/fix-537-drop-node-date-on-old-git
drop node_date on old git
2 parents 53c16ce + 32ab7e6 commit abb67b1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v6.0.1
2+
=======
3+
4+
* fix #537: drop node_date on old git to avoid errors on missing %cI
5+
16
v6.0.0
27
======
38

src/setuptools_scm/git.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def get_head_date(self):
6161
return
6262
# TODO, when dropping python3.6 use fromiso
6363
date_part = timestamp.split("T")[0]
64+
if "%c" in date_part:
65+
trace("git too old -> timestamp is ", timestamp)
66+
return None
6467
return datetime.strptime(date_part, r"%Y-%m-%d").date()
6568

6669
def is_shallow(self):

testing/test_git.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from os.path import join as opj
99
from setuptools_scm.file_finder_git import git_find_files
1010
from datetime import date
11-
11+
from unittest.mock import patch, Mock
1212

1313
pytestmark = pytest.mark.skipif(
1414
not has_command("git", warn=False), reason="git executable not found"
@@ -307,3 +307,12 @@ def parse_date():
307307
assert git_wd.get_head_date() == today
308308
meta = git.parse(os.fspath(wd.cwd))
309309
assert meta.node_date == today
310+
311+
312+
def test_git_getdate_badgit(
313+
wd,
314+
):
315+
wd.commit_testfile()
316+
git_wd = git.GitWorkdir(os.fspath(wd.cwd))
317+
with patch.object(git_wd, "do_ex", Mock(return_value=("%cI", "", 0))):
318+
assert git_wd.get_head_date() is None

0 commit comments

Comments
 (0)