Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: safer re-merging with updated upstream #3499

Merged
merged 15 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/events/markdown_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ $$$
LockURL: "lock-url",
RePlanCmd: "atlantis plan -d path -w workspace",
ApplyCmd: "atlantis apply -d path -w workspace",
HasDiverged: true,
MergedAgain: true,
},
Workspace: "workspace",
RepoRelDir: "path",
Expand All @@ -210,7 +210,7 @@ $$$
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d path -w workspace$

:warning: The branch we're merging into is ahead, it is recommended to pull new commits first.
:twisted_rightwards_arrows: Upstream was modified, a new merge was performed.

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down Expand Up @@ -1974,7 +1974,7 @@ $$$
LockURL: "lock-url",
RePlanCmd: "atlantis plan -d path -w workspace",
ApplyCmd: "atlantis apply -d path -w workspace",
HasDiverged: true,
MergedAgain: true,
},
Workspace: "workspace",
RepoRelDir: "path",
Expand All @@ -1992,7 +1992,7 @@ $$$
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d path -w workspace$

:warning: The branch we're merging into is ahead, it is recommended to pull new commits first.
:twisted_rightwards_arrows: Upstream was modified, a new merge was performed.

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
16 changes: 8 additions & 8 deletions server/events/mock_workingdir_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions server/events/mocks/mock_working_dir.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ type PlanSuccess struct {
RePlanCmd string
// ApplyCmd is the command that users should run to apply this plan.
ApplyCmd string
// HasDiverged is true if we're using the checkout merge strategy and the
// branch we're merging into has been updated since we cloned and merged
// it.
HasDiverged bool
// MergedAgain is true if we're using the checkout merge strategy and the
// branch we're merging into had been updated, and we had to merge again
// before planning
MergedAgain bool
}

type PolicySetResult struct {
Expand Down
6 changes: 3 additions & 3 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx command.ProjectContext) (*model
}
defer unlockFn()

p.WorkingDir.SetSafeToReClone()
p.WorkingDir.SetCheckForUpstreamChanges()
// Clone is idempotent so okay to run even if the repo was already cloned.
repoDir, hasDiverged, cloneErr := p.WorkingDir.Clone(ctx.HeadRepo, ctx.Pull, ctx.Workspace)
repoDir, mergedAgain, cloneErr := p.WorkingDir.Clone(ctx.HeadRepo, ctx.Pull, ctx.Workspace)
if cloneErr != nil {
if unlockErr := lockAttempt.UnlockFn(); unlockErr != nil {
ctx.Log.Err("error unlocking state after plan error: %v", unlockErr)
Expand Down Expand Up @@ -576,7 +576,7 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx command.ProjectContext) (*model
TerraformOutput: strings.Join(outputs, "\n"),
RePlanCmd: ctx.RePlanCmd,
ApplyCmd: ctx.ApplyCmd,
HasDiverged: hasDiverged,
MergedAgain: mergedAgain,
}, "", nil
}

Expand Down
5 changes: 0 additions & 5 deletions server/events/templates/diverged.tmpl

This file was deleted.

5 changes: 5 additions & 0 deletions server/events/templates/merged_again.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ define "mergedAgain" -}}
{{ if .MergedAgain }}
:twisted_rightwards_arrows: Upstream was modified, a new merge was performed.
{{ end -}}
{{ end -}}
2 changes: 1 addition & 1 deletion server/events/templates/plan_success_unwrapped.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ This plan was not saved because one or more projects failed and automerge requir
* :repeat: To **plan** this project again, comment:
* `{{ .RePlanCmd }}`
{{ end -}}
{{ template "diverged" . }}
{{ template "mergedAgain" . }}
{{ end -}}
2 changes: 1 addition & 1 deletion server/events/templates/plan_success_wrapped.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ This plan was not saved because one or more projects failed and automerge requir
{{ end -}}
</details>
{{ .PlanSummary -}}
{{ template "diverged" . -}}
{{ template "mergedAgain" . -}}
{{ end -}}
Loading