aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-15 21:43:33 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-15 21:43:33 +0200
commited2e3b299e03e4bfd4c37bf5232e9fde05c0600d (patch)
treea4ecca997e4528b643758ddaa1dedfa4546369cd /options.go
parent4c6e65190f48f0a7558718d239ffb23ee59580ac (diff)
downloadgo-git-ed2e3b299e03e4bfd4c37bf5232e9fde05c0600d.tar.gz
Repository.Pull, PoC
Diffstat (limited to 'options.go')
-rw-r--r--options.go52
1 files changed, 51 insertions, 1 deletions
diff --git a/options.go b/options.go
index 2aebbc7..0c1fefb 100644
--- a/options.go
+++ b/options.go
@@ -1,6 +1,8 @@
package git
import (
+ "errors"
+
"gopkg.in/src-d/go-git.v3/clients/common"
"gopkg.in/src-d/go-git.v4/core"
)
@@ -10,6 +12,11 @@ const (
DefaultRemoteName = "origin"
)
+var (
+ ErrMissingURL = errors.New("URL field is required")
+ ErrMissingReferences = errors.New("references cannot be empty")
+)
+
// RepositoryCloneOptions describe how a clone should be perform
type RepositoryCloneOptions struct {
// The (possibly remote) repository URL to clone from
@@ -26,7 +33,12 @@ type RepositoryCloneOptions struct {
Depth int
}
-func (o *RepositoryCloneOptions) Default() {
+// Validate validate the fields and set the default values
+func (o *RepositoryCloneOptions) Validate() error {
+ if o.URL == "" {
+ return ErrMissingURL
+ }
+
if o.RemoteName == "" {
o.RemoteName = DefaultRemoteName
}
@@ -34,12 +46,50 @@ func (o *RepositoryCloneOptions) Default() {
if o.ReferenceName == "" {
o.ReferenceName = core.HEAD
}
+
+ return nil
+}
+
+// RepositoryPullOptions describe how a pull should be perform
+type RepositoryPullOptions struct {
+ // Name of the remote to be pulled
+ RemoteName string
+ // Remote branch to clone
+ ReferenceName core.ReferenceName
+ // Fetch only ReferenceName if true
+ SingleBranch bool
+ // Limit fetching to the specified number of commits
+ Depth int
+}
+
+// Validate validate the fields and set the default values
+func (o *RepositoryPullOptions) Validate() error {
+ if o.RemoteName == "" {
+ o.RemoteName = DefaultRemoteName
+ }
+
+ if o.ReferenceName == "" {
+ o.ReferenceName = core.HEAD
+ }
+
+ return nil
}
// RemoteFetchOptions describe how a fetch should be perform
type RemoteFetchOptions struct {
// Remote branchs to fetch
References []*core.Reference
+ // Local references present on the local storage
+ LocalReferences []*core.Reference
// Limit fetching to the specified number of commits
Depth int
}
+
+// Validate validate the fields and set the default values
+func (o *RemoteFetchOptions) Validate() error {
+ if len(o.References) == 0 {
+ return ErrMissingReferences
+ }
+
+ return nil
+}