GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fork seams: after a rebase, exclude an upstream file named like a for… · scuttletoby/t3code@42571f7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/scripts
    • fork-follow.sh
    • fork-follow.test.sh
    • fork-seam-check.cjs
    • fork-seam-check.test.cjs
  • docs/fork
    • updates.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/scripts/fork-follow.sh‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-follow.sh
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ schema_check "$base" "The series"
195195
# is a fork with a list of its own). After a rebase (--after-rebase), a "pending" ceiling or "lost"
196196
# count above the file's lines is only a note: upstream taking a fork line drops it in the rebase,
197197
# and the next run (from the new base) would refuse it. So the series gets a commit that lowers each
198-
# one (#325); a count that rose is still refused, as raising one is the owner's review.
198+
# one (#325), and excludes in "forkFiles" each upstream file a pull request's run would take for the
199+
# fork's own (#432); a count that rose is still refused, as raising one is the owner's review.
199200
seam_refusal="Fork changes to upstream files must stay within the seam lines"
200201
# What a lowering commit changed, for the run's summary: written only once the plan has finished,
201202
# as a later check can still stop it and then nothing is pushed.
@@ -218,7 +219,7 @@ seam_check() { # seam_check BASE WHAT [--after-rebase]
218219
as_fork commit -q -m "fork seams: lower counts after the rebase onto $target_tag" -m "$lowered"
219220
printf '%s\n' "$2 lowered the seam list (.github/fork-seams.json) in a commit of its own:" "$lowered" >&2
220221
lowered_summary=("### Seam list lowered: $2" "" "$lowered" "" \
221-
"Committed on top of the rebased series (the candidate); the fork lines or upstream lines these counted are gone." "")
222+
"Committed on top of the rebased series (the candidate); the fork lines or upstream lines these counted are gone, and each excluded file is upstream's." "")
222223
# The lowered list is judged again: it must pass and lower nothing more.
223224
status=0
224225
seam_run "$1" ${3:+"$3"} || status=$?
Collapse file

‎.github/scripts/fork-follow.test.sh‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-follow.test.sh
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,24 @@ plan
693693
check "plan: re-run of a rebase that lowered the list -> the same files, advance to the earlier release" \
694694
eval 'action_is advance && [[ "$(out candidate)" == "$released" ]] && grep -q "lowered the seam list" "$root/out"'
695695

696+
# #432: upstream adds a file named like the fork's (upstream's own "fork" feature names files so).
697+
# A pull request's run would take it for the fork's own, so the run from upstream refused it and
698+
# every fork-follow stopped until a pull request excluded it. After the rebase the plan excludes
699+
# it itself, in the lowering commit, and the next run passes.
700+
new_upstream
701+
new_fork v0.1.10
702+
up_release v0.1.11 'echo up > fork-up.txt'
703+
plan
704+
check "plan: an upstream file named like a fork file is excluded in the lowered list, not a stop" \
705+
eval 'action_is rebase && [[ ! -e "$root/refused" ]] \
706+
&& [[ "$(lowered_list | jq -c .forkFiles)" == "[\"!fork-up.txt\"]" ]] \
707+
&& grep -qx -- "- fork-up.txt: \"forkFiles\" \"!fork-up.txt\" added (upstream has it; a pull request'"'"'s run took it for a fork file)" <<< "$(git -C "$root/work" log -1 --format=%b "$(out candidate)")"'
708+
work git reset -q --hard "$(out candidate)"
709+
work git push -q --force origin HEAD:main
710+
plan
711+
check "plan: the next run from the new base passes the list with the exclusion" \
712+
eval 'action_is release && [[ ! -e "$root/report.md" ]] && hasnt "lowered the seam list" "$root/out"'
713+
696714
# The lowered list is checked again and must lower nothing more. A seam check that always lowers
697715
# (in the fork's series, which the plan runs) stops the plan: the report says what was lowered, and
698716
# the run's summary claims no commit, as nothing goes on from here.
Collapse file

‎.github/scripts/fork-seam-check.cjs‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-seam-check.cjs
+48-15Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,20 @@ function findListedGone(config, { atBase, atHead }) {
555555
}
556556

557557
/**
558-
* Upstream's files the head still has that a pull request's run would take for the fork's own (a
559-
* hole in that run). `upstreamFiles`: every path upstream has; `atHead`: a path's text in head.
558+
* Upstream files in head that a pull request's run would take for the fork's own. Refused, except
559+
* right after a rebase that writes a lowered list: there each goes to `lowered.hidden` and lowerList
560+
* excludes it in "forkFiles", which only narrows what a pull request's run takes for the fork's own.
560561
*/
561-
function findHiddenUpstreamFiles(upstreamFiles, isForkFile, atHead) {
562-
return upstreamFiles
563-
.filter((file) => isForkFile(file) && atHead(file) !== undefined)
564-
.map(
565-
(file) =>
566-
`${file}: upstream has it, but a pull request's run takes it for a fork file (its name or "forkFiles"); exclude it with "!${file}".`,
567-
);
562+
function findHiddenUpstreamFiles(upstreamFiles, isForkFile, atHead, lowered) {
563+
const hidden = upstreamFiles.filter((file) => isForkFile(file) && atHead(file) !== undefined);
564+
if (lowered !== undefined) {
565+
for (const file of hidden) lowered.hidden.add(file);
566+
return [];
567+
}
568+
return hidden.map(
569+
(file) =>
570+
`${file}: upstream has it, but a pull request's run takes it for a fork file (its name or "forkFiles"); exclude it with "!${file}".`,
571+
);
568572
}
569573

570574
/**
@@ -877,10 +881,10 @@ const MOVED_WHY =
877881
'Was "pending": fork-follow moved it here once it had no fork line left, as its "lost" entry still counts upstream lines it loses. No seam line: a fork line goes in a file of the fork\'s own.';
878882

879883
/**
880-
* `text` with the counts in `lowered` ({ pending, lost }: Maps of file to count) lowered, as { text, changes },
881-
* or undefined when nothing changes. Only lowers; a count at 0 removes the entry. A "pending" file with no fork
882-
* line left that "lost" still names moves to "files" with no seam line (no fork line may come back, no line may
883-
* be lost). Two-space JSON, parsed again before it is returned, so a lowered list is never one the check refuses.
884+
* `text` with `lowered` ({ pending, lost } Maps of counts, `hidden` Set of upstream files) applied, as
885+
* { text, changes }, or undefined when nothing changes. Only lowers; a count at 0 removes the entry; a
886+
* "pending" file with no fork line left moves to "files"; each hidden file stops being a fork file
887+
* (its own "forkFiles" entry goes, or a `!` entry excludes it). Parsed again before it is returned.
884888
*/
885889
function lowerList(text, lowered) {
886890
const raw = JSON.parse(text);
@@ -927,6 +931,21 @@ function lowerList(text, lowered) {
927931
}),
928932
);
929933
}
934+
for (const file of lowered.hidden ?? []) {
935+
const patterns = raw.forkFiles ?? [];
936+
const kept = patterns.filter((pattern) => pattern !== file);
937+
const named = forkFileTest(kept)(file);
938+
if (named) kept.push(`!${file}`);
939+
raw.forkFiles = kept;
940+
const what = !named
941+
? "entry removed"
942+
: kept.length === patterns.length
943+
? `entry replaced by "!${file}"`
944+
: `"!${file}" added`;
945+
changes.push(
946+
`${file}: "forkFiles" ${what} (upstream has it; a pull request's run took it for a fork file)`,
947+
);
948+
}
930949
// Appended through defineProperty: a file named `__proto__` stays an own key.
931950
for (const file of moved) {
932951
Object.defineProperty(raw.files, file, {
@@ -1038,7 +1057,9 @@ function main(argv) {
10381057
}
10391058
}
10401059
const lowered =
1041-
parsed.loweredList === undefined ? undefined : { pending: new Map(), lost: new Map() };
1060+
parsed.loweredList === undefined
1061+
? undefined
1062+
: { pending: new Map(), lost: new Map(), hidden: new Set() };
10421063
const unlisted = findUnlistedChanges(config, {
10431064
changed,
10441065
atBase,
@@ -1087,6 +1108,7 @@ function main(argv) {
10871108
git(["ls-tree", "-r", "-z", "--name-only", mergeBase]).split("\0").filter(Boolean),
10881109
isForkFile,
10891110
atHead,
1111+
lowered,
10901112
)
10911113
: []),
10921114
];
@@ -1127,7 +1149,18 @@ function main(argv) {
11271149
if (listProblem !== undefined) return 1;
11281150
if (lowered !== undefined) {
11291151
// After a rebase only: fork-follow commits the lowered list into the rebased series.
1130-
const lower = lowerList(textAt(configRef, CONFIG), lowered);
1152+
const listText = textAt(configRef, CONFIG);
1153+
const lower = lowerList(listText, lowered);
1154+
const isStillFork = forkFileTest(parseConfig(lower?.text ?? listText).forkFiles);
1155+
const still = [...lowered.hidden].filter((file) => isStillFork(file));
1156+
if (still.length > 0) {
1157+
for (const file of still) {
1158+
console.error(
1159+
printable(`${file}: the lowered list still takes this upstream file for a fork file.`),
1160+
);
1161+
}
1162+
return 1;
1163+
}
11311164
if (lower !== undefined) {
11321165
fs.writeFileSync(parsed.loweredList, lower.text);
11331166
for (const change of lower.changes) console.log(printable(`Lowered: ${change}`));
Collapse file

‎.github/scripts/fork-seam-check.test.cjs‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-seam-check.test.cjs
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,90 @@ test("from upstream, an upstream file named like a fork file fails on the comman
913913
});
914914
});
915915

916+
// A file upstream names like a fork file stopped every fork-follow after the rebase until a pull
917+
// request excluded it. Right after a rebase that writes a lowered list, the list excludes it.
918+
test("after a rebase, the lowered list excludes an upstream file a pull request's run takes for a fork file", () => {
919+
withRepo(({ dir, commit, fromUpstream }) => {
920+
const upstream = commit(
921+
{ "src/exact.ts": UP, "src/forkJoin.ts": UP, "src/usage/Up.ts": UP, ...BASE },
922+
"upstream",
923+
);
924+
// Old state: a list with no "forkFiles" key, and one whose entries take upstream's files.
925+
const forkFiles = ["src/usage/", "src/exact.ts", "src/fork-own.ts"];
926+
const series = commit(
927+
{ ...seams({ files: SEAM, forkFiles }), "src/fork-own.ts": UP },
928+
"fork series",
929+
);
930+
const out = path.join(dir, "..", `${path.basename(dir)}-lowered.json`);
931+
try {
932+
// Before the rebase, or after it with no list to write, it is still refused: nothing would
933+
// commit the exclusion, and main's pull request runs would keep the hole.
934+
for (const args of [[], ["--after-rebase"]]) {
935+
const refused = fromUpstream(...args, upstream, series);
936+
assert.equal(refused.status, 1, args.join(" "));
937+
assert.match(refused.stderr, /- src\/forkJoin\.ts: upstream has it/);
938+
}
939+
const result = fromUpstream("--after-rebase", "--lowered-list", out, upstream, series);
940+
assert.equal(result.status, 0, result.stderr);
941+
const why = "(upstream has it; a pull request's run took it for a fork file)";
942+
assert.deepEqual(result.stdout.match(/^Lowered: .*$/gm), [
943+
`Lowered: src/exact.ts: "forkFiles" entry removed ${why}`,
944+
`Lowered: src/forkJoin.ts: "forkFiles" "!src/forkJoin.ts" added ${why}`,
945+
`Lowered: src/usage/Up.ts: "forkFiles" "!src/usage/Up.ts" added ${why}`,
946+
]);
947+
const lowered = parseConfig(fs.readFileSync(out, "utf8"));
948+
assert.deepEqual(lowered.forkFiles, [
949+
"src/usage/",
950+
"src/fork-own.ts",
951+
"!src/forkJoin.ts",
952+
"!src/usage/Up.ts",
953+
]);
954+
// Main's pull request runs judge upstream's three as upstream's; the fork's own stay its own.
955+
const isForkFile = forkFileTest(lowered.forkFiles);
956+
for (const file of ["src/exact.ts", "src/forkJoin.ts", "src/usage/Up.ts"]) {
957+
assert.equal(isForkFile(file), false, file);
958+
}
959+
assert.equal(isForkFile("src/fork-own.ts"), true);
960+
assert.equal(isForkFile("src/usage/Own.ts"), true);
961+
// Runs again with the lowered list committed: nothing more to lower or refuse.
962+
fs.rmSync(out);
963+
const committed = commit({ [CONFIG]: JSON.stringify(lowered) }, "lowered");
964+
for (const args of [["--after-rebase", "--lowered-list", out], ["--after-rebase"], []]) {
965+
const again = fromUpstream(...args, upstream, committed);
966+
assert.equal(again.status, 0, `${args.join(" ")}: ${again.stderr}`);
967+
assert.doesNotMatch(again.stdout, /Lowered/);
968+
}
969+
assert.equal(fs.existsSync(out), false);
970+
// A fork change in such a file is refused, never excluded away, and nothing is written.
971+
const changed = commit(
972+
{ [CONFIG]: JSON.stringify({ files: SEAM, forkFiles }), "src/forkJoin.ts": `${UP}x();\n` },
973+
"fork line",
974+
);
975+
const stopped = fromUpstream("--after-rebase", "--lowered-list", out, upstream, changed);
976+
assert.equal(stopped.status, 1);
977+
assert.match(stopped.stderr, /- src\/forkJoin\.ts: upstream file with 1 fork line/);
978+
assert.equal(fs.existsSync(out), false);
979+
} finally {
980+
fs.rmSync(out, { force: true });
981+
}
982+
});
983+
});
984+
985+
test("lowerList excludes a hidden upstream file in a list with no forkFiles, or replaces its own entry", () => {
986+
const none = `${JSON.stringify({ files: {} }, null, 2)}\n`;
987+
const hidden = (...files) => ({ pending: new Map(), lost: new Map(), hidden: new Set(files) });
988+
assert.deepEqual(JSON.parse(lowerList(none, hidden("src/forkJoin.ts")).text), {
989+
files: {},
990+
forkFiles: ["!src/forkJoin.ts"],
991+
});
992+
// Named like the fork's and listed: the entry alone would not exclude it, so a `!` replaces it.
993+
const listed = `${JSON.stringify({ files: {}, forkFiles: ["fork/up.ts"] }, null, 2)}\n`;
994+
const result = lowerList(listed, hidden("fork/up.ts"));
995+
assert.deepEqual(JSON.parse(result.text).forkFiles, ["!fork/up.ts"]);
996+
assert.match(result.changes[0], /^fork\/up\.ts: "forkFiles" entry replaced by "!fork\/up\.ts"/);
997+
assert.equal(lowerList(none, hidden()), undefined);
998+
});
999+
9161000
// Both cases passed in both modes before.
9171001
test("a rename or delete cannot hide an upstream file, from upstream or on a pull request", () => {
9181002
withRepo(({ dir, git, commit, run, fromUpstream }) => {
Collapse file

‎docs/fork/updates.md‎

Copy file name to clipboardExpand all lines: docs/fork/updates.md
+6-3Lines changed: 6 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ watches; it changes nothing on the machine, and `0` turns it off.
122122
(the runbook below), regenerate the tree and commit it into the rebased series before pushing; a
123123
pull request that changes only the tree is judged line by line and refused. A pull request's run has no upstream commit,
124124
so it takes files named as the fork's (`fork`, `fork-*`, `forkName*`, `FORK_*`) and `forkFiles`
125-
for the fork's own; from upstream, a pattern that matches an upstream file fails. Then remove the
126-
entry (or exclude a fork-named path with `!path`): from then on a pull request's run judges the
127-
file as upstream's, also before the rebase that brings upstream's copy. For the same
125+
for the fork's own; from upstream, a pattern that matches an upstream file fails. Right after a
126+
rebase it is not refused: fork-follow excludes the file itself in its lowering commit (the
127+
file's own `forkFiles` entry goes; a fork-named path or one another pattern takes gets `!path`),
128+
which only narrows what a pull request's run takes for the fork's own. Before a rebase (a list
129+
on main that lets one through) it still fails: remove the entry or add the `!path` with a pull
130+
request. Either way a pull request's run then judges the file as upstream's. For the same
128131
reason a pull request's run counts upstream's copies of a seam line against its allowance: a
129132
seam line upstream also has (`}`, `/**`) cannot be added by a pull request, only checked by
130133
fork-follow, so keep seam lines specific. A listed copy main's tip already has is spent too, not

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.