getPullRequestEditedDiffRanges: work around fatal error
This commits adds a "git repack" step to getPullRequestEditedDiffRanges to work around a Git bug concerning tracking of grafted commits.
This commit is contained in:
parent
3e10d3452b
commit
57a28594b9
2 changed files with 25 additions and 2 deletions
|
|
@ -205,6 +205,24 @@ export const gitFetch = async function (branch: string, extraFlags: string[]) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Repack the git repository, using with the given flags. Errors are logged.
|
||||
*
|
||||
* This function uses the `checkout_path` to determine the repository path and
|
||||
* works only when called from `analyze` or `upload-sarif`.
|
||||
*/
|
||||
export const gitRepack = async function (flags: string[]) {
|
||||
try {
|
||||
await runGitCommand(
|
||||
getOptionalInput("checkout_path"),
|
||||
["repack", ...flags],
|
||||
"Cannot repack the repository.",
|
||||
);
|
||||
} catch {
|
||||
// Errors are already logged by runGitCommand()
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute the all merge bases between the given refs. Returns an empty array
|
||||
* if no merge base is found, or if there is an error.
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ async function getPullRequestEditedDiffRanges(
|
|||
|
||||
// To compute the merge bases between the base branch and the PR topic branch,
|
||||
// we need to fetch the commit graph from the branch heads to those merge
|
||||
// babes. The following 4-step procedure does so while limiting the amount of
|
||||
// babes. The following 6-step procedure does so while limiting the amount of
|
||||
// history fetched.
|
||||
|
||||
// Step 1: Deepen from the PR merge commit to the base branch head and the PR
|
||||
|
|
@ -317,7 +317,12 @@ async function getPullRequestEditedDiffRanges(
|
|||
// Step 4: Fetch the base branch history, stopping when we reach commits that
|
||||
// are reachable from the PR topic branch head.
|
||||
await actionsUtil.gitFetch(baseRef, [`--shallow-exclude=${headRef}`]);
|
||||
// Step 5: Deepen the history so that we have the merge bases between the base
|
||||
// Step 5: Repack the history to remove the shallow grafts that were added by
|
||||
// the previous fetches. This step works around a bug that causes subsequent
|
||||
// deepening fetches to fail with "fatal: error in object: unshallow <SHA>".
|
||||
// See https://stackoverflow.com/q/63878612
|
||||
await actionsUtil.gitRepack(["-d"]);
|
||||
// Step 6: Deepen the history so that we have the merge bases between the base
|
||||
// branch and the PR topic branch.
|
||||
await actionsUtil.deepenGitHistory();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue