Repository: pypa/setuptools_scm

Issue:
v6 breaks on Centos7 due to older git
Hi,

Changes between v5 and v6 results in downstream packages failing to build/install on Centos7, e.g. black

Centos7 seems to come with git 1.8.3.1 which doesn't support the `%cI` format as used by `get_head_date()` resulting in the following error when using pre-commit+black:
```
File "/tmp/pip-build-env-y421rvu8/overlay/lib/python3.7/site-packages/setuptools_scm/git.py", line 124, in parse
        node_date = wd.get_head_date() or date.today()
      File "/tmp/pip-build-env-y421rvu8/overlay/lib/python3.7/site-packages/setuptools_scm/git.py", line 64, in get_head_date
        return datetime.strptime(date_part, r"%Y-%m-%d").date()
      File "/opt/checksec/canopy/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
        tt, fraction, gmtoff_fraction = _strptime(data_string, format)
      File "/opt/checksec/canopy/lib/python3.7/_strptime.py", line 359, in _strptime
        (data_string, format))
    ValueError: time data '%cI' does not match format '%Y-%m-%d'
```

Installing either a newer git or `setuptools_scm~=5.0` works around the issue.

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 2bfe2d9..ecbcf81 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,8 @@
+v6.0.1
+=======
+
+*  fix #537: drop node_date on old git to avoid errors on missing %cI
+
 v6.0.0
 ======
 
diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py
index b1a85ab..c7f301b 100644
--- a/src/setuptools_scm/git.py
+++ b/src/setuptools_scm/git.py
@@ -61,6 +61,9 @@ class GitWorkdir:
             return
         # TODO, when dropping python3.6 use fromiso
         date_part = timestamp.split("T")[0]
+        if "%c" in date_part:
+            trace("git too old -> timestamp is ", timestamp)
+            return None
         return datetime.strptime(date_part, r"%Y-%m-%d").date()
 
     def is_shallow(self):


Test patch:
diff --git a/testing/test_git.py b/testing/test_git.py
index d934c02..8080574 100644
--- a/testing/test_git.py
+++ b/testing/test_git.py
@@ -8,7 +8,7 @@ from datetime import datetime
 from os.path import join as opj
 from setuptools_scm.file_finder_git import git_find_files
 from datetime import date
-
+from unittest.mock import patch, Mock
 
 pytestmark = pytest.mark.skipif(
     not has_command("git", warn=False), reason="git executable not found"
@@ -307,3 +307,12 @@ def test_git_getdate(wd):
     assert git_wd.get_head_date() == today
     meta = git.parse(os.fspath(wd.cwd))
     assert meta.node_date == today
+
+
+def test_git_getdate_badgit(
+    wd,
+):
+    wd.commit_testfile()
+    git_wd = git.GitWorkdir(os.fspath(wd.cwd))
+    with patch.object(git_wd, "do_ex", Mock(return_value=("%cI", "", 0))):
+        assert git_wd.get_head_date() is None