Don't check for commits ahead by when syncing fork #616
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.
Change
Remove code that checks for 'commits ahead by' in a fork. This is because the HTTP API we use can sync fork even with additional commits - i.e., can perform a non-fast forward merge (provided they don't conflict)
Validation
Manually validated by adding extra commits in the default branch of my fork. Verified that the sync fork code succeeds and pulls the latest upstream commits in my fork.
History
The initial code for handling the sync fork step (added in PR #235) made use of a
this.github.Git.Reference.Updatecall for syncing fork. As the PR description states, this call would fail if a fast-forward update was not possible, meaning the forked repo was ahead of / had additional commits that were not present in upstream. In this case, we would throw aNonFastForwardExceptionguarding against this scenario since we knew theUpdate()call would fail. This exception however, didn't block PR creation in old code since the sync fork step was previously done only during first execution in a retry loop and if it threw a NonFastForwardException, we would still try creating a reference / branch & then a PR. The old code still had flaws in the sense that if the fork was behind way too many commits, the reference creation & PR creation would both fail, but we would never be able to even attempt the sync fork to mitigate it because of some additional commits in fork making us throw aNonFastForwardExceptionWe switched to making a direct HTTP call to the GitHub API for syncing fork in PR #581. The benefit here is that the HTTP API call does not fail if the fork is "ahead of" the upstream. It can successfully sync the fork provided that the additional commits do not conflict with the changes in upstream. If they conflict, it throws a
409error code which is already handled in the code. Also, when switching to the HTTP API, the logic was changed in PR #597 such that we do not attempt to sync fork only during first execution, but we retry the API multiple times as well. A consequence of it, or a regression one may say, is that the old code did allow cases where even if the sync fork was not attempted due toNonFastForwardException, PR creation may still succeed in some cases provided the fork wasn't wayyy too behind. But now since we check sync fork in every execution after PR #597 and every execution would just throw aNonFastForwardException, we never make it to PR creation step. Now, this regression should also be handled in this PR where we just remove theNonFastForwardExceptioncheck, since the HTTP API can sync fork even if it is a non-fast forward updateMicrosoft Reviewers: Open in CodeFlow