From 26524f42d8f84e8a5833f1b8d21d082c12d8ec79 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Fri, 5 Apr 2024 22:21:53 +0800 Subject: [PATCH 1/2] execute module replacement in a single command --- environment.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/environment.go b/environment.go index e088367..5b99f8a 100644 --- a/environment.go +++ b/environment.go @@ -144,13 +144,18 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { replaced := make(map[string]string) for _, r := range b.Replacements { log.Printf("[INFO] Replace %s => %s", r.Old.String(), r.New.String()) - cmd := env.newGoModCommand(ctx, "edit", - "-replace", fmt.Sprintf("%s=%s", r.Old.Param(), r.New.Param())) + + replaced[r.Old.String()] = r.New.String() + } + if len(replaced) > 0 { + cmd := env.newGoModCommand(ctx, "edit") + for o, n := range replaced { + cmd.Args = append(cmd.Args, "-replace", fmt.Sprintf("%s=%s", o, n)) + } err := env.runCommand(ctx, cmd) if err != nil { return nil, err } - replaced[r.Old.String()] = r.New.String() } // check for early abort From bd00fc14c575afac3cbdb8e6dd21af2d3c5f7039 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Fri, 5 Apr 2024 22:24:55 +0800 Subject: [PATCH 2/2] remove empty line --- environment.go | 1 - 1 file changed, 1 deletion(-) diff --git a/environment.go b/environment.go index 5b99f8a..38b616c 100644 --- a/environment.go +++ b/environment.go @@ -144,7 +144,6 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { replaced := make(map[string]string) for _, r := range b.Replacements { log.Printf("[INFO] Replace %s => %s", r.Old.String(), r.New.String()) - replaced[r.Old.String()] = r.New.String() } if len(replaced) > 0 {