aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-22 00:18:02 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-22 00:18:02 +0200
commitf42d82364c5d159f65a48e720433ad2bc97f0b7f (patch)
tree82623f4163625786f4e8e41028dcd1c7abaf209f /config/config.go
parenta045606fc9c5cbf30b409384cbdad4804f01c61d (diff)
downloadgo-git-f42d82364c5d159f65a48e720433ad2bc97f0b7f.tar.gz
Remote.Fetch multiple RefSpec support
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go38
1 files changed, 35 insertions, 3 deletions
diff --git a/config/config.go b/config/config.go
index b70cebc..4cf5f7c 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,9 +1,20 @@
package config
-import "errors"
+import (
+ "errors"
+ "fmt"
+
+ "gopkg.in/src-d/go-git.v3/clients/common"
+)
+
+const (
+ DefaultRefSpec = "+refs/heads/*:refs/remotes/%s/*"
+)
var (
- ErrRemoteConfigNotFound = errors.New("remote config not found")
+ ErrRemoteConfigNotFound = errors.New("remote config not found")
+ ErrRemoteConfigEmptyURL = errors.New("remote config: empty URL")
+ ErrRemoteConfigEmptyName = errors.New("remote config: empty name")
)
type ConfigStorage interface {
@@ -16,5 +27,26 @@ type ConfigStorage interface {
type RemoteConfig struct {
Name string
URL string
- Fetch RefSpec
+ Fetch []RefSpec
+}
+
+// Validate validate the fields and set the default values
+func (c *RemoteConfig) Validate() error {
+ if c.Name == "" {
+ return ErrRemoteConfigEmptyName
+ }
+
+ if c.URL == "" {
+ return ErrRemoteConfigEmptyURL
+ }
+
+ if _, err := common.NewEndpoint(c.URL); err != nil {
+ return err
+ }
+
+ if len(c.Fetch) == 0 {
+ c.Fetch = []RefSpec{RefSpec(fmt.Sprintf(DefaultRefSpec, c.Name))}
+ }
+
+ return nil
}