aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-08-02 08:12:44 +0200
committerGitHub <noreply@github.com>2017-08-02 08:12:44 +0200
commit9befb514d83e22268d00ab2c0fdd797b3742f0e9 (patch)
tree923a78009cce4531912b92e1b756a6a8f3ee6d32 /config/config.go
parent91cdedae7faffca0a707fa47780efafe157ba47c (diff)
parente5c6fa237776870483cbe227d7f7ea943f35cb12 (diff)
downloadgo-git-9befb514d83e22268d00ab2c0fdd797b3742f0e9.tar.gz
Merge pull request #501 from smola/config-multiple-urls
config: multiple values in RemoteConfig (URLs and Fetch)
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go51
1 files changed, 39 insertions, 12 deletions
diff --git a/config/config.go b/config/config.go
index bcea63e..cb10738 100644
--- a/config/config.go
+++ b/config/config.go
@@ -159,13 +159,22 @@ func (c *Config) marshalCore() {
func (c *Config) marshalRemotes() {
s := c.Raw.Section(remoteSection)
- s.Subsections = make(format.Subsections, len(c.Remotes))
+ newSubsections := make(format.Subsections, 0, len(c.Remotes))
+ added := make(map[string]bool)
+ for _, subsection := range s.Subsections {
+ if remote, ok := c.Remotes[subsection.Name]; ok {
+ newSubsections = append(newSubsections, remote.marshal())
+ added[subsection.Name] = true
+ }
+ }
- var i int
- for _, r := range c.Remotes {
- s.Subsections[i] = r.marshal()
- i++
+ for name, remote := range c.Remotes {
+ if !added[name] {
+ newSubsections = append(newSubsections, remote.marshal())
+ }
}
+
+ s.Subsections = newSubsections
}
func (c *Config) marshalSubmodules() {
@@ -187,8 +196,9 @@ func (c *Config) marshalSubmodules() {
type RemoteConfig struct {
// Name of the remote
Name string
- // URL the URL of a remote repository
- URL string
+ // URLs the URLs of a remote repository. It must be non-empty. Fetch will
+ // always use the first URL, while push will use all of them.
+ URLs []string
// Fetch the default set of "refspec" for fetch operation
Fetch []RefSpec
@@ -203,7 +213,7 @@ func (c *RemoteConfig) Validate() error {
return ErrRemoteConfigEmptyName
}
- if c.URL == "" {
+ if len(c.URLs) == 0 {
return ErrRemoteConfigEmptyURL
}
@@ -233,8 +243,13 @@ func (c *RemoteConfig) unmarshal(s *format.Subsection) error {
fetch = append(fetch, rs)
}
+ var urls []string
+ for _, f := range c.raw.Options.GetAll(urlKey) {
+ urls = append(urls, f)
+ }
+
c.Name = c.raw.Name
- c.URL = c.raw.Option(urlKey)
+ c.URLs = urls
c.Fetch = fetch
return nil
@@ -246,9 +261,21 @@ func (c *RemoteConfig) marshal() *format.Subsection {
}
c.raw.Name = c.Name
- c.raw.SetOption(urlKey, c.URL)
- for _, rs := range c.Fetch {
- c.raw.SetOption(fetchKey, rs.String())
+ if len(c.URLs) == 0 {
+ c.raw.RemoveOption(urlKey)
+ } else {
+ c.raw.SetOption(urlKey, c.URLs...)
+ }
+
+ if len(c.Fetch) == 0 {
+ c.raw.RemoveOption(fetchKey)
+ } else {
+ var values []string
+ for _, rs := range c.Fetch {
+ values = append(values, rs.String())
+ }
+
+ c.raw.SetOption(fetchKey, values...)
}
return c.raw