aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:45:28 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:45:28 +0200
commit40fa5882a2c73f8c075403b7ec85870f04deda07 (patch)
tree97a7708e159721f92d643ceb802ee18143d78191 /options.go
parentff18ce3751ad80cfd0297845872ba1d796c36ca5 (diff)
downloadgo-git-40fa5882a2c73f8c075403b7ec85870f04deda07.tar.gz
worktree: Commit method implementation
Diffstat (limited to 'options.go')
-rw-r--r--options.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/options.go b/options.go
index 50fba10..48c9819 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"
)
@@ -42,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 default settings. This option is ignored if the
+ // within, using their defaut 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
@@ -251,3 +252,47 @@ type LogOptions struct {
// the default From.
From plumbing.Hash
}
+
+var (
+ ErrMissingAuthor = errors.New("author field is required")
+ ErrMissingCommitter = errors.New("committer 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
+ // equal to 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 []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
+}