@@ -329,19 +329,11 @@ func loadModelWithContext(ctx context.Context, configDetails *types.ConfigDetail
329
329
return nil , errors .New ("No files specified" )
330
330
}
331
331
332
- err := projectName (* configDetails , opts )
332
+ err := projectName (configDetails , opts )
333
333
if err != nil {
334
334
return nil , err
335
335
}
336
336
337
- // TODO(milas): this should probably ALWAYS set (overriding any existing)
338
- if _ , ok := configDetails .Environment [consts .ComposeProjectName ]; ! ok && opts .projectName != "" {
339
- if configDetails .Environment == nil {
340
- configDetails .Environment = map [string ]string {}
341
- }
342
- configDetails .Environment [consts .ComposeProjectName ] = opts .projectName
343
- }
344
-
345
337
return load (ctx , * configDetails , opts , nil )
346
338
}
347
339
@@ -601,10 +593,14 @@ func InvalidProjectNameErr(v string) error {
601
593
// projectName determines the canonical name to use for the project considering
602
594
// the loader Options as well as `name` fields in Compose YAML fields (which
603
595
// also support interpolation).
604
- //
605
- // TODO(milas): restructure loading so that we don't need to re-parse the YAML
606
- // here, as it's both wasteful and makes this code error-prone.
607
- func projectName (details types.ConfigDetails , opts * Options ) error {
596
+ func projectName (details * types.ConfigDetails , opts * Options ) error {
597
+ defer func () {
598
+ if details .Environment == nil {
599
+ details .Environment = map [string ]string {}
600
+ }
601
+ details .Environment [consts .ComposeProjectName ] = opts .projectName
602
+ }()
603
+
608
604
if opts .projectNameImperativelySet {
609
605
if NormalizeProjectName (opts .projectName ) != opts .projectName {
610
606
return InvalidProjectNameErr (opts .projectName )
0 commit comments