-
Notifications
You must be signed in to change notification settings - Fork 425
Fix bundle transport in shallow checkouts #31603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b297570
4c20598
d61d800
92060e7
4873a9f
0e501e0
ce4c4d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,8 +150,30 @@ function hasMergeCommitsInRange(baseRef, headRef, options = {}) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Ensure the current repository has full history before fetching a git bundle. | ||
| * | ||
| * Bundles generated from a commit range can declare prerequisite commits. A | ||
| * depth-1 checkout may not contain those prerequisites, and `git fetch <bundle>` | ||
| * rejects the bundle before the caller can update refs. Unshallowing first makes | ||
| * the prerequisites available while avoiding a no-op network fetch for full | ||
| * checkouts. | ||
| * | ||
| * @param {{ getExecOutput: Function, exec: Function }} execApi - Exec API to run git commands. | ||
| * @param {Object} [options] - Options passed through to exec calls. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function ensureFullHistoryForBundle(execApi, options = {}) { | ||
| const { stdout } = await execApi.getExecOutput("git", ["rev-parse", "--is-shallow-repository"], options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] The Consider treating any failure as non-shallow and logging a warning: try {
({ stdout } = await execApi.getExecOutput(
'git', ['rev-parse', '--is-shallow-repository'], options
));
} catch {
core.warning('Could not determine shallow status; skipping unshallow');
return;
}Adding a test for this error path would lock in the fallback behaviour. |
||
| if (stdout.trim() === "true") { | ||
| core.info("Repository is shallow; fetching full history before applying bundle"); | ||
| await execApi.exec("git", ["fetch", "--unshallow", "origin"], options); | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| execGitSync, | ||
| ensureFullHistoryForBundle, | ||
| getGitAuthEnv, | ||
| hasMergeCommitsInRange, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] This mock branch is dead code.
cmdis"git"(just the executable), socmd.startsWith("git ls-remote")is alwaysfalse. The catch-all return covers ls-remote calls, but the intent is invisible.Fix to match by args:
The pattern used in the existing tests at lines ~1848 (
cmdStr.includes('ls-remote --heads origin')) is an alternative. Either way, the dead branch should be removed so the mock accurately documents its contract.