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

Commit 3713157

Browse files
committed
worktree: Commit, tests improvements
1 parent b8b61e7 commit 3713157

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

options.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type CloneOptions struct {
4343
// Limit fetching to the specified number of commits.
4444
Depth int
4545
// RecurseSubmodules after the clone is created, initialize all submodules
46-
// within, using their defaut settings. This option is ignored if the
46+
// within, using their default settings. This option is ignored if the
4747
// cloned repository does not have a worktree.
4848
RecurseSubmodules SubmoduleRescursivity
4949
// Progress is where the human readable information sent by the server is
@@ -73,7 +73,7 @@ func (o *CloneOptions) Validate() error {
7373
type PullOptions struct {
7474
// Name of the remote to be pulled. If empty, uses the default.
7575
RemoteName string
76-
// Remote branch to clone. If empty, uses HEAD.
76+
// Remote branch to clone. If empty, uses HEAD.
7777
ReferenceName plumbing.ReferenceName
7878
// Fetch only ReferenceName if true.
7979
SingleBranch bool
@@ -254,8 +254,7 @@ type LogOptions struct {
254254
}
255255

256256
var (
257-
ErrMissingAuthor = errors.New("author field is required")
258-
ErrMissingCommitter = errors.New("committer field is required")
257+
ErrMissingAuthor = errors.New("author field is required")
259258
)
260259

261260
// CommitOptions describes how a commit operation should be performed.
@@ -266,10 +265,10 @@ type CommitOptions struct {
266265
// Author is the author's signature of the commit.
267266
Author *object.Signature
268267
// Committer is the committer's signature of the commit. If Committer is
269-
// equal to nil the Author signature is used.
268+
// nil the Author signature is used.
270269
Committer *object.Signature
271-
// Parents parents commits for the new commit, by default is the hash of
272-
// HEAD reference.
270+
// Parents are the parents commits for the new commit, by default when
271+
// len(Parents) is zero, the hash of HEAD reference is used.
273272
Parents []plumbing.Hash
274273
}
275274

options_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package git
2+
3+
import (
4+
. "gopkg.in/check.v1"
5+
"gopkg.in/src-d/go-git.v4/plumbing/object"
6+
)
7+
8+
type OptionsSuite struct {
9+
BaseSuite
10+
}
11+
12+
var _ = Suite(&OptionsSuite{})
13+
14+
func (s *OptionsSuite) TestCommitOptionsParentsFromHEAD(c *C) {
15+
o := CommitOptions{Author: &object.Signature{}}
16+
err := o.Validate(s.Repository)
17+
c.Assert(err, IsNil)
18+
c.Assert(o.Parents, HasLen, 1)
19+
}
20+
21+
func (s *OptionsSuite) TestCommitOptionsMissingAuthor(c *C) {
22+
o := CommitOptions{}
23+
err := o.Validate(s.Repository)
24+
c.Assert(err, Equals, ErrMissingAuthor)
25+
}
26+
27+
func (s *OptionsSuite) TestCommitOptionsCommitter(c *C) {
28+
sig := &object.Signature{}
29+
30+
o := CommitOptions{Author: sig}
31+
err := o.Validate(s.Repository)
32+
c.Assert(err, IsNil)
33+
34+
c.Assert(o.Committer, Equals, o.Author)
35+
}

plumbing/object/commit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ type Commit struct {
3030
Committer Signature
3131
// Message is the commit message, contains arbitrary text.
3232
Message string
33-
// TreeHash hash of the tree pointed by the commit.
33+
// TreeHash is the hash of the root tree of the commit.
3434
TreeHash plumbing.Hash
35-
// ParentHashes hashes of the parent commits of the commit.
35+
// ParentHashes are the hashes of the parent commits of the commit.
3636
ParentHashes []plumbing.Hash
3737

3838
s storer.EncodedObjectStorer

worktree_commit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error
2222
return plumbing.ZeroHash, err
2323
}
2424

25-
if opts.All == true {
25+
if opts.All {
2626
if err := w.autoAddModifiedAndDeleted(); err != nil {
2727
return plumbing.ZeroHash, err
2828
}
@@ -103,7 +103,7 @@ func (w *Worktree) buildCommitObject(msg string, opts *CommitOptions, tree plumb
103103
}
104104

105105
// commitIndexHelper converts a given index.Index file into multiple git objects
106-
// reading the blogs from the given filesystem and creating the trees from the
106+
// reading the blobs from the given filesystem and creating the trees from the
107107
// index structure. The created objects are pushed to a given Storer.
108108
type commitIndexHelper struct {
109109
fs billy.Filesystem

worktree_commit_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ import (
1313
"gopkg.in/src-d/go-billy.v2/memfs"
1414
)
1515

16+
func (s *WorktreeSuite) TestCommitInvalidOptions(c *C) {
17+
r, err := Init(memory.NewStorage(), memfs.New())
18+
c.Assert(err, IsNil)
19+
20+
w, err := r.Worktree()
21+
c.Assert(err, IsNil)
22+
23+
hash, err := w.Commit("", &CommitOptions{})
24+
c.Assert(err, Equals, ErrMissingAuthor)
25+
c.Assert(hash.IsZero(), Equals, true)
26+
}
27+
1628
func (s *WorktreeSuite) TestCommitInitial(c *C) {
1729
expected := plumbing.NewHash("98c4ac7c29c913f7461eae06e024dc18e80d23a4")
1830

@@ -74,6 +86,7 @@ func (s *WorktreeSuite) TestCommitAll(c *C) {
7486
c.Assert(err, IsNil)
7587

7688
billy.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
89+
billy.WriteFile(fs, "foo", []byte("foo"), 0644)
7790

7891
hash, err := w.Commit("foo\n", &CommitOptions{
7992
All: true,

0 commit comments

Comments
 (0)