blob: b0b01415f19903ce105f218c3c7047179da8b489 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package git
import (
"bytes"
"io"
"strings"
"gopkg.in/src-d/go-git.v3/core"
)
// File represents git file objects.
type File struct {
Name string
io.Reader
Hash core.Hash
}
// Contents returns the contents of a file as a string.
func (f *File) Contents() string {
buf := new(bytes.Buffer)
buf.ReadFrom(f)
return buf.String()
}
// Lines returns a slice of lines from the contents of a file, stripping
// all end of line characters. If the last line is empty (does not end
// in an end of line), it is also stripped.
func (f *File) Lines() []string {
splits := strings.Split(f.Contents(), "\n")
// remove the last line if it is empty
if splits[len(splits)-1] == "" {
return splits[:len(splits)-1]
}
return splits
}
|