aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--options.go13
-rw-r--r--options_test.go35
-rw-r--r--plumbing/object/commit.go4
-rw-r--r--worktree_commit.go4
-rw-r--r--worktree_commit_test.go13
5 files changed, 58 insertions, 11 deletions
diff --git a/options.go b/options.go
index 48c9819..977e462 100644
--- a/options.go
+++ b/options.go
@@ -43,7 +43,7 @@ type CloneOptions struct {
// Limit fetching to the specified number of commits.
Depth int
// RecurseSubmodules after the clone is created, initialize all submodules
- // within, using their defaut settings. This option is ignored if the
+ // within, using their default settings. This option is ignored if the
// cloned repository does not have a worktree.
RecurseSubmodules SubmoduleRescursivity
// Progress is where the human readable information sent by the server is
@@ -73,7 +73,7 @@ func (o *CloneOptions) Validate() error {
type PullOptions struct {
// Name of the remote to be pulled. If empty, uses the default.
RemoteName string
- // Remote branch to clone. If empty, uses HEAD.
+ // Remote branch to clone. If empty, uses HEAD.
ReferenceName plumbing.ReferenceName
// Fetch only ReferenceName if true.
SingleBranch bool
@@ -254,8 +254,7 @@ type LogOptions struct {
}
var (
- ErrMissingAuthor = errors.New("author field is required")
- ErrMissingCommitter = errors.New("committer field is required")
+ ErrMissingAuthor = errors.New("author field is required")
)
// CommitOptions describes how a commit operation should be performed.
@@ -266,10 +265,10 @@ type CommitOptions struct {
// Author is the author's signature of the commit.
Author *object.Signature
// Committer is the committer's signature of the commit. If Committer is
- // equal to nil the Author signature is used.
+ // nil the Author signature is used.
Committer *object.Signature
- // Parents parents commits for the new commit, by default is the hash of
- // HEAD reference.
+ // Parents are the parents commits for the new commit, by default when
+ // len(Parents) is zero, the hash of HEAD reference is used.
Parents []plumbing.Hash
}
diff --git a/options_test.go b/options_test.go
new file mode 100644
index 0000000..5274113
--- /dev/null
+++ b/options_test.go
@@ -0,0 +1,35 @@
+package git
+
+import (
+ . "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git.v4/plumbing/object"
+)
+
+type OptionsSuite struct {
+ BaseSuite
+}
+
+var _ = Suite(&OptionsSuite{})
+
+func (s *OptionsSuite) TestCommitOptionsParentsFromHEAD(c *C) {
+ o := CommitOptions{Author: &object.Signature{}}
+ err := o.Validate(s.Repository)
+ c.Assert(err, IsNil)
+ c.Assert(o.Parents, HasLen, 1)
+}
+
+func (s *OptionsSuite) TestCommitOptionsMissingAuthor(c *C) {
+ o := CommitOptions{}
+ err := o.Validate(s.Repository)
+ c.Assert(err, Equals, ErrMissingAuthor)
+}
+
+func (s *OptionsSuite) TestCommitOptionsCommitter(c *C) {
+ sig := &object.Signature{}
+
+ o := CommitOptions{Author: sig}
+ err := o.Validate(s.Repository)
+ c.Assert(err, IsNil)
+
+ c.Assert(o.Committer, Equals, o.Author)
+}
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index adac4f9..0a20ae6 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -30,9 +30,9 @@ type Commit struct {
Committer Signature
// Message is the commit message, contains arbitrary text.
Message string
- // TreeHash hash of the tree pointed by the commit.
+ // TreeHash is the hash of the root tree of the commit.
TreeHash plumbing.Hash
- // ParentHashes hashes of the parent commits of the commit.
+ // ParentHashes are the hashes of the parent commits of the commit.
ParentHashes []plumbing.Hash
s storer.EncodedObjectStorer
diff --git a/worktree_commit.go b/worktree_commit.go
index 9cefdcf..bec75b2 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -22,7 +22,7 @@ func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error
return plumbing.ZeroHash, err
}
- if opts.All == true {
+ if opts.All {
if err := w.autoAddModifiedAndDeleted(); err != nil {
return plumbing.ZeroHash, err
}
@@ -103,7 +103,7 @@ func (w *Worktree) buildCommitObject(msg string, opts *CommitOptions, tree plumb
}
// commitIndexHelper converts a given index.Index file into multiple git objects
-// reading the blogs from the given filesystem and creating the trees from the
+// reading the blobs from the given filesystem and creating the trees from the
// index structure. The created objects are pushed to a given Storer.
type commitIndexHelper struct {
fs billy.Filesystem
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index f9cf4f3..7e1b93c 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -13,6 +13,18 @@ import (
"gopkg.in/src-d/go-billy.v2/memfs"
)
+func (s *WorktreeSuite) TestCommitInvalidOptions(c *C) {
+ r, err := Init(memory.NewStorage(), memfs.New())
+ c.Assert(err, IsNil)
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ hash, err := w.Commit("", &CommitOptions{})
+ c.Assert(err, Equals, ErrMissingAuthor)
+ c.Assert(hash.IsZero(), Equals, true)
+}
+
func (s *WorktreeSuite) TestCommitInitial(c *C) {
expected := plumbing.NewHash("98c4ac7c29c913f7461eae06e024dc18e80d23a4")
@@ -74,6 +86,7 @@ func (s *WorktreeSuite) TestCommitAll(c *C) {
c.Assert(err, IsNil)
billy.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
+ billy.WriteFile(fs, "foo", []byte("foo"), 0644)
hash, err := w.Commit("foo\n", &CommitOptions{
All: true,