diff --git a/commit.go b/commit.go index 40b9e08..47819bf 100644 --- a/commit.go +++ b/commit.go @@ -79,6 +79,7 @@ func (ci *Commit) TreeId() *Oid { // Parse commit information from the (uncompressed) raw // data from the commit object. +// \n\n separate headers from message func parseCommitData(data []byte) (*Commit, error) { commit := new(Commit) commit.parents = make([]*Oid, 0, 1) @@ -122,7 +123,7 @@ l: nextline += eol + 1 case eol == 0: commit.CommitMessage = string(data[nextline+1:]) - nextline++ + break l default: break l } diff --git a/commit_test.go b/commit_test.go new file mode 100644 index 0000000..5759932 --- /dev/null +++ b/commit_test.go @@ -0,0 +1,21 @@ +package gogit + +import ( + "testing" +) + +// Guard for runtime error: slice bounds out of range +func TestParseCommitData(t *testing.T) { + str := "tree 47e960bd3b10e549716c31badb1fc06aacd708e1\n" + + "author Artiom 1379666165 +0300" + + "committer Artiom 1379666165 +0300\n\n" + + "if case if ClientForAction will return error, client can absent (be nil)\n\n" + + "Conflicts:\n" + + " app/class.js\n" + + commit, _ := parseCommitData([]byte(str)) + + if commit.treeId.String() != "47e960bd3b10e549716c31badb1fc06aacd708e1" { + t.Fatalf("Got bad tree %s", commit.treeId) + } +}