diff options
author | Santiago M. Mola <santi@mola.io> | 2017-07-24 10:51:01 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-08-01 13:01:54 +0200 |
commit | 9488c59834f6a2591910b7b360721cec2c16c548 (patch) | |
tree | fea051f6cf08a62aad12e32b2240aa837be22628 /config/config.go | |
parent | 7b08a3005480a50f0f4290aff8f3702085d5e30d (diff) | |
download | go-git-9488c59834f6a2591910b7b360721cec2c16c548.tar.gz |
config: multiple values in RemoteConfig (URLs and Fetch)
* Change `URL string` to `URL []string` in `RemoteConfig`, since
git allows multiple URLs per remote. See:
http://marc.info/?l=git&m=116231242118202&w=2
* Fix marshalling of multiple fetch refspecs.
Diffstat (limited to 'config/config.go')
-rw-r--r-- | config/config.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/config/config.go b/config/config.go index bcea63e..1f3cd77 100644 --- a/config/config.go +++ b/config/config.go @@ -187,8 +187,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 +204,7 @@ func (c *RemoteConfig) Validate() error { return ErrRemoteConfigEmptyName } - if c.URL == "" { + if len(c.URLs) == 0 { return ErrRemoteConfigEmptyURL } @@ -233,8 +234,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 +252,14 @@ func (c *RemoteConfig) marshal() *format.Subsection { } c.raw.Name = c.Name - c.raw.SetOption(urlKey, c.URL) + c.raw.RemoveOption(urlKey) + for _, url := range c.URLs { + c.raw.AddOption(urlKey, url) + } + + c.raw.RemoveOption(fetchKey) for _, rs := range c.Fetch { - c.raw.SetOption(fetchKey, rs.String()) + c.raw.AddOption(fetchKey, rs.String()) } return c.raw |