aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-05 11:34:50 +0200
committerGitHub <noreply@github.com>2017-05-05 11:34:50 +0200
commitced875aec7bef9113e1c37b1b811a59e17dbd138 (patch)
tree3cf652b8cfa94e011d4d7b5addfd13945870cda8 /options.go
parente80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff)
parent3713157d189a109bdccdb055200defb17297b6de (diff)
downloadgo-git-ced875aec7bef9113e1c37b1b811a59e17dbd138.tar.gz
Merge pull request #375 from mcuadros/commit
worktree: Commit method implementation
Diffstat (limited to 'options.go')
-rw-r--r--options.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/options.go b/options.go
index 50fba10..977e462 100644
--- a/options.go
+++ b/options.go
@@ -5,6 +5,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/sideband"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
)
@@ -72,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
@@ -251,3 +252,46 @@ type LogOptions struct {
// the default From.
From plumbing.Hash
}
+
+var (
+ ErrMissingAuthor = errors.New("author field is required")
+)
+
+// CommitOptions describes how a commit operation should be performed.
+type CommitOptions struct {
+ // All automatically stage files that have been modified and deleted, but
+ // new files you have not told Git about are not affected.
+ All bool
+ // Author is the author's signature of the commit.
+ Author *object.Signature
+ // Committer is the committer's signature of the commit. If Committer is
+ // nil the Author signature is used.
+ Committer *object.Signature
+ // 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
+}
+
+// Validate validates the fields and sets the default values.
+func (o *CommitOptions) Validate(r *Repository) error {
+ if o.Author == nil {
+ return ErrMissingAuthor
+ }
+
+ if o.Committer == nil {
+ o.Committer = o.Author
+ }
+
+ if len(o.Parents) == 0 {
+ head, err := r.Head()
+ if err != nil && err != plumbing.ErrReferenceNotFound {
+ return err
+ }
+
+ if head != nil {
+ o.Parents = []plumbing.Hash{head.Hash()}
+ }
+ }
+
+ return nil
+}