MCPcopy Index your code
hub / github.com/go-git/go-git / TestDecodeClearsExistingState

Method TestDecodeClearsExistingState

plumbing/object/commit_test.go:45–86  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

43}
44
45func (s *SuiteCommit) TestDecodeClearsExistingState(c *C) {
46 const raw = "tree eba74343e2f15d62adedfd8c883ee0262b5c8021\n\nfresh message\n"
47
48 staleSrc := &plumbing.MemoryObject{}
49 commit := &Commit{
50 Hash: plumbing.NewHash("1111111111111111111111111111111111111111"),
51 Author: Signature{Name: "Stale Author", Email: "author@example.local", When: time.Unix(1, 0).UTC()},
52 Committer: Signature{Name: "Stale Committer", Email: "committer@example.local", When: time.Unix(2, 0).UTC()},
53 MergeTag: "stale merge tag",
54 PGPSignature: "stale signature",
55 Message: "stale message",
56 TreeHash: plumbing.NewHash("2222222222222222222222222222222222222222"),
57 ParentHashes: []plumbing.Hash{
58 plumbing.NewHash("3333333333333333333333333333333333333333"),
59 },
60 Encoding: MessageEncoding("latin-1"),
61 ExtraHeaders: []ExtraHeader{
62 {Key: "x-stale", Value: "stale"},
63 },
64 s: s.Storer,
65 src: staleSrc,
66 }
67
68 obj := &plumbing.MemoryObject{}
69 obj.SetType(plumbing.CommitObject)
70 _, err := obj.Write([]byte(raw))
71 c.Assert(err, IsNil)
72
73 c.Assert(commit.Decode(obj), IsNil)
74 c.Assert(commit.Hash, Equals, obj.Hash())
75 c.Assert(commit.Author, DeepEquals, Signature{})
76 c.Assert(commit.Committer, DeepEquals, Signature{})
77 c.Assert(commit.MergeTag, Equals, "")
78 c.Assert(commit.PGPSignature, Equals, "")
79 c.Assert(commit.Message, Equals, "fresh message\n")
80 c.Assert(commit.TreeHash.String(), Equals, "eba74343e2f15d62adedfd8c883ee0262b5c8021")
81 c.Assert(commit.ParentHashes, IsNil)
82 c.Assert(commit.Encoding, Equals, defaultUtf8CommitMessageEncoding)
83 c.Assert(commit.ExtraHeaders, IsNil)
84 c.Assert(commit.s, Equals, s.Storer)
85 c.Assert(commit.src, Equals, obj)
86}
87
88func (s *SuiteCommit) TestType(c *C) {
89 c.Assert(s.Commit.Type(), Equals, plumbing.CommitObject)

Callers

nothing calls this directly

Calls 7

SetTypeMethod · 0.95
WriteMethod · 0.95
DecodeMethod · 0.95
HashMethod · 0.95
NewHashFunction · 0.92
MessageEncodingTypeAlias · 0.85
StringMethod · 0.65

Tested by

no test coverage detected