@@ -329,19 +329,11 @@ func loadModelWithContext(ctx context.Context, configDetails *types.ConfigDetail
329329 return nil , errors .New ("No files specified" )
330330 }
331331
332- err := projectName (* configDetails , opts )
332+ err := projectName (configDetails , opts )
333333 if err != nil {
334334 return nil , err
335335 }
336336
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-
345337 return load (ctx , * configDetails , opts , nil )
346338}
347339
@@ -601,10 +593,14 @@ func InvalidProjectNameErr(v string) error {
601593// projectName determines the canonical name to use for the project considering
602594// the loader Options as well as `name` fields in Compose YAML fields (which
603595// 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+
608604 if opts .projectNameImperativelySet {
609605 if NormalizeProjectName (opts .projectName ) != opts .projectName {
610606 return InvalidProjectNameErr (opts .projectName )
0 commit comments