fix: Propagate git errors in divergence checks to abort plan#6632
fix: Propagate git errors in divergence checks to abort plan#6632bhavith wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Atlantis’ working directory divergence checks to return and propagate git command errors so plan/apply can fail loudly instead of silently assuming divergence and potentially planning against stale code.
Changes:
- Change
WorkingDir.HasDiverged/HasDivergedFromPullHeadto return(bool, error)and propagate errors from divergence checks. - Update callers and mocks to handle the new return signature.
- Update unit tests to accommodate the signature change.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| server/events/working_dir.go | Changes divergence APIs to return errors and updates merge recheck logic. |
| server/events/working_dir_test.go | Updates divergence tests for new (bool, error) signature. |
| server/events/undiverged_project_impact_test.go | Updates mocked divergence expectations for new signature. |
| server/events/project_command_runner_test.go | Updates mocked divergence expectations for new signature. |
| server/events/mocks/mock_working_dir.go | Regenerates/updates mock methods for new signature. |
| server/events/mock_workingdir_test.go | Updates test mock implementation for new signature. |
| server/events/command_requirement_handler.go | Updates undiverged requirement divergence plumbing for new signature. |
| server/events/command_requirement_handler_test.go | Updates mocked divergence expectations for new signature. |
Files not reviewed (2)
- server/events/mock_workingdir_test.go: Generated file
- server/events/mocks/mock_working_dir.go: Generated file
| diverged, err := w.recheckDiverged(logger, p, headRepo, cloneDir) | ||
| if err != nil { | ||
| return true, err | ||
| } |
There was a problem hiding this comment.
Idea is to return divergence if there is a failure, along with the error.
| outputStatusUno, err := statusUnoCmd.CombinedOutput() | ||
| if err != nil { | ||
| logger.Warn("getting repo status has failed: %s", string(outputStatusUno)) | ||
| return true | ||
| return true, nil | ||
| } |
There was a problem hiding this comment.
If git status failed, we dont have to fail the plan. Just responding divergence true is enough.
| if err != nil { | ||
| ctx.Log.Warn("evaluating undiverged requirement has failed, falling back to full divergence check: %s", err) | ||
| diverged = a.hasDiverged(repoDir, ctx, cmd, nil) | ||
| // Here it doesn't matter if diverged check has errored. If `true` is returned, | ||
| // diverged path will be followed which will ask the user to rebase | ||
| diverged, _ = a.hasDiverged(repoDir, ctx, cmd, nil) | ||
| } |
There was a problem hiding this comment.
That is fine. This change is relevant for MergeableRequirement. For UnDivergedRequirement, a failure will return divergence and then the user has to rebase the branch.
| if len(autoplanWhenModified) > 0 { | ||
| return w.hasDivergedForPatterns(logger, cloneDir, projectPath, autoplanWhenModified, pullRequest, w.getDivergedFiles) | ||
| return w.hasDivergedForPatterns(logger, cloneDir, projectPath, autoplanWhenModified, pullRequest, w.getDivergedFiles), nil | ||
| } |
There was a problem hiding this comment.
Idea is to fail plan if git mutation failed. Not for all errors.
| if len(autoplanWhenModified) > 0 { | ||
| return w.hasDivergedForPatterns(logger, cloneDir, projectPath, autoplanWhenModified, pullRequest, w.getDivergedFilesFromPullHead) | ||
| return w.hasDivergedForPatterns(logger, cloneDir, projectPath, autoplanWhenModified, pullRequest, w.getDivergedFilesFromPullHead), nil | ||
| } |
There was a problem hiding this comment.
Idea is to fail plan if git update or git fetch have failed. Not for all github actions.
Signed-off-by: bhavith <bhavith.vijayan@cognite.com>
|
please create a bug report with the atlantis config first. |
what
Propagate errors from hasDiverged and recheckDiverged so that if they fail, the plan is also marked as failed.
why
Currently if there are errors while checking divergence or updating remote branch, divergence is assumed. The error itself is not returned and hence hidden. In such scenarios, fixing divergence updates local repo with outdated remote and that causes stale plan which goes unnoticed.
With this change if the checks fail, the plan is also failed to ensure the user is aware.
tests