aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
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
}