Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop node_date on old git #538

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
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