Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit a35adcf

Browse files
committed
tags tests, Tag.String and Commit.String
1 parent 114c839 commit a35adcf

9 files changed

+155
-151
lines changed

commit.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"sort"
9+
"strings"
910

1011
"gopkg.in/src-d/go-git.v4/core"
1112
)
@@ -184,11 +185,25 @@ func (b *Commit) Encode(o core.Object) error {
184185

185186
func (c *Commit) String() string {
186187
return fmt.Sprintf(
187-
"%s %s\nAuthor: %s\nDate: %s\n",
188-
core.CommitObject, c.Hash, c.Author.String(), c.Author.When,
188+
"%s %s\nAuthor: %s\nDate: %s\n\n%s\n",
189+
core.CommitObject, c.Hash, c.Author.String(),
190+
c.Author.When.Format(DateFormat), indent(c.Message),
189191
)
190192
}
191193

194+
func indent(t string) string {
195+
var output []string
196+
for _, line := range strings.Split(t, "\n") {
197+
if len(line) != 0 {
198+
line = " " + line
199+
}
200+
201+
output = append(output, line)
202+
}
203+
204+
return strings.Join(output, "\n")
205+
}
206+
192207
// CommitIter provides an iterator for a set of commits.
193208
type CommitIter struct {
194209
core.ObjectIter

commit_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,33 @@ func (s *SuiteCommit) TestString(c *C) {
121121
c.Assert(s.Commit.String(), Equals, ""+
122122
"commit 1669dce138d9b841a518c64b10914d88f5e488ea\n"+
123123
"Author: Máximo Cuadros Ortiz <[email protected]>\n"+
124-
"Date: 2015-03-31 13:48:14 +0200 +0200\n",
124+
"Date: Tue Mar 31 13:48:14 2015 +0200\n"+
125+
"\n"+
126+
" Merge branch 'master' of github.com:tyba/git-fixture\n"+
127+
"\n",
125128
)
126129
}
127130

131+
func (s *SuiteCommit) TestStringMultiLine(c *C) {
132+
hash := core.NewHash("e7d896db87294e33ca3202e536d4d9bb16023db3")
133+
134+
commit, err := s.Repositories["https://github.com/src-d/go-git.git"].Commit(hash)
135+
c.Assert(err, IsNil)
136+
137+
c.Assert(commit.String(), Equals, ""+
138+
"commit e7d896db87294e33ca3202e536d4d9bb16023db3\n"+
139+
"Author: Alberto Cortés <[email protected]>\n"+
140+
"Date: Wed Jan 27 11:13:49 2016 +0100\n"+
141+
"\n"+
142+
" fix zlib invalid header error\n"+
143+
"\n"+
144+
" The return value of reads to the packfile were being ignored, so zlib\n"+
145+
" was getting invalid data on it read buffers.\n"+
146+
"\n",
147+
)
148+
149+
}
150+
128151
func (s *SuiteCommit) TestCommitIterNext(c *C) {
129152
i := s.Commit.Parents()
130153

common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ func checkClose(c io.Closer, err *error) {
5151
*err = cerr
5252
}
5353
}
54+
55+
const DateFormat = "Mon Jan 02 15:04:05 2006 -0700"
Binary file not shown.
Binary file not shown.

fixtures/fixtures.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ var fixtures = Fixtures{{
4747
PackfileHash: core.NewHash("3559b3b47e695b33b0913237a4df3357e739831c"),
4848
DotGitHash: core.NewHash("174be6bd4292c18160542ae6dc6704b877b8a01a"),
4949
ObjectsCount: 2133,
50+
}, {
51+
Tags: []string{"packfile", "tags"},
52+
URL: "https://github.com/git-fixtures/tags.git",
53+
Head: core.NewHash("f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),
54+
PackfileHash: core.NewHash("b68617dd8637fe6409d9842825a843a1d9a6e484"),
5055
}, {
5156
Tags: []string{"packfile"},
5257
URL: "https://github.com/spinnaker/spinnaker.git",

objects_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
. "gopkg.in/check.v1"
1010
)
1111

12-
var fixturesURL = []packedFixture{
13-
{"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"},
14-
}
15-
1612
type ObjectsSuite struct {
1713
BaseSuite
1814
}

tag.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,25 @@ func (t *Tag) Encode(o core.Object) error {
113113
return err
114114
}
115115
defer checkClose(w, &err)
116+
116117
if _, err = fmt.Fprintf(w,
117118
"object %s\ntype %s\ntag %s\ntagger ",
118119
t.Target.String(), t.TargetType.Bytes(), t.Name); err != nil {
119120
return err
120121
}
122+
121123
if err = t.Tagger.Encode(w); err != nil {
122124
return err
123125
}
126+
124127
if _, err = fmt.Fprint(w, "\n\n"); err != nil {
125128
return err
126129
}
130+
127131
if _, err = fmt.Fprint(w, t.Message); err != nil {
128132
return err
129133
}
134+
130135
return err
131136
}
132137

@@ -143,7 +148,6 @@ func (t *Tag) Commit() (*Commit, error) {
143148
// object the tree of that commit will be returned. If the tag does not point
144149
// to a commit or tree object ErrUnsupportedObject will be returned.
145150
func (t *Tag) Tree() (*Tree, error) {
146-
// TODO: If the tag is of type commit, follow the commit to its tree?
147151
switch t.TargetType {
148152
case core.CommitObject:
149153
commit, err := t.r.Commit(t.Target)
@@ -175,9 +179,11 @@ func (t *Tag) Object() (Object, error) {
175179
// String returns the meta information contained in the tag as a formatted
176180
// string.
177181
func (t *Tag) String() string {
182+
obj, _ := t.Object()
178183
return fmt.Sprintf(
179-
"%s %s\nObject: %s\nType: %s\nTag: %s\nTagger: %s\nDate: %s\n",
180-
core.TagObject, t.Hash, t.Target, t.TargetType, t.Name, t.Tagger.String(), t.Tagger.When,
184+
"%s %s\nTagger: %s\nDate: %s\n\n%s\n%s",
185+
core.TagObject, t.Name, t.Tagger.String(), t.Tagger.When.Format(DateFormat),
186+
t.Message, obj,
181187
)
182188
}
183189

tag_test.go

Lines changed: 98 additions & 141 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)