From 260dd4fc78ad236783d05bb43bdbbc3d47edec2c Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Sun, 8 Nov 2026 21:06:28 +1100 Subject: [PATCH] Warn about corrected branch names only for envs being deployed --- internal/deploy/deploy.go | 9 +++++---- internal/deploy/deploy_test.go | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/deploy/deploy.go b/internal/deploy/deploy.go index 65accc5..cc35f6e 100644 --- a/internal/deploy/deploy.go +++ b/internal/deploy/deploy.go @@ -378,9 +378,6 @@ func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envR skipped[b] = fmt.Errorf("branch %s collides with environment %s, skipped", b, name) } } - if !isExact && s.InvalidBranches == "correct_and_warn" { - log.Printf("warning: branch %s deployed as environment %s", win, name) - } envs[name] = envRef{win, all[win]} } return envs, skipped, nil @@ -413,10 +410,14 @@ func (d *Deployer) deploySource(ctx context.Context, p *srcPlan, modules bool) e } var mu sync.Mutex var wg sync.WaitGroup - for name, ref := range p.envs { + for _, name := range slices.Sorted(maps.Keys(p.envs)) { + ref := p.envs[name] if !full && !p.want[name] { continue } + if _, corrected, _ := s.EnvName(ref.branch); corrected && s.InvalidBranches == "correct_and_warn" { + log.Printf("warning: branch %s deployed as environment %s", ref.branch, name) + } wg.Add(1) go func() { defer wg.Done() diff --git a/internal/deploy/deploy_test.go b/internal/deploy/deploy_test.go index 68c9856..0ec941b 100644 --- a/internal/deploy/deploy_test.go +++ b/internal/deploy/deploy_test.go @@ -888,9 +888,15 @@ func TestNamedDeployPrefixedSources(t *testing.T) { p := &Source{Name: "p", Remote: f.control, Basedir: pbase, Prefix: "p", InvalidBranches: "correct_and_warn"} f.cfg.Sources["p"] = p penv := func(name string) string { return f.deployer().owned(p, filepath.Join(pbase, name)) } + var logs bytes.Buffer + log.SetOutput(&logs) + defer log.SetOutput(os.Stderr) if err := f.deploy(false, "main"); err != nil || f.env("main") == "" { t.Fatalf("deploy main: %v", err) } + if strings.Contains(logs.String(), "benvin/x") { + t.Fatalf("named deploy warned about a branch it did not deploy:\n%s", logs.String()) + } if penv("p_main") != "" { t.Fatal("env name main also deployed branch main of source p as p_main") }