fix: avoid resetting fetch head when doing branch fetch unshallow #4577
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When doing merge strategy with shallow clones, git will set FETCH_HEAD to base branch when doing unshallow. This fetches another time to reset it back, as we depend on the value later.
what
When using
merge
strategy with acheckout-depth
and the shallow branch can't find a common base with the base branch, a full branch must be fetched with--unshallow
. This PR does another fetch from the feature branch after doing this, to keep theFETCH_HEAD
as expected for future operations.why
When doing
merge
strategy with shallow clones, git will setFETCH_HEAD
to base branch when doing unshallow.FETCH_HEAD
is later used as the ref when doing a merge to base branch, effectively merging it with itself. This in turn causes Atlantis to plan/apply against the base branch and presenting "no changes", even when there should be changes.tests
We have been running a fork with this fix for a few month, using a
merge
strategy with acheckout-depth
value that triggers a full clone relatively often. We have not experienced plans against the base branch since this fix, while we experienced them quite often before.references
While the original issue seems to be referring to a different situation, there is as issue comment describing this situation. The bug being fixed would also present errors like the ones in the issue, though I don't think this PR fixes that specific issue.