From 6cfa6622f31953bd75bfae4c9b10915e3dd6bd78 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Fri, 22 Sep 2023 12:39:00 -0600 Subject: Go documentation for all public functions --- commit.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'commit.go') diff --git a/commit.go b/commit.go index c7a102d..cdbb244 100644 --- a/commit.go +++ b/commit.go @@ -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") -- cgit v1.2.3