summaryrefslogtreecommitdiff
path: root/commit.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-09-22 12:39:00 -0600
committertjpcc <tjp@ctrl-c.club>2023-09-22 12:39:00 -0600
commit6cfa6622f31953bd75bfae4c9b10915e3dd6bd78 (patch)
tree71c6d9b9e76ba0abc9ae6031a316f644246461d7 /commit.go
parent1a1832b77d53849a0aa8216627301aaf9e18d6f8 (diff)
Go documentation for all public functions
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go8
1 files changed, 8 insertions, 0 deletions
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")