diff options
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -5,6 +5,7 @@ import ( "time" ) +// Commit represents a git commit. type Commit struct { Repo *Repository @@ -22,15 +23,22 @@ type Commit struct { Message string } +// ParentHash returns a ref name usable to reach the commit's parent. func (c *Commit) ParentHash() string { return c.Hash + "^" } +// ShortMessage returns the first line of the commit message. func (c *Commit) ShortMessage() string { short, _, _ := strings.Cut(c.Message, "\n") return short } +// RestOfMessage returns all but the first line of the commit message. +// +// It will trim any newline prefixes however, so be aware that +// c.ShortMessage + "\n" + c.RestOfMessage may not produce the original +// commit message. For that use c.Message. func (c *Commit) RestOfMessage() string { _, rest, _ := strings.Cut(c.Message, "\n") return strings.TrimPrefix(rest, "\n") |