Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 9dd3944

Browse files
committed
Clamp object timestamps before unix epoch to unix epoch
1 parent 1cef577 commit 9dd3944

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

plumbing/object/object.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func (s *Signature) decodeTimeAndTimeZone(b []byte) {
152152
}
153153

154154
func (s *Signature) encodeTimeAndTimeZone(w io.Writer) error {
155-
_, err := fmt.Fprintf(w, "%d %s", s.When.Unix(), s.When.Format("-0700"))
155+
u := s.When.Unix()
156+
if u < 0 {
157+
u = 0
158+
}
159+
_, err := fmt.Fprintf(w, "%d %s", u, s.When.Format("-0700"))
156160
return err
157161
}
158162

plumbing/object/tag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (s *TagSuite) TestStringNonCommit(c *C) {
265265
c.Assert(tag.String(), Equals,
266266
"tag TAG TWO\n"+
267267
"Tagger: <>\n"+
268-
"Date: Mon Jan 01 00:00:00 0001 +0000\n"+
268+
"Date: Thu Jan 01 00:00:00 1970 +0000\n"+
269269
"\n"+
270270
"tag two\n")
271271
}

0 commit comments

Comments
 (0)