fix(dev-infra): incorrect base revision for merge script autosquash (#37138)
As mentioned in the previous commit, the autosquash strategy has not been used in the components repo, so we could easily regress. After thorough manual testing of the autosquash strategy again, now that the merge script will be moved to framework, it came to mind that there is a bug with the base revision in the autosquash merge strategy. The problem is that the base revision of a given PR is relying on the amount of commits in a PR. This is prone to error because the amount of commits could easily change in the autosquash merge strategy, because fixup or squash commits will be collapsed. Basically invalidating the base revision. To fix this, we fixate the base revision by determining the actual SHA. This one is guaranteed to not change after the autosquash rebase. The current merge script in framework fixates the revision by creating a separate branch, but there is no benefit in that, compared to just using an explicit SHA that doesn't need to be cleaned up.. PR Close #37138
This commit is contained in:
parent
e19930e70d
commit
c2c14c2a1f
|
@ -34,10 +34,16 @@ export class AutosquashMergeStrategy extends MergeStrategy {
|
||||||
return PullRequestFailure.unsatisfiedBaseSha();
|
return PullRequestFailure.unsatisfiedBaseSha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SHA for the first commit the pull request is based on. Usually we would able
|
||||||
|
// to just rely on the base revision provided by `getPullRequestBaseRevision`, but
|
||||||
|
// the revision would rely on the amount of commits in a pull request. This is not
|
||||||
|
// reliable as we rebase the PR with autosquash where the amount of commits could
|
||||||
|
// change. We work around this by parsing the base revision so that we have a fixated
|
||||||
|
// SHA before the autosquash rebase is performed.
|
||||||
|
const baseSha =
|
||||||
|
this.git.run(['rev-parse', this.getPullRequestBaseRevision(pullRequest)]).stdout.trim();
|
||||||
// Git revision range that matches the pull request commits.
|
// Git revision range that matches the pull request commits.
|
||||||
const revisionRange = this.getPullRequestRevisionRange(pullRequest);
|
const revisionRange = `${baseSha}..${TEMP_PR_HEAD_BRANCH}`;
|
||||||
// Git revision for the first commit the pull request is based on.
|
|
||||||
const baseRevision = this.getPullRequestBaseRevision(pullRequest);
|
|
||||||
|
|
||||||
// We always rebase the pull request so that fixup or squash commits are automatically
|
// We always rebase the pull request so that fixup or squash commits are automatically
|
||||||
// collapsed. Git's autosquash functionality does only work in interactive rebases, so
|
// collapsed. Git's autosquash functionality does only work in interactive rebases, so
|
||||||
|
@ -49,7 +55,7 @@ export class AutosquashMergeStrategy extends MergeStrategy {
|
||||||
const rebaseEnv =
|
const rebaseEnv =
|
||||||
needsCommitMessageFixup ? undefined : {...process.env, GIT_SEQUENCE_EDITOR: 'true'};
|
needsCommitMessageFixup ? undefined : {...process.env, GIT_SEQUENCE_EDITOR: 'true'};
|
||||||
this.git.run(
|
this.git.run(
|
||||||
['rebase', '--interactive', '--autosquash', baseRevision, TEMP_PR_HEAD_BRANCH],
|
['rebase', '--interactive', '--autosquash', baseSha, TEMP_PR_HEAD_BRANCH],
|
||||||
{stdio: 'inherit', env: rebaseEnv});
|
{stdio: 'inherit', env: rebaseEnv});
|
||||||
|
|
||||||
// Update pull requests commits to reference the pull request. This matches what
|
// Update pull requests commits to reference the pull request. This matches what
|
||||||
|
|
Loading…
Reference in New Issue