Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Fixed commit parsing with message line witout spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalie Lazu committed Oct 18, 2013
1 parent 5f47795 commit 54cd7da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion commit.go
Expand Up @@ -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)
Expand Down Expand Up @@ -122,7 +123,7 @@ l:
nextline += eol + 1
case eol == 0:
commit.CommitMessage = string(data[nextline+1:])
nextline++
break l
default:
break l
}
Expand Down
21 changes: 21 additions & 0 deletions 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 <kron@example.com> 1379666165 +0300" +
"committer Artiom <kron@example.com> 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)
}
}

0 comments on commit 54cd7da

Please sign in to comment.