mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 06:04:33 +01:00
fix: base CHANGELOG read in readFragments fails loudly; history readers try git show first
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
48a9d92a2f
commit
6aac45aa74
4 files changed
+37
-23
No files matched your search
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { headingVersion, parseChangelog } from './changelog-check';
|
||||
import { readHistoryFile } from './history-read';
|
||||
import type { Bump } from './version-source';
|
||||
|
||||
export const FRAGMENT_README = 'README.md';
|
||||
@@ -75,8 +76,8 @@ export function readFragments(cwd: string, treeish: string | null, dir: string,
|
||||
return out;
|
||||
};
|
||||
const excluded = new Map((exclude ? list(exclude) : []).map(e => [e.path, e.sha]));
|
||||
const shown = exclude && changelog ? git(cwd, ['show', `${exclude}:${changelog}`]) : null;
|
||||
const released = shown?.ok ? parseChangelog(shown.out.replace(/\r\n/g, '\n')).sections.filter(s => !s.unreleased).map(s => s.lines) : [];
|
||||
const shown = exclude && changelog ? readHistoryFile(cwd, exclude, changelog) : null;
|
||||
const released = shown !== null ? parseChangelog(shown.replace(/\r\n/g, '\n')).sections.filter(s => !s.unreleased).map(s => s.lines) : [];
|
||||
const isReleased = (body: string) => {
|
||||
const want = body.split('\n');
|
||||
return released.some(lines => lines.some((_, i) => want.every((w, k) => lines[i + k] === w)));
|
||||
|
||||
+14
-10
@@ -2,12 +2,14 @@
|
||||
* Read one file at a commit when the checkout may be a blobless clone
|
||||
* (`filter: blob:none`), where git fetches an old file's contents on demand
|
||||
* and that fetch can fail. The TypeScript twin of
|
||||
* .github/scripts/history-read.sh: existence comes from the ref's tree
|
||||
* (`git ls-tree`, local data only); a listed path is read with `git show`,
|
||||
* tried 3 times in a partial clone (only a fetch can recover) and once
|
||||
* otherwise, waiting HISTORY_READ_BACKOFF_SECONDS (default 2) times the attempt
|
||||
* between tries; every other failure throws HISTORY_READ_FAILED instead of
|
||||
* reading as absent (docs/troubleshooting.md#history-read-failed).
|
||||
* .github/scripts/history-read.sh. A read that `git show` answers is the
|
||||
* file. When it fails, existence comes from the ref's tree (`git ls-tree
|
||||
* --full-tree`, local data only): a path the tree does not list is absent, and
|
||||
* a listed one is retried, 3 tries in all in a partial clone (only a fetch can
|
||||
* recover) and none otherwise, waiting HISTORY_READ_BACKOFF_SECONDS (default 2)
|
||||
* times the attempt between tries. Every other failure throws
|
||||
* HISTORY_READ_FAILED instead of reading as absent
|
||||
* (docs/troubleshooting.md#history-read-failed).
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
@@ -25,15 +27,17 @@ export function readHistoryFile(repoRoot: string, ref: string, file: string): st
|
||||
return new HistoryReadError(`cannot read ${file} at ${ref}. ${cause} (${version}). Fix: see docs/troubleshooting.md#history-read-failed (HISTORY_READ_FAILED)`);
|
||||
};
|
||||
const firstLine = (r: ReturnType<typeof git>) => (r.stderr ?? '').split('\n')[0] || r.error?.message || `exit ${r.status}`;
|
||||
let shown = git(['show', `${ref}:${file}`]);
|
||||
if (shown.status === 0) return shown.stdout;
|
||||
const listed = git(['ls-tree', '--full-tree', ref, '--', file]);
|
||||
if (listed.status !== 0) throw fail(`git ls-tree failed: ${firstLine(listed)}`);
|
||||
if (!listed.stdout.trim()) return null;
|
||||
const promisors = (git(['config', '--get-regexp', '^(remote\\..+\\.promisor|extensions\\.partialclone)$']).stdout ?? '').split('\n');
|
||||
const tries = promisors.some(line => line && !/ false$/i.test(line)) ? HISTORY_READ_TRIES : 1;
|
||||
for (let attempt = 1; ; attempt++) {
|
||||
const shown = git(['show', `${ref}:${file}`]);
|
||||
if (shown.status === 0) return shown.stdout;
|
||||
if (attempt === tries) throw fail(`git show failed ${tries === 1 ? 'once (not a partial clone, so no retry)' : `${tries} times`}: ${firstLine(shown)}`);
|
||||
for (let attempt = 1; attempt < tries; attempt++) {
|
||||
Bun.sleepSync(attempt * 1000 * Number(process.env.HISTORY_READ_BACKOFF_SECONDS ?? 2));
|
||||
shown = git(['show', `${ref}:${file}`]);
|
||||
if (shown.status === 0) return shown.stdout;
|
||||
}
|
||||
throw fail(`git show failed ${tries === 1 ? 'once (not a partial clone, so no retry)' : `${tries} times`}: ${firstLine(shown)}`);
|
||||
}
|
||||
Reference in new issue
Block a user