Skip to content

Read a commit timestamp whose offset is beyond 14 hours instead of failing Log() [patch] - #267

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/262-out-of-range-timezone
Oct 20, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/262-out-of-range-timezone

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #262

What changed

GitLogParser.ReadTimestamp used to throw GitParseException whenever DateTimeOffset.TryParse failed. DateTimeOffset only holds offsets up to ±14:00, but git accepts any ±hhmm zone, so one imported commit with +1500 made Log() fail for the entire history, and made Commit() report failure after git had already made the commit.

When the normal parse fails, ReadTimestamp now reads %aI/%cI by hand: yyyy-MM-ddTHH:mm:ss plus a ±hh:mm offset. If the offset is beyond ±14:00, it returns the same instant in UTC. Any other malformed value still throws, and so does an in-range offset that failed to parse for some other reason.

GitSignature.Timestamp now documents this as the one exception to its preserved-offset rule.

Design note: the issue suggested adding %at/%ct to LogFormat. I kept the format unchanged and read the offset from the existing ISO field instead. That gives the same instant without changing the field count, which every log fixture and FieldCount depend on. If you'd rather have the Unix-seconds fields, that's a follow-up.

Tests

GitLogParserTests:

  • ReadsATimestampWithAnOffsetBeyondFourteenHours: +15:00 and -15:00 author and committer dates parse to Unix time 1700000000, with an in-range row for comparison. The values are exactly what git 2.43 prints for GIT_AUTHOR_DATE="1700000000 +1500" / GIT_COMMITTER_DATE="1700000000 -1500", which I checked against a real repository.
  • RejectsAMalformedTimestampWithAnOutOfRangeOffset: a malformed offset, an invalid month, and an offset with no date still throw GitParseException.

Without the parser change, the +15:00 and -15:00 rows fail. With it, the full suite passes: 923/923.


Generated by Claude Code

…iling Log() [patch]

git stores a commit's zone as an arbitrary +-hhmm, so imported history can
carry +15:00, which DateTimeOffset cannot hold. ReadTimestamp threw
GitParseException for that record, failing Log() for the whole history and
making Commit() report failure after git had made the commit.

The parser now reads such a timestamp by hand and returns the same instant in
UTC. GitSignature.Timestamp documents the exception to its preserved-offset
rule.

Fixes #262

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PTQ7jCRWNMZJ4a5VEJRtt4
Addresses SonarCloud S3358 on this change; behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PTQ7jCRWNMZJ4a5VEJRtt4
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 2e20b47 into main Oct 20, 2026
18 checks passed
@matt-edmondson
matt-edmondson deleted the fix/262-out-of-range-timezone branch October 20, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log() throws GitParseException for the whole history when any commit has a timezone offset beyond ±14:00 (e.g. +1500), which git accepts

2 participants