@@ -16,12 +16,9 @@ import (
1616)
1717
1818// logRecord assembles one `git log -z --pretty=format:` record as git would emit it. Fields and
19- // records share the same NUL separator, so records are joined with it too.
20- func logRecord (sha , author , commitTime , subject , body , message string ) string {
21- return logRecordWithTrailers (sha , author , commitTime , subject , body , message , "" )
22- }
23-
24- func logRecordWithTrailers (sha , author , commitTime , subject , body , message , trailers string ) string {
19+ // records share the same NUL separator, so records are joined with it too. Pass "" for trailers
20+ // when the commit has none.
21+ func logRecord (sha , author , commitTime , subject , body , message , trailers string ) string {
2522 return strings .Join ([]string {sha , author , commitTime , subject , body , message , trailers }, "\x00 " )
2623}
2724
@@ -30,8 +27,8 @@ var _ = Describe("parseCommitLogOutput", func() {
3027 stdout := strings .Join ([]string {
3128 logRecord ("abc123" , "Alice Example" , "2023-11-14T22:33:20-04:00" , "feat: do something important" ,
3229 "Body paragraph one.\n \n Signed-off-by: Alice Example <alice@example.com>\n " ,
33- "feat: do something important\n \n Body paragraph one.\n \n Signed-off-by: Alice Example <alice@example.com>\n " ),
34- logRecord ("def456" , "Bob Example" , "2023-11-14T22:33:20+00:00" , "subject only" , "" , "subject only\n " ),
30+ "feat: do something important\n \n Body paragraph one.\n \n Signed-off-by: Alice Example <alice@example.com>\n " , "" ),
31+ logRecord ("def456" , "Bob Example" , "2023-11-14T22:33:20+00:00" , "subject only" , "" , "subject only\n " , "" ),
3532 }, "\x00 " )
3633
3734 results , err := git .ParseCommitLogOutput (stdout )
@@ -61,8 +58,8 @@ var _ = Describe("parseCommitLogOutput", func() {
6158
6259 It ("preserves the empty fields of a commit with no message" , func () {
6360 stdout := strings .Join ([]string {
64- logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "" , "" , "" ),
65- logRecord ("def456" , "Bob" , "2023-11-14T22:33:20+00:00" , "subject" , "" , "subject\n " ),
61+ logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "" , "" , "" , "" ),
62+ logRecord ("def456" , "Bob" , "2023-11-14T22:33:20+00:00" , "subject" , "" , "subject\n " , "" ),
6663 }, "\x00 " )
6764
6865 results , err := git .ParseCommitLogOutput (stdout )
@@ -75,7 +72,7 @@ var _ = Describe("parseCommitLogOutput", func() {
7572
7673 It ("keeps a message that contains the field separator's printable predecessors" , func () {
7774 results , err := git .ParseCommitLogOutput (
78- logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "before\x1f after\n " , "s\n \n before\x1f after\n " ))
75+ logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "before\x1f after\n " , "s\n \n before\x1f after\n " , "" ))
7976 Expect (err ).NotTo (HaveOccurred ())
8077 Expect (results ["abc123" ].State .Body ).To (Equal ("before\x1f after" ))
8178 })
@@ -86,7 +83,7 @@ var _ = Describe("parseCommitLogOutput", func() {
8683 })
8784
8885 It ("parses the trailers field into a map with repeated keys" , func () {
89- results , err := git .ParseCommitLogOutput (logRecordWithTrailers ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "" , "s\n " ,
86+ results , err := git .ParseCommitLogOutput (logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "" , "s\n " ,
9087 "Signed-off-by: A\n Signed-off-by: B\n Promoter-Description: \" a: b\" \n " ))
9188 Expect (err ).NotTo (HaveOccurred ())
9289 Expect (results ["abc123" ].Trailers ()).To (Equal (map [string ][]string {
@@ -96,14 +93,14 @@ var _ = Describe("parseCommitLogOutput", func() {
9693 })
9794
9895 It ("returns an empty, non-nil trailer map for a commit without trailers" , func () {
99- results , err := git .ParseCommitLogOutput (logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "" , "s\n " ))
96+ results , err := git .ParseCommitLogOutput (logRecord ("abc123" , "Alice" , "2023-11-14T22:33:20+00:00" , "s" , "" , "s\n " , "" ))
10097 Expect (err ).NotTo (HaveOccurred ())
10198 Expect (results ["abc123" ].Trailers ()).NotTo (BeNil ())
10299 Expect (results ["abc123" ].Trailers ()).To (BeEmpty ())
103100 })
104101
105102 It ("rejects an unparsable committer time" , func () {
106- _ , err := git .ParseCommitLogOutput (logRecord ("abc123" , "Alice" , "not-a-time" , "s" , "" , "s\n " ))
103+ _ , err := git .ParseCommitLogOutput (logRecord ("abc123" , "Alice" , "not-a-time" , "s" , "" , "s\n " , "" ))
107104 Expect (err ).To (MatchError (ContainSubstring ("parse committer time" )))
108105 })
109106})
0 commit comments