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: fetch before checking status #3832

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

lukemassa
Copy link
Contributor

@lukemassa lukemassa commented Oct 8, 2023

what

Run a fetch (specifically git remote update) before running git status when checking HasDiverged()

why

If you don't pull down any remote refs, there's no point in checking for divergence.

I believe this bug has been present since undiverged was introduced as an apply requirement in #1587. The original implementation of HasDiverged(), unlike warnDiverged() that it was based off, did not run any remote updates (https://github.com/runatlantis/atlantis/pull/1587/files#diff-46caccf1d70c25419bae0a880c70ef586a884d76cb826e1a08e48e11f87c4363R173).

I did what I believed to be the minimal possible change to make this work, there might be tweaks in terms of fetch vs remote update, depth, etc.

tests

I did the following before and after this change

  1. Ran atlantis plan
  2. Updated main
  3. Ran atlantis apply

Before, the apply went through, and the working directory on disk did not show any divergence.

After, the apply was blocked with the message "Default branch must be rebased onto pull request before running apply.", and on disk divergence was shown

references

closes #3254
introduced in #1587

@lukemassa lukemassa requested a review from a team as a code owner October 8, 2023 18:47
@github-actions github-actions bot added the go Pull requests that update Go code label Oct 8, 2023
@jamengual jamengual added bug Something isn't working waiting-on-review Waiting for a review from a maintainer labels Oct 10, 2023
@jamengual
Copy link
Contributor

@GenPage

@finnag
Copy link
Contributor

finnag commented Oct 17, 2023

I don't think this PR works as intended, since it's behind a if !w.CheckoutMerge guard. The HasDiverged function as written is only meaningful if you have checkout set to merge. "undiverged" and checkout strategy "merge" cannot be meaningfully combined. It should maybe be rewritten into 3 choices for what to do if the branches have diverged: fail, ignore, or merge.

Note also: If you have managed to plan, apply is safe even if you update main, the project lock should keep you covered.

@lukemassa
Copy link
Contributor Author

I don't think this PR works as intended, since it's behind a if !w.CheckoutMerge guard. The HasDiverged function as written is only meaningful if you have checkout set to merge. "undiverged" and checkout strategy "merge" cannot be meaningfully combined. It should maybe be rewritten into 3 choices for what to do if the branches have diverged: fail, ignore, or merge.

I'm not sure I follow. To be clear, I'm not attempting to merge here, or really affect the local checkout in any way. The only goal is to fetch remotes, so that the determination of "has diverged" can be made. Without this change, HasDiverged is only checking to see if the constructed branch has diverged from the local copy of main, which it never will.

Note also: If you have managed to plan, apply is safe even if you update main, the project lock should keep you covered.

This may be true but, from my reading of the undiverged setting, this is the situation that is supposed to be blocked if you add that requirement.

From https://www.runatlantis.io/docs/command-requirements.html#meaning-2

undiverged enforces that Atlantis local version of main is up to date with remote so that the state of the source during the apply is identical to that if you were to merge the PR at that time.

This comparison to remote is not currently happening, which my PR attempts to fix.

I don't have any recommendation of what to do from the undiverged state, other than to fail the apply per the documentation.

@jamengual
Copy link
Contributor

interesting video related to the conversation https://www.youtube.com/watch?app=desktop&v=rLDKhjJbg3A

@lukemassa
Copy link
Contributor Author

We discussed this at office hours today and I changed the command to git fetch per recommendation from @GenPage

@GenPage GenPage enabled auto-merge (squash) December 12, 2023 00:26
@GenPage GenPage merged commit 242640b into runatlantis:main Dec 12, 2023
24 checks passed
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* fix: fetch before checking status

* Switch to fetch
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* fix: fetch before checking status

* Switch to fetch
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 waiting-on-review Waiting for a review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undiverged not working for plan or apply
4 participants