From 7a3b2b34c96818590f09b8b85ec62907ebea355c Mon Sep 17 00:00:00 2001 From: Matt Spaulding Date: Fri, 29 Sep 2017 15:36:59 -0700 Subject: [PATCH] Add recursive submodule setting for Git repositories --- cfg/config.go | 20 ++++++++++++++++++-- cfg/lock.go | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index ae01039a..8ccbce8d 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -377,6 +377,7 @@ type Dependency struct { Subpackages []string `yaml:"subpackages,omitempty"` Arch []string `yaml:"arch,omitempty"` Os []string `yaml:"os,omitempty"` + Recursive bool `yaml:"recursive,omitempty"` } // A transitive representation of a dependency for importing and exploting to yaml. @@ -389,6 +390,7 @@ type dep struct { Subpackages []string `yaml:"subpackages,omitempty"` Arch []string `yaml:"arch,omitempty"` Os []string `yaml:"os,omitempty"` + Recursive bool `yaml:"recursive,omitempty"` } // DependencyFromLock converts a Lock to a Dependency @@ -401,6 +403,7 @@ func DependencyFromLock(lock *Lock) *Dependency { Subpackages: lock.Subpackages, Arch: lock.Arch, Os: lock.Os, + Recursive: lock.Recursive, } } @@ -418,6 +421,7 @@ func (d *Dependency) UnmarshalYAML(unmarshal func(interface{}) error) error { d.Subpackages = newDep.Subpackages d.Arch = newDep.Arch d.Os = newDep.Os + d.Recursive = newDep.Recursive if d.Reference == "" && newDep.Ref != "" { d.Reference = newDep.Ref @@ -455,6 +459,7 @@ func (d *Dependency) MarshalYAML() (interface{}, error) { Subpackages: d.Subpackages, Arch: d.Arch, Os: d.Os, + Recursive: d.Recursive, } return newDep, nil @@ -511,7 +516,12 @@ func (d *Dependency) GetRepo(dest string) (vcs.Repo, error) { if len(VcsType) > 0 && VcsType != "None" { switch vcs.Type(VcsType) { case vcs.Git: - return vcs.NewGitRepo(remote, dest) + r, err := vcs.NewGitRepo(remote, dest) + if err != nil { + return nil, err + } + r.SetRecursive(d.Recursive) + return r, nil case vcs.Svn: return vcs.NewSvnRepo(remote, dest) case vcs.Hg: @@ -524,7 +534,12 @@ func (d *Dependency) GetRepo(dest string) (vcs.Repo, error) { } // When no type set we try to autodetect. - return vcs.NewRepo(remote, dest) + r, err := vcs.NewRepo(remote, dest) + if err != nil { + return nil, err + } + r.SetRecursive(d.Recursive) + return r, nil } // Clone creates a clone of a Dependency @@ -538,6 +553,7 @@ func (d *Dependency) Clone() *Dependency { Subpackages: d.Subpackages, Arch: d.Arch, Os: d.Os, + Recursive: d.Recursive, } } diff --git a/cfg/lock.go b/cfg/lock.go index c03ac417..ee1c8468 100644 --- a/cfg/lock.go +++ b/cfg/lock.go @@ -162,6 +162,7 @@ type Lock struct { Subpackages []string `yaml:"subpackages,omitempty"` Arch []string `yaml:"arch,omitempty"` Os []string `yaml:"os,omitempty"` + Recursive bool `yaml:"recursive:omitempty"` } // Clone creates a clone of a Lock. @@ -174,6 +175,7 @@ func (l *Lock) Clone() *Lock { Subpackages: l.Subpackages, Arch: l.Arch, Os: l.Os, + Recursive: l.Recursive, } } @@ -187,6 +189,7 @@ func LockFromDependency(dep *Dependency) *Lock { Subpackages: dep.Subpackages, Arch: dep.Arch, Os: dep.Os, + Recursive: dep.Recursive, } }