Skip to content

Commit

Permalink
Merge pull request #538 from RonnyPfannschmidt/fix-537-drop-node-date…
Browse files Browse the repository at this point in the history
…-on-old-git

drop node_date on old git
  • Loading branch information
RonnyPfannschmidt authored Mar 17, 2021
2 parents 53c16ce + 32ab7e6 commit abb67b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v6.0.1
=======

* fix #537: drop node_date on old git to avoid errors on missing %cI

v6.0.0
======

Expand Down
3 changes: 3 additions & 0 deletions src/setuptools_scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def get_head_date(self):
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):
Expand Down
11 changes: 10 additions & 1 deletion testing/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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"
Expand Down Expand Up @@ -307,3 +307,12 @@ def parse_date():
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

0 comments on commit abb67b1

Please sign in to comment.