benignswarm 0.12.140 → 0.12.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/git.js +23 -7
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/git.js
CHANGED
|
@@ -575,24 +575,40 @@ export function remoteHead(branch, remote = "origin", cwd = process.cwd()) {
|
|
|
575
575
|
const line = r.stdout.split("\n").find((l) => l.trim().endsWith(`refs/heads/${branch}`));
|
|
576
576
|
return line ? line.split(/\s+/)[0] : null;
|
|
577
577
|
}
|
|
578
|
+
/** Verify ancestry against the immutable advertised tip, after proving its object is fetched. */
|
|
579
|
+
export function remoteTrackingRefContainsCommit(branch, advertisedTip, sha, cwd = process.cwd()) {
|
|
580
|
+
if (fullSha(`refs/remotes/${branch}`, cwd) !== advertisedTip)
|
|
581
|
+
return false;
|
|
582
|
+
return isAncestor(sha, advertisedTip, cwd) === true;
|
|
583
|
+
}
|
|
578
584
|
/** Fetch origin, then report a remote branch containing the submitted commit. */
|
|
579
585
|
export function findRemoteCommitBranch(sha, localBranch, cwd = process.cwd(), remote = "origin") {
|
|
580
586
|
const checkedRef = `${remote}/${localBranch}`;
|
|
581
|
-
|
|
587
|
+
// Submission only needs current remote-tracking refs. Force pruning off even when user/repo
|
|
588
|
+
// config enables it: pruning stale refs takes .git/packed-refs.lock in the shared Git dir.
|
|
589
|
+
const fetched = spawnSync("git", ["-c", "fetch.prune=false", "-c", `remote.${remote}.prune=false`, "fetch", remote], { cwd, encoding: "utf8", timeout: 120_000 });
|
|
582
590
|
if (fetched.status !== 0) {
|
|
583
591
|
const detail = (fetched.stderr || fetched.stdout || `git fetch ${remote} exited with status ${fetched.status ?? "unknown"}`).trim();
|
|
584
592
|
return { remoteBranch: null, checkedRef, checked: false, reason: `git fetch ${remote} failed: ${detail}` };
|
|
585
593
|
}
|
|
586
|
-
const
|
|
587
|
-
if (
|
|
588
|
-
const detail = (
|
|
589
|
-
return { remoteBranch: null, checkedRef, checked:
|
|
594
|
+
const advertised = spawnSync("git", ["ls-remote", "--heads", remote], { cwd, encoding: "utf8", timeout: 30_000 });
|
|
595
|
+
if (advertised.status !== 0) {
|
|
596
|
+
const detail = (advertised.stderr || advertised.stdout || `git ls-remote ${remote} exited with status ${advertised.status ?? "unknown"}`).trim();
|
|
597
|
+
return { remoteBranch: null, checkedRef, checked: false, reason: `git ls-remote ${remote} failed: ${detail}` };
|
|
598
|
+
}
|
|
599
|
+
const advertisedTips = new Map();
|
|
600
|
+
for (const line of advertised.stdout.split("\n")) {
|
|
601
|
+
const [tip, ref] = line.trim().split(/\s+/);
|
|
602
|
+
if (ref?.startsWith("refs/heads/") && tip)
|
|
603
|
+
advertisedTips.set(`${remote}/${ref.slice("refs/heads/".length)}`, tip);
|
|
590
604
|
}
|
|
591
|
-
|
|
605
|
+
// Check ancestry against the advertised object ID, not a mutable tracking ref. A concurrent
|
|
606
|
+
// fetch can move that ref between checking its tip and asking Git about containment.
|
|
607
|
+
const branches = [...advertisedTips].filter(([branch, tip]) => branch !== `${remote}/HEAD` && remoteTrackingRefContainsCommit(branch, tip, sha, cwd)).map(([branch]) => branch).sort();
|
|
592
608
|
const remoteBranch = branches.includes(checkedRef) ? checkedRef : branches[0] ?? null;
|
|
593
609
|
return remoteBranch
|
|
594
610
|
? { remoteBranch, checkedRef, checked: true, reason: null }
|
|
595
|
-
: { remoteBranch: null, checkedRef, checked: true, reason: `
|
|
611
|
+
: { remoteBranch: null, checkedRef, checked: true, reason: `no advertised ${remote} branch contains the submitted commit ${sha}` };
|
|
596
612
|
}
|
|
597
613
|
export function formatRemoteCommitFailure(localBranch, checkedRef, reason) {
|
|
598
614
|
return `Could not verify the submitted commit for local branch ${localBranch}: checked ${checkedRef} and other origin branches; ${reason}`;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.141";
|