Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

types/commit: skip parent line for root commits in payload

Signed-off-by: Carl 'Subzidion' Hiltbrunner <git@carl.hiltbrunner.email>

authored by

Carl 'Subzidion' Hiltbrunner and committed by
Tangled
84ae132b 41c1359b

+70 -1
+1 -1
types/commit.go
··· 149 149 for _, p := range c.ParentHashes { 150 150 fmt.Fprintf(&payload, "parent %s\n", p.String()) 151 151 } 152 - } else { 152 + } else if c.Parent != "" { 153 153 // present for backwards compatibility 154 154 fmt.Fprintf(&payload, "parent %s\n", c.Parent) 155 155 }
+69
types/commit_test.go
··· 1 + package types 2 + 3 + import ( 4 + "strings" 5 + "testing" 6 + "time" 7 + 8 + "github.com/go-git/go-git/v5/plumbing" 9 + "github.com/go-git/go-git/v5/plumbing/object" 10 + ) 11 + 12 + func TestPayloadRootCommit(t *testing.T) { 13 + when := time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC) 14 + sig := object.Signature{Name: "Alice", Email: "alice@example.com", When: when} 15 + 16 + c := Commit{ 17 + Author: sig, 18 + Committer: sig, 19 + Message: "initial commit\n", 20 + Tree: "abc123", 21 + } 22 + 23 + payload := c.Payload() 24 + 25 + for _, line := range strings.Split(payload, "\n") { 26 + if strings.HasPrefix(line, "parent ") || line == "parent" { 27 + t.Errorf("root commit payload must not contain a parent line, got: %q\nfull payload:\n%s", line, payload) 28 + } 29 + } 30 + } 31 + 32 + func TestPayloadWithParentHashes(t *testing.T) { 33 + when := time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC) 34 + sig := object.Signature{Name: "Alice", Email: "alice@example.com", When: when} 35 + parent := plumbing.NewHash("0000000000000000000000000000000000000001") 36 + 37 + c := Commit{ 38 + Author: sig, 39 + Committer: sig, 40 + Message: "second commit\n", 41 + Tree: "abc123", 42 + ParentHashes: []plumbing.Hash{parent}, 43 + } 44 + 45 + payload := c.Payload() 46 + want := "parent " + parent.String() 47 + if !strings.Contains(payload, want) { 48 + t.Errorf("payload missing %q\nfull payload:\n%s", want, payload) 49 + } 50 + } 51 + 52 + func TestPayloadLegacyParentField(t *testing.T) { 53 + when := time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC) 54 + sig := object.Signature{Name: "Alice", Email: "alice@example.com", When: when} 55 + 56 + c := Commit{ 57 + Author: sig, 58 + Committer: sig, 59 + Message: "second commit\n", 60 + Tree: "abc123", 61 + Parent: "0000000000000000000000000000000000000001", 62 + } 63 + 64 + payload := c.Payload() 65 + want := "parent 0000000000000000000000000000000000000001" 66 + if !strings.Contains(payload, want) { 67 + t.Errorf("payload missing %q\nfull payload:\n%s", want, payload) 68 + } 69 + }