diff --git a/dev-infra/pr/merge/strategies/api-merge.ts b/dev-infra/pr/merge/strategies/api-merge.ts index 36eb159d7c..f52b768e00 100644 --- a/dev-infra/pr/merge/strategies/api-merge.ts +++ b/dev-infra/pr/merge/strategies/api-merge.ts @@ -135,7 +135,13 @@ export class GithubApiMergeStrategy extends MergeStrategy { // Cherry pick the merged commits into the remaining target branches. const failedBranches = await this.cherryPickIntoTargetBranches( - `${targetSha}~${targetCommitsCount}..${targetSha}`, cherryPickTargetBranches); + `${targetSha}~${targetCommitsCount}..${targetSha}`, cherryPickTargetBranches, { + // Commits that have been created by the Github API do not necessarily contain + // a reference to the source pull request (unless the squash strategy is used). + // To ensure that original commits can be found when a commit is viewed in a + // target branch, we add a link to the original commits when cherry-picking. + linkToOriginalCommits: true, + }); // We already checked whether the PR can be cherry-picked into the target branches, // but in case the cherry-pick somehow fails, we still handle the conflicts here. The diff --git a/dev-infra/pr/merge/strategies/strategy.ts b/dev-infra/pr/merge/strategies/strategy.ts index 9c29c1b8d9..2e1ff24d26 100644 --- a/dev-infra/pr/merge/strategies/strategy.ts +++ b/dev-infra/pr/merge/strategies/strategy.ts @@ -69,7 +69,8 @@ export abstract class MergeStrategy { * @returns A list of branches for which the revisions could not be cherry-picked into. */ protected cherryPickIntoTargetBranches(revisionRange: string, targetBranches: string[], options: { - dryRun?: boolean + dryRun?: boolean, + linkToOriginalCommits?: boolean, } = {}) { const cherryPickArgs = [revisionRange]; const failedBranches: string[] = []; @@ -82,6 +83,14 @@ export abstract class MergeStrategy { cherryPickArgs.push('--no-commit'); } + if (options.linkToOriginalCommits) { + // We add `-x` when cherry-picking as that will allow us to easily jump to original + // commits for cherry-picked commits. With that flag set, Git will automatically append + // the original SHA/revision to the commit message. e.g. `(cherry picked from commit <..>)`. + // https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x. + cherryPickArgs.push('-x'); + } + // Cherry-pick the refspec into all determined target branches. for (const branchName of targetBranches) { const localTargetBranch = this.getLocalTargetBranchName(branchName);