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

Fix timezone error #1039

Merged
merged 3 commits into from
May 6, 2024
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
3 changes: 3 additions & 0 deletions src/setuptools_scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
import shlex
import sys
import warnings

from datetime import date
Expand Down Expand Up @@ -119,6 +120,8 @@ def parse_timestamp(timestamp_text: str) -> date | None:
if "%c" in timestamp_text:
log.warning("git too old -> timestamp is %r", timestamp_text)
return None
if sys.version_info < (3, 11) and timestamp_text.endswith("Z"):
timestamp_text = timestamp_text[:-1] + "+00:00"
return datetime.fromisoformat(timestamp_text).date()

res = run_git(
Expand Down
16 changes: 16 additions & 0 deletions testing/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ def test_git_getdate_badgit(
assert git_wd.get_head_date() is None


def test_git_getdate_git_2_45_0_plus(
wd: WorkDir, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
wd.commit_testfile()
git_wd = git.GitWorkdir(wd.cwd)
fake_date_result = CompletedProcess(
args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0
)
with patch.object(
git,
"run_git",
Mock(return_value=fake_date_result),
):
assert git_wd.get_head_date() == date(2024, 4, 30)


@pytest.fixture()
def signed_commit_wd(monkeypatch: pytest.MonkeyPatch, wd: WorkDir) -> WorkDir:
if not has_command("gpg", args=["--version"], warn=False):
Expand Down
Loading