Skip to content

Commit 0f5225d

Browse files
committed
Ensure that apply data is present in submodules as well
Otherwise calling "project.Module#ApplyNewVersion()" on a submodule would return an empty version.
1 parent ff888f5 commit 0f5225d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

project/project.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func New(config config.Config, manifestFiles []string, options ...projectOption)
175175
moduleRepository := module.Repository
176176
submodules := make([]Module, 0)
177177

178+
// Create apply data for this module and fill the blanks from the default apply data
179+
moduleApply := newApplyFromTemplate(module, defaultApply)
180+
178181
if config.ForceHttpsRepos {
179182
moduleRepository = utils.ConvertGithubGitToHTTPS(module.Repository)
180183
}
@@ -184,6 +187,9 @@ func New(config config.Config, manifestFiles []string, options ...projectOption)
184187
path := getModulePath(repositoryRoot, moduleName, submodule)
185188
name := getMavenCoordinates(path).ArtifactId
186189

190+
// Create apply data for this submodule and fill the blanks from the parent module apply data
191+
submoduleApply := newApplyFromTemplate(submodule, moduleApply)
192+
187193
if name == "" {
188194
name = moduleName
189195
}
@@ -195,6 +201,7 @@ func New(config config.Config, manifestFiles []string, options ...projectOption)
195201
Revision: module.Revision,
196202
Assemblies: submodule.Assemblies,
197203
AssemblyAttachment: submodule.AssemblyAttachment,
204+
apply: submoduleApply,
198205
})
199206
}
200207
}
@@ -206,15 +213,6 @@ func New(config config.Config, manifestFiles []string, options ...projectOption)
206213
name = moduleName
207214
}
208215

209-
moduleApply := Apply{
210-
FromRevision: module.Apply.FromRevision,
211-
NewBranch: module.Apply.NewBranch,
212-
NewVersion: module.Apply.NewVersion,
213-
}
214-
215-
// Merge the module `apply` field with the default apply values.
216-
mergo.Merge(&moduleApply, defaultApply)
217-
218216
newModule := Module{
219217
Name: name,
220218
Path: path,
@@ -261,6 +259,21 @@ func New(config config.Config, manifestFiles []string, options ...projectOption)
261259
return project
262260
}
263261

262+
func newApplyFromTemplate(module manifest.ManifestModule, template Apply) Apply {
263+
newApply := Apply{
264+
FromRevision: module.Apply.FromRevision,
265+
NewBranch: module.Apply.NewBranch,
266+
NewVersion: module.Apply.NewVersion,
267+
}
268+
269+
// Fill in missing Apply attributes from template
270+
if err := mergo.Merge(&newApply, template); err != nil {
271+
logger.Fatal("Couldn't merge apply state: src=%#v dst=%#v", template, newApply)
272+
}
273+
274+
return newApply
275+
}
276+
264277
func applyModuleOverride(c config.Config, modules []Module) []Module {
265278
newModules := make([]Module, 0)
266279

0 commit comments

Comments
 (0)