From c85155e583d38f2b8ff85a92c78147b77ef334cf Mon Sep 17 00:00:00 2001 From: Paris Morali Date: Thu, 23 Apr 2020 17:07:01 +0100 Subject: [PATCH] Fix: Do not automerge with errors or noop Extra guards have been added to preven automatically merging a branch upstream when automerge is enabled but errors exist or if no commands where executed at all. An example of this bug in action is when you delete a plan and atlantis lock via the UI and then execute atlantis apply No projects are applied but the branch is automerged --- server/events/command_runner.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/events/command_runner.go b/server/events/command_runner.go index c00853475..90d4e1c52 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -273,7 +273,8 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead c.updateCommitStatus(ctx, cmd.Name, pullStatus) - if cmd.Name == models.ApplyCommand && c.automergeEnabled(ctx, projectCmds) { + // Do not automerge if no commands were executed at all, or if there have been errors + if cmd.Name == models.ApplyCommand && c.automergeEnabled(ctx, projectCmds) && len(projectCmds) > 0 && !result.HasErrors() { c.automerge(ctx, pullStatus) } }