Skip to content

fix: Propagate git errors in divergence checks to abort plan#6632

Open
bhavith wants to merge 1 commit into
runatlantis:mainfrom
bhavith:propagate-error
Open

fix: Propagate git errors in divergence checks to abort plan#6632
bhavith wants to merge 1 commit into
runatlantis:mainfrom
bhavith:propagate-error

Conversation

@bhavith

@bhavith bhavith commented Jul 6, 2026

Copy link
Copy Markdown

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

  • I have tested my changes by running our local instance with these changes
  • Added test cases covering these scenarios

@bhavith bhavith changed the title Propagate git errors in divergence checks to abort plan/apply fix: Propagate git errors in divergence checks to abort plan/apply Jul 6, 2026
@bhavith bhavith force-pushed the propagate-error branch from 6fb43fd to 82d3e60 Compare July 6, 2026 19:12
@bhavith bhavith marked this pull request as ready for review July 6, 2026 21:49
Copilot AI review requested due to automatic review settings July 6, 2026 21:49
@dosubot dosubot Bot added bug Something isn't working go Pull requests that update Go code labels Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / HasDivergedFromPullHead to 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

Comment on lines +222 to +225
diverged, err := w.recheckDiverged(logger, p, headRepo, cloneDir)
if err != nil {
return true, err
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea is to return divergence if there is a failure, along with the error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 410 to 414
outputStatusUno, err := statusUnoCmd.CombinedOutput()
if err != nil {
logger.Warn("getting repo status has failed: %s", string(outputStatusUno))
return true
return true, nil
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If git status failed, we dont have to fail the plan. Just responding divergence true is enough.

Comment thread server/events/working_dir.go Outdated
Comment on lines 112 to 117
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)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 336 to 338
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
}

@bhavith bhavith Jul 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea is to fail plan if git mutation failed. Not for all errors.

Comment thread server/events/working_dir_test.go Outdated
Comment thread server/events/working_dir_test.go Outdated
Comment thread server/events/working_dir_test.go Outdated
Comment on lines 355 to 357
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
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea is to fail plan if git update or git fetch have failed. Not for all github actions.

@bhavith bhavith marked this pull request as draft July 6, 2026 21:57
@bhavith bhavith changed the title fix: Propagate git errors in divergence checks to abort plan/apply fix: Propagate git errors in divergence checks to abort plan Jul 6, 2026
@bhavith bhavith force-pushed the propagate-error branch from f120a0a to f536a24 Compare July 6, 2026 22:10
Signed-off-by: bhavith <bhavith.vijayan@cognite.com>
@bhavith bhavith force-pushed the propagate-error branch from f536a24 to 1191492 Compare July 6, 2026 22:17
@bhavith bhavith marked this pull request as ready for review July 6, 2026 22:18
@chenrui333

Copy link
Copy Markdown
Member

please create a bug report with the atlantis config first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants