fix(dev-infra): merge script autosquash should be interactive (#37138)
The components repo does not use the autosquash merge strategy, so recent changes to that seem to broke the autosquash strategy. Since we don't run the rebase in interactive mode, the `--autosquash` flag has no effect. This is by design in Git. We can make it work by setting the git sequence editor to `true` so that the rebase seems like an interactive one to Git, while it isn't one for the user. This matches conceptually with the merge script currently used in framework. The only difference is that we allow a real interactive rebase if the `commit message fixup` label is applied. This allows commit message modifications (and others) if needed. PR Close #37138
This commit is contained in:
parent
e7c017cfe3
commit
e19930e70d
|
@ -39,17 +39,18 @@ export class AutosquashMergeStrategy extends MergeStrategy {
|
|||
// Git revision for the first commit the pull request is based on.
|
||||
const baseRevision = this.getPullRequestBaseRevision(pullRequest);
|
||||
|
||||
// By default, we rebase the pull request so that fixup or squash commits are
|
||||
// automatically collapsed. Optionally, if a commit message fixup is needed, we
|
||||
// make this an interactive rebase so that commits can be selectively modified
|
||||
// before the merge completes.
|
||||
// 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
|
||||
// our rebase is always interactive. In reality though, unless a commit message fixup
|
||||
// is desired, we set the `GIT_SEQUENCE_EDITOR` environment variable to `true` so that
|
||||
// the rebase seems interactive to Git, while it's not interactive to the user.
|
||||
// See: https://github.com/git/git/commit/891d4a0313edc03f7e2ecb96edec5d30dc182294.
|
||||
const branchBeforeRebase = this.git.getCurrentBranch();
|
||||
const rebaseArgs = ['--autosquash', baseRevision, TEMP_PR_HEAD_BRANCH];
|
||||
if (needsCommitMessageFixup) {
|
||||
this.git.run(['rebase', '--interactive', ...rebaseArgs], {stdio: 'inherit'});
|
||||
} else {
|
||||
this.git.run(['rebase', ...rebaseArgs]);
|
||||
}
|
||||
const rebaseEnv =
|
||||
needsCommitMessageFixup ? undefined : {...process.env, GIT_SEQUENCE_EDITOR: 'true'};
|
||||
this.git.run(
|
||||
['rebase', '--interactive', '--autosquash', baseRevision, TEMP_PR_HEAD_BRANCH],
|
||||
{stdio: 'inherit', env: rebaseEnv});
|
||||
|
||||
// Update pull requests commits to reference the pull request. This matches what
|
||||
// Github does when pull requests are merged through the Web UI. The motivation is
|
||||
|
|
Loading…
Reference in New Issue