@webpieces/pr-gate 0.4.975 → 0.4.977
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/package.json +6 -6
- package/src/scripts/commands/await-checks-command.d.ts +6 -3
- package/src/scripts/commands/await-checks-command.js +17 -12
- package/src/scripts/commands/await-checks-command.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +1 -1
- package/src/scripts/commands/await-reviews-command.js +3 -3
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +3 -1
- package/src/scripts/commands/check-pr-command.js +12 -9
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/cleanup-command.js +12 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-push-dev-command.js +3 -4
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/finish-update-command.js +1 -1
- package/src/scripts/commands/finish-update-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
- package/src/scripts/commands/human-post-pr-command.js +33 -32
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +5 -1
- package/src/scripts/commands/land-pr-command.js +37 -23
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/main-checkout.d.ts +4 -1
- package/src/scripts/commands/main-checkout.js +22 -22
- package/src/scripts/commands/main-checkout.js.map +1 -1
- package/src/scripts/commands/push-dev-command.js +28 -29
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -5
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.js +10 -10
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-update-command.d.ts +1 -1
- package/src/scripts/commands/start-update-command.js +3 -3
- package/src/scripts/commands/start-update-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.js +4 -4
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +6 -6
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
- package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/working-tree-gate.d.ts +4 -1
- package/src/scripts/commands/working-tree-gate.js +14 -11
- package/src/scripts/commands/working-tree-gate.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
- package/src/scripts/commands/worktree-cleanup.js +4 -4
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +4 -6
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -4
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +2 -2
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/git-gatherInfo.js +6 -7
- package/src/scripts/git-gatherInfo.js.map +1 -1
- package/src/scripts/pr-gate-container.d.ts +9 -0
- package/src/scripts/pr-gate-container.js +19 -0
- package/src/scripts/pr-gate-container.js.map +1 -0
- package/src/scripts/workflow/await-loop.d.ts +1 -1
- package/src/scripts/workflow/await-loop.js +1 -1
- package/src/scripts/workflow/await-loop.js.map +1 -1
- package/src/scripts/workflow/build-affected.js +1 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
- package/src/scripts/workflow/build-artifact-gate.js +3 -3
- package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +9 -6
- package/src/scripts/workflow/build-gate-log.js +34 -40
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/checklist-detector.d.ts +2 -2
- package/src/scripts/workflow/checklist-detector.js +4 -4
- package/src/scripts/workflow/checklist-detector.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
- package/src/scripts/workflow/checklist-scanner.js +11 -11
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
- package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
- package/src/scripts/workflow/dev-deploy-refs.js +8 -8
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
- package/src/scripts/workflow/dev-resolve-runner.js +30 -30
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/diff-basis.d.ts +4 -2
- package/src/scripts/workflow/diff-basis.js +18 -15
- package/src/scripts/workflow/diff-basis.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.d.ts +5 -3
- package/src/scripts/workflow/diff-materializer.js +18 -15
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
- package/src/scripts/workflow/gated-pr-publisher.js +23 -22
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
- package/src/scripts/workflow/generated-artifact-registry.js +11 -8
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/git-exec.d.ts +22 -12
- package/src/scripts/workflow/git-exec.js +45 -29
- package/src/scripts/workflow/git-exec.js.map +1 -1
- package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
- package/src/scripts/workflow/git-findForkPoint.js +31 -23
- package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
- package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
- package/src/scripts/workflow/git-readAiBranchName.js +8 -5
- package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
- package/src/scripts/workflow/landed-tree-resolver.js +11 -8
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
- package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +5 -4
- package/src/scripts/workflow/merge-end.js +28 -27
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +5 -1
- package/src/scripts/workflow/merge-start.js +56 -49
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/open-pr-check.d.ts +4 -2
- package/src/scripts/workflow/open-pr-check.js +11 -8
- package/src/scripts/workflow/open-pr-check.js.map +1 -1
- package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
- package/src/scripts/workflow/pr-comment-upserter.js +15 -14
- package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
- package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
- package/src/scripts/workflow/pr-context-writer.js +3 -3
- package/src/scripts/workflow/pr-context-writer.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +8 -5
- package/src/scripts/workflow/pr-merger.js +32 -27
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
- package/src/scripts/workflow/provenance-enforcer.js +19 -17
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +7 -6
- package/src/scripts/workflow/review-round-state.js +33 -38
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/run-update.js +1 -1
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
- package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
- package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
- package/src/scripts/wp-await-checks.js +2 -2
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +2 -2
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +2 -2
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +2 -2
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +2 -2
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +2 -2
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +2 -2
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +2 -2
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +2 -2
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +2 -2
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-reap-worktree.js +2 -2
- package/src/scripts/wp-reap-worktree.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +2 -2
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +2 -2
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +2 -2
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +2 -2
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +2 -2
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +2 -2
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MainCheckout = exports.StashedFiles = exports.GitRun = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const inversify_1 = require("inversify");
|
|
7
6
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
8
8
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
9
9
|
/**
|
|
10
10
|
* git's own words for the one checkout failure this class is allowed to react to. Matched on git's
|
|
@@ -97,6 +97,10 @@ exports.StashedFiles = StashedFiles;
|
|
|
97
97
|
* is decided from their text, and they are the two that render live progress, which a pipe flattens.
|
|
98
98
|
*/
|
|
99
99
|
let MainCheckout = class MainCheckout {
|
|
100
|
+
git;
|
|
101
|
+
constructor(git) {
|
|
102
|
+
this.git = git;
|
|
103
|
+
}
|
|
100
104
|
/**
|
|
101
105
|
* Fetch, check out main, fast-forward it. Returns the files that had to be stashed to get there —
|
|
102
106
|
* empty in the ordinary case.
|
|
@@ -106,10 +110,10 @@ let MainCheckout = class MainCheckout {
|
|
|
106
110
|
* the whole point of this command is that it is safe to run without thinking. A refusal to
|
|
107
111
|
* fast-forward is a real condition a human should see and decide about.
|
|
108
112
|
*/
|
|
109
|
-
goToMain(repoRoot, untracked) {
|
|
110
|
-
this.passThrough(repoRoot, ['fetch', 'origin', 'main']);
|
|
111
|
-
const stashed = this.checkoutMain(repoRoot, untracked);
|
|
112
|
-
if (this.passThrough(repoRoot, ['pull', '--ff-only', 'origin', 'main']) !== 0) {
|
|
113
|
+
async goToMain(repoRoot, untracked) {
|
|
114
|
+
await this.passThrough(repoRoot, ['fetch', 'origin', 'main']);
|
|
115
|
+
const stashed = await this.checkoutMain(repoRoot, untracked);
|
|
116
|
+
if (await this.passThrough(repoRoot, ['pull', '--ff-only', 'origin', 'main']) !== 0) {
|
|
113
117
|
throw new rules_config_1.CliExitError(1, `${SEP}❌ Local main could not fast-forward\n${SEP}\n`
|
|
114
118
|
+ 'Local main has commits that origin/main does not, so it is not a clean copy of the\n'
|
|
115
119
|
+ 'remote. Nothing was reset — those commits may be the only copy. Inspect them with\n'
|
|
@@ -118,13 +122,13 @@ let MainCheckout = class MainCheckout {
|
|
|
118
122
|
}
|
|
119
123
|
return stashed;
|
|
120
124
|
}
|
|
121
|
-
checkoutMain(repoRoot, untracked) {
|
|
122
|
-
const first = this.captureAndEcho(repoRoot, ['checkout', 'main']);
|
|
125
|
+
async checkoutMain(repoRoot, untracked) {
|
|
126
|
+
const first = await this.captureAndEcho(repoRoot, ['checkout', 'main']);
|
|
123
127
|
if (first.succeeded())
|
|
124
128
|
return new StashedFiles([]);
|
|
125
129
|
if (!this.isCollision(first, untracked))
|
|
126
130
|
throw this.checkoutFailed(first);
|
|
127
|
-
const stash = this.captureAndEcho(repoRoot, ['stash', 'push', '-u',
|
|
131
|
+
const stash = await this.captureAndEcho(repoRoot, ['stash', 'push', '-u',
|
|
128
132
|
'-m', 'wp-sync-main: untracked files that collided with main']);
|
|
129
133
|
if (!stash.succeeded()) {
|
|
130
134
|
throw new rules_config_1.CliExitError(1, `${SEP}❌ Could not check out main, and could not stash\n${SEP}\n`
|
|
@@ -134,7 +138,7 @@ let MainCheckout = class MainCheckout {
|
|
|
134
138
|
+ 'above. Move or delete these files yourself, then re-run:\n\n'
|
|
135
139
|
+ this.list(untracked.paths));
|
|
136
140
|
}
|
|
137
|
-
const second = this.captureAndEcho(repoRoot, ['checkout', 'main']);
|
|
141
|
+
const second = await this.captureAndEcho(repoRoot, ['checkout', 'main']);
|
|
138
142
|
const stashed = new StashedFiles(untracked.paths);
|
|
139
143
|
if (!second.succeeded()) {
|
|
140
144
|
throw new rules_config_1.CliExitError(1, `${SEP}❌ Could not check out main even after stashing\n${SEP}\n`
|
|
@@ -175,24 +179,20 @@ let MainCheckout = class MainCheckout {
|
|
|
175
179
|
return paths.map((path) => ` ${path}\n`).join('');
|
|
176
180
|
}
|
|
177
181
|
/** git piped, then echoed back verbatim — for the one command whose text is decided on. */
|
|
178
|
-
captureAndEcho(repoRoot, args) {
|
|
179
|
-
const result =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const stderr = result.stderr ?? '';
|
|
184
|
-
process.stdout.write(stdout);
|
|
185
|
-
process.stderr.write(stderr);
|
|
186
|
-
return new GitRun(result.status === null ? 1 : result.status, `${stdout}${stderr}`);
|
|
182
|
+
async captureAndEcho(repoRoot, args) {
|
|
183
|
+
const result = await this.git.run(['-C', repoRoot, ...args]);
|
|
184
|
+
process.stdout.write(result.stdout);
|
|
185
|
+
process.stderr.write(result.stderr);
|
|
186
|
+
return new GitRun(result.code, `${result.stdout}${result.stderr}`);
|
|
187
187
|
}
|
|
188
188
|
/** git with its output going straight to the terminal — for the commands whose progress is the point. */
|
|
189
|
-
passThrough(repoRoot, args) {
|
|
190
|
-
|
|
191
|
-
return result.status === null ? 1 : result.status;
|
|
189
|
+
async passThrough(repoRoot, args) {
|
|
190
|
+
return (await this.git.passThrough(['-C', repoRoot, ...args])).code;
|
|
192
191
|
}
|
|
193
192
|
};
|
|
194
193
|
exports.MainCheckout = MainCheckout;
|
|
195
194
|
exports.MainCheckout = MainCheckout = tslib_1.__decorate([
|
|
196
|
-
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
|
|
195
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
196
|
+
tslib_1.__metadata("design:paramtypes", [tooling_common_1.GitProcessApi])
|
|
197
197
|
], MainCheckout);
|
|
198
198
|
//# sourceMappingURL=main-checkout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-checkout.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/main-checkout.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,yCAA2D;AAC3D,0DAAuD;AAIvD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,mDAAmD,CAAC;AAEjF,wGAAwG;AACxG,MAAa,MAAM;IACM;IAAyB;IAA9C,YAAqB,MAAc,EAAW,MAAc;QAAvC,WAAM,GAAN,MAAM,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEhE,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IAC7B,CAAC;CACJ;AAND,wBAMC;AAED;;;;;;;;GAQG;AACH,MAAa,YAAY;IACA;IAArB,YAAqB,KAAwB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IAEjD,OAAO;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,+DAA+D;IAC/D,MAAM;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/E,OAAO,GAAG,GAAG,6DAA6D,GAAG,IAAI;cAC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AAG,MAAM,EAAE,CAAC,CAAC;IACxF,CAAC;IAED,yGAAyG;IACjG,WAAW,CAAC,QAAgB,EAAE,IAAc;QAChD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QACnG,OAAO,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACtD,CAAC;CACJ,CAAA;AApGY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,YAAY,CAoGxB","sourcesContent":["import { spawnSync } from 'child_process';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { CliExitError } from '@webpieces/rules-config';\n\nimport { UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * git's own words for the one checkout failure this class is allowed to react to. Matched on git's\n * TEXT rather than re-derived from the untracked list on purpose: git's rules here cover\n * directory-vs-file collisions, sparse checkouts and case-insensitive filesystems, and any\n * re-derivation of them drifts from the git actually installed. git's refusal is the authority.\n */\nconst WOULD_BE_OVERWRITTEN = 'untracked working tree files would be overwritten';\n\n/** One git invocation's exit status and the output it produced, for a caller that must decide on it. */\nexport class GitRun {\n constructor(readonly status: number, readonly output: string) {}\n\n succeeded(): boolean {\n return this.status === 0;\n }\n}\n\n/**\n * The files `git stash -u` took so the checkout could proceed — carried out so the caller can SHOUT\n * about them. Empty is the overwhelmingly common case: nothing collided, nothing was stashed.\n *\n * The message is ALL CAPS and banner-wrapped deliberately. This is the one path in the command where\n * files that were sitting in the working tree are no longer sitting in the working tree, and a reader\n * who skims past that line loses track of their own work. Everything else this command prints is\n * routine; this is not.\n */\nexport class StashedFiles {\n constructor(readonly paths: readonly string[]) {}\n\n isEmpty(): boolean {\n return this.paths.length === 0;\n }\n\n /** The human-facing banner, or '' when nothing was stashed. */\n render(): string {\n if (this.isEmpty()) return '';\n const list = this.paths.map((path: string): string => ` ${path}\\n`).join('');\n const quoted = this.paths.map((path: string): string => `'${path}'`).join(' ');\n return `${SEP}⚠️ UNTRACKED FILES WERE STASHED BECAUSE THEY CONFLICTED\\n${SEP}\\n`\n + 'GIT REFUSED TO CHECK OUT MAIN: AN UNTRACKED FILE HERE SITS AT A PATH MAIN TRACKS, AND\\n'\n + 'THE CHECKOUT WOULD HAVE OVERWRITTEN IT. `git stash -u` TAKES EVERY UNTRACKED FILE, NOT\\n'\n + 'ONLY THE ONE THAT COLLIDED, SO ALL OF THESE LEFT THE WORKING TREE. THE CHECKOUT WAS THEN\\n'\n + 'RETRIED AND YOU ARE NOW ON A CLEAN MAIN. NOTHING WAS DELETED — YOUR VERSION OF EVERY\\n'\n + 'FILE BELOW IS IN THE STASH:\\n\\n'\n + list\n + '\\nGET THEM BACK WITH:\\n\\n'\n + ' git stash pop\\n\\n'\n + 'EXPECT THAT POP TO REFUSE THE FIRST TIME. IT LANDS ON THE NEW MAIN, WHICH IS EXACTLY\\n'\n + 'WHERE A COMMITTED COPY OF THE COLLIDING PATH NOW SITS — THAT COLLISION IS WHY ANY OF\\n'\n + 'THIS HAPPENED — SO GIT SAYS \"already exists, no checkout\" AND KEEPS THE STASH. TO TAKE\\n'\n + 'YOUR VERSIONS BACK, DELETE MAIN\\'S COPIES AND POP ONTO THE HOLE:\\n\\n'\n + ` rm -f ${quoted} && git stash pop\\n\\n`\n + 'NOTHING IS DISCARDED WHILE THE POP HAS NOT SUCCEEDED — `git stash list` STILL SHOWS THE\\n'\n + 'ENTRY, AS MANY TRIES AS YOU NEED. IF THE FILE IS GENERATED, REGENERATING IT ON THE NEW\\n'\n + 'MAIN IS USUALLY BETTER THAN RESTORING A COPY BUILT FROM THE OLD ONE.\\n\\n'\n + 'WHY STASHED AND NOT REFUSED: REACHING A CLEAN MAIN HAS TO STAY POSSIBLE. A REFUSAL HERE\\n'\n + 'DEADLOCKS ANYONE — HUMAN OR AGENT — WHOSE NEXT STEP IS GATED ON BEING ON MAIN, AND AN\\n'\n + `AGENT MID-UPGRADE CANNOT ASK FOR HELP.\\n${SEP}`;\n }\n}\n\n/**\n * Get onto a current main, whatever the working tree is holding.\n *\n * ─── WHY A COLLISION STASHES RATHER THAN REFUSES ──────────────────────────────────────────────────\n * `WorkingTreeGate` deliberately lets untracked files through: they are on no branch, so the switch\n * does not move them. That is true about the FILES and not true about the CHECKOUT — git aborts when\n * an untracked file sits at a path the destination branch TRACKS (\"The following untracked working\n * tree files would be overwritten by checkout\"). Letting untracked files reach the checkout is\n * exactly what makes that abort reachable, and the field case that produced it is the common one: a\n * generated `design.html`, untracked in a working clone because it is regenerated, and committed on\n * main.\n *\n * A refusal there is a DEAD END for the one caller that most needs the command to work — an agent\n * mid-upgrade of webpieces, unable to use its tools until it reaches a clean main, with nobody\n * watching to move the file for it. So the collision is resolved rather than reported: stash with\n * `-u`, retry, and then say so loudly enough that no human loses track of the files. Losing a minute\n * to a `git stash pop` beats a state nothing can get out of.\n *\n * ─── WHY THE CHECKOUT'S OUTPUT IS CAPTURED AND RE-PRINTED ─────────────────────────────────────────\n * The decision above is made on git's own refusal text, which means the checkout cannot run on\n * `stdio: 'inherit'` — inherited output is never seen by this process. It is piped and echoed back\n * instead, so the reader still gets every byte git wrote. `fetch` and `pull` stay inherited: nothing\n * is decided from their text, and they are the two that render live progress, which a pipe flattens.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class MainCheckout {\n /**\n * Fetch, check out main, fast-forward it. Returns the files that had to be stashed to get there —\n * empty in the ordinary case.\n *\n * `--ff-only` rather than a `reset --hard`, deliberately: a developer or an agent that\n * accidentally committed to local main would have that work silently destroyed by a reset, and\n * the whole point of this command is that it is safe to run without thinking. A refusal to\n * fast-forward is a real condition a human should see and decide about.\n */\n goToMain(repoRoot: string, untracked: UntrackedFiles): StashedFiles {\n this.passThrough(repoRoot, ['fetch', 'origin', 'main']);\n const stashed = this.checkoutMain(repoRoot, untracked);\n if (this.passThrough(repoRoot, ['pull', '--ff-only', 'origin', 'main']) !== 0) {\n throw new CliExitError(1, `${SEP}❌ Local main could not fast-forward\\n${SEP}\\n`\n + 'Local main has commits that origin/main does not, so it is not a clean copy of the\\n'\n + 'remote. Nothing was reset — those commits may be the only copy. Inspect them with\\n'\n + '`git log origin/main..main` and decide what they are before going further.\\n'\n + this.alsoStashed(stashed));\n }\n return stashed;\n }\n\n private checkoutMain(repoRoot: string, untracked: UntrackedFiles): StashedFiles {\n const first = this.captureAndEcho(repoRoot, ['checkout', 'main']);\n if (first.succeeded()) return new StashedFiles([]);\n if (!this.isCollision(first, untracked)) throw this.checkoutFailed(first);\n\n const stash = this.captureAndEcho(repoRoot, ['stash', 'push', '-u',\n '-m', 'wp-sync-main: untracked files that collided with main']);\n if (!stash.succeeded()) {\n throw new CliExitError(1, `${SEP}❌ Could not check out main, and could not stash\\n${SEP}\\n`\n + 'git refused the checkout because untracked files in this tree sit at paths main\\n'\n + 'tracks, and `git stash -u` then failed too, so NOTHING WAS STASHED — the tree is\\n'\n + 'exactly as you left it and you are still on your branch. Both git messages are\\n'\n + 'above. Move or delete these files yourself, then re-run:\\n\\n'\n + this.list(untracked.paths));\n }\n\n const second = this.captureAndEcho(repoRoot, ['checkout', 'main']);\n const stashed = new StashedFiles(untracked.paths);\n if (!second.succeeded()) {\n throw new CliExitError(1, `${SEP}❌ Could not check out main even after stashing\\n${SEP}\\n`\n + 'The untracked files below WERE stashed — they are no longer in the working tree —\\n'\n + 'and git still refused the checkout, so something else is blocking it. Its message is\\n'\n + 'above. You are still on your branch. Recover the files with `git stash pop`, and\\n'\n + 'read git\\'s reason before re-running:\\n\\n'\n + this.list(stashed.paths));\n }\n return stashed;\n }\n\n /**\n * Only the collision git NAMES, and only when there is something a stash could actually take.\n * Untracked files with any other refusal, or a refusal with an empty untracked list, is a\n * different problem and stashing would be a guess.\n */\n private isCollision(run: GitRun, untracked: UntrackedFiles): boolean {\n return run.output.includes(WOULD_BE_OVERWRITTEN) && !untracked.isEmpty();\n }\n\n private checkoutFailed(run: GitRun): CliExitError {\n return new CliExitError(1, `${SEP}❌ Could not check out main\\n${SEP}\\n`\n + 'git refused the checkout for a reason this command does not resolve on your behalf — its\\n'\n + 'message is above and is the thing to read. The states that reach here:\\n\\n'\n + ' • a merge or rebase is in progress — finish it or `git merge --abort` / `git rebase\\n'\n + ' --abort`, then re-run\\n'\n + ' • unmerged paths from a conflict — resolve them and `git add` them, then re-run\\n'\n + ' • no local `main` and no `origin/main` to create it from — check `git remote -v`\\n\\n'\n + `git's output:\\n${run.output}`);\n }\n\n /** Appended to a failure that happens AFTER the stash, so the stash is never silently forgotten. */\n private alsoStashed(stashed: StashedFiles): string {\n if (stashed.isEmpty()) return '';\n return '\\nALSO: THESE UNTRACKED FILES WERE STASHED TO GET HERE — `git stash pop` RETURNS THEM:\\n\\n'\n + this.list(stashed.paths);\n }\n\n private list(paths: readonly string[]): string {\n return paths.map((path: string): string => ` ${path}\\n`).join('');\n }\n\n /** git piped, then echoed back verbatim — for the one command whose text is decided on. */\n private captureAndEcho(repoRoot: string, args: string[]): GitRun {\n const result = spawnSync('git', ['-C', repoRoot, ...args], {\n encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],\n });\n const stdout = result.stdout ?? '';\n const stderr = result.stderr ?? '';\n process.stdout.write(stdout);\n process.stderr.write(stderr);\n return new GitRun(result.status === null ? 1 : result.status, `${stdout}${stderr}`);\n }\n\n /** git with its output going straight to the terminal — for the commands whose progress is the point. */\n private passThrough(repoRoot: string, args: string[]): number {\n const result = spawnSync('git', ['-C', repoRoot, ...args], { encoding: 'utf8', stdio: 'inherit' });\n return result.status === null ? 1 : result.status;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"main-checkout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C,CAAC,IAAI,CAAC;IACxE,CAAC;CACJ,CAAA;AAjGY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEH,8BAAa;GADtC,YAAY,CAiGxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { CliExitError } from '@webpieces/rules-config';\nimport { GitProcessApi } from '@webpieces/tooling-common';\n\nimport { UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * git's own words for the one checkout failure this class is allowed to react to. Matched on git's\n * TEXT rather than re-derived from the untracked list on purpose: git's rules here cover\n * directory-vs-file collisions, sparse checkouts and case-insensitive filesystems, and any\n * re-derivation of them drifts from the git actually installed. git's refusal is the authority.\n */\nconst WOULD_BE_OVERWRITTEN = 'untracked working tree files would be overwritten';\n\n/** One git invocation's exit status and the output it produced, for a caller that must decide on it. */\nexport class GitRun {\n constructor(readonly status: number, readonly output: string) {}\n\n succeeded(): boolean {\n return this.status === 0;\n }\n}\n\n/**\n * The files `git stash -u` took so the checkout could proceed — carried out so the caller can SHOUT\n * about them. Empty is the overwhelmingly common case: nothing collided, nothing was stashed.\n *\n * The message is ALL CAPS and banner-wrapped deliberately. This is the one path in the command where\n * files that were sitting in the working tree are no longer sitting in the working tree, and a reader\n * who skims past that line loses track of their own work. Everything else this command prints is\n * routine; this is not.\n */\nexport class StashedFiles {\n constructor(readonly paths: readonly string[]) {}\n\n isEmpty(): boolean {\n return this.paths.length === 0;\n }\n\n /** The human-facing banner, or '' when nothing was stashed. */\n render(): string {\n if (this.isEmpty()) return '';\n const list = this.paths.map((path: string): string => ` ${path}\\n`).join('');\n const quoted = this.paths.map((path: string): string => `'${path}'`).join(' ');\n return `${SEP}⚠️ UNTRACKED FILES WERE STASHED BECAUSE THEY CONFLICTED\\n${SEP}\\n`\n + 'GIT REFUSED TO CHECK OUT MAIN: AN UNTRACKED FILE HERE SITS AT A PATH MAIN TRACKS, AND\\n'\n + 'THE CHECKOUT WOULD HAVE OVERWRITTEN IT. `git stash -u` TAKES EVERY UNTRACKED FILE, NOT\\n'\n + 'ONLY THE ONE THAT COLLIDED, SO ALL OF THESE LEFT THE WORKING TREE. THE CHECKOUT WAS THEN\\n'\n + 'RETRIED AND YOU ARE NOW ON A CLEAN MAIN. NOTHING WAS DELETED — YOUR VERSION OF EVERY\\n'\n + 'FILE BELOW IS IN THE STASH:\\n\\n'\n + list\n + '\\nGET THEM BACK WITH:\\n\\n'\n + ' git stash pop\\n\\n'\n + 'EXPECT THAT POP TO REFUSE THE FIRST TIME. IT LANDS ON THE NEW MAIN, WHICH IS EXACTLY\\n'\n + 'WHERE A COMMITTED COPY OF THE COLLIDING PATH NOW SITS — THAT COLLISION IS WHY ANY OF\\n'\n + 'THIS HAPPENED — SO GIT SAYS \"already exists, no checkout\" AND KEEPS THE STASH. TO TAKE\\n'\n + 'YOUR VERSIONS BACK, DELETE MAIN\\'S COPIES AND POP ONTO THE HOLE:\\n\\n'\n + ` rm -f ${quoted} && git stash pop\\n\\n`\n + 'NOTHING IS DISCARDED WHILE THE POP HAS NOT SUCCEEDED — `git stash list` STILL SHOWS THE\\n'\n + 'ENTRY, AS MANY TRIES AS YOU NEED. IF THE FILE IS GENERATED, REGENERATING IT ON THE NEW\\n'\n + 'MAIN IS USUALLY BETTER THAN RESTORING A COPY BUILT FROM THE OLD ONE.\\n\\n'\n + 'WHY STASHED AND NOT REFUSED: REACHING A CLEAN MAIN HAS TO STAY POSSIBLE. A REFUSAL HERE\\n'\n + 'DEADLOCKS ANYONE — HUMAN OR AGENT — WHOSE NEXT STEP IS GATED ON BEING ON MAIN, AND AN\\n'\n + `AGENT MID-UPGRADE CANNOT ASK FOR HELP.\\n${SEP}`;\n }\n}\n\n/**\n * Get onto a current main, whatever the working tree is holding.\n *\n * ─── WHY A COLLISION STASHES RATHER THAN REFUSES ──────────────────────────────────────────────────\n * `WorkingTreeGate` deliberately lets untracked files through: they are on no branch, so the switch\n * does not move them. That is true about the FILES and not true about the CHECKOUT — git aborts when\n * an untracked file sits at a path the destination branch TRACKS (\"The following untracked working\n * tree files would be overwritten by checkout\"). Letting untracked files reach the checkout is\n * exactly what makes that abort reachable, and the field case that produced it is the common one: a\n * generated `design.html`, untracked in a working clone because it is regenerated, and committed on\n * main.\n *\n * A refusal there is a DEAD END for the one caller that most needs the command to work — an agent\n * mid-upgrade of webpieces, unable to use its tools until it reaches a clean main, with nobody\n * watching to move the file for it. So the collision is resolved rather than reported: stash with\n * `-u`, retry, and then say so loudly enough that no human loses track of the files. Losing a minute\n * to a `git stash pop` beats a state nothing can get out of.\n *\n * ─── WHY THE CHECKOUT'S OUTPUT IS CAPTURED AND RE-PRINTED ─────────────────────────────────────────\n * The decision above is made on git's own refusal text, which means the checkout cannot run on\n * `stdio: 'inherit'` — inherited output is never seen by this process. It is piped and echoed back\n * instead, so the reader still gets every byte git wrote. `fetch` and `pull` stay inherited: nothing\n * is decided from their text, and they are the two that render live progress, which a pipe flattens.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class MainCheckout {\n constructor(private readonly git: GitProcessApi) {}\n\n /**\n * Fetch, check out main, fast-forward it. Returns the files that had to be stashed to get there —\n * empty in the ordinary case.\n *\n * `--ff-only` rather than a `reset --hard`, deliberately: a developer or an agent that\n * accidentally committed to local main would have that work silently destroyed by a reset, and\n * the whole point of this command is that it is safe to run without thinking. A refusal to\n * fast-forward is a real condition a human should see and decide about.\n */\n async goToMain(repoRoot: string, untracked: UntrackedFiles): Promise<StashedFiles> {\n await this.passThrough(repoRoot, ['fetch', 'origin', 'main']);\n const stashed = await this.checkoutMain(repoRoot, untracked);\n if (await this.passThrough(repoRoot, ['pull', '--ff-only', 'origin', 'main']) !== 0) {\n throw new CliExitError(1, `${SEP}❌ Local main could not fast-forward\\n${SEP}\\n`\n + 'Local main has commits that origin/main does not, so it is not a clean copy of the\\n'\n + 'remote. Nothing was reset — those commits may be the only copy. Inspect them with\\n'\n + '`git log origin/main..main` and decide what they are before going further.\\n'\n + this.alsoStashed(stashed));\n }\n return stashed;\n }\n\n private async checkoutMain(repoRoot: string, untracked: UntrackedFiles): Promise<StashedFiles> {\n const first = await this.captureAndEcho(repoRoot, ['checkout', 'main']);\n if (first.succeeded()) return new StashedFiles([]);\n if (!this.isCollision(first, untracked)) throw this.checkoutFailed(first);\n\n const stash = await this.captureAndEcho(repoRoot, ['stash', 'push', '-u',\n '-m', 'wp-sync-main: untracked files that collided with main']);\n if (!stash.succeeded()) {\n throw new CliExitError(1, `${SEP}❌ Could not check out main, and could not stash\\n${SEP}\\n`\n + 'git refused the checkout because untracked files in this tree sit at paths main\\n'\n + 'tracks, and `git stash -u` then failed too, so NOTHING WAS STASHED — the tree is\\n'\n + 'exactly as you left it and you are still on your branch. Both git messages are\\n'\n + 'above. Move or delete these files yourself, then re-run:\\n\\n'\n + this.list(untracked.paths));\n }\n\n const second = await this.captureAndEcho(repoRoot, ['checkout', 'main']);\n const stashed = new StashedFiles(untracked.paths);\n if (!second.succeeded()) {\n throw new CliExitError(1, `${SEP}❌ Could not check out main even after stashing\\n${SEP}\\n`\n + 'The untracked files below WERE stashed — they are no longer in the working tree —\\n'\n + 'and git still refused the checkout, so something else is blocking it. Its message is\\n'\n + 'above. You are still on your branch. Recover the files with `git stash pop`, and\\n'\n + 'read git\\'s reason before re-running:\\n\\n'\n + this.list(stashed.paths));\n }\n return stashed;\n }\n\n /**\n * Only the collision git NAMES, and only when there is something a stash could actually take.\n * Untracked files with any other refusal, or a refusal with an empty untracked list, is a\n * different problem and stashing would be a guess.\n */\n private isCollision(run: GitRun, untracked: UntrackedFiles): boolean {\n return run.output.includes(WOULD_BE_OVERWRITTEN) && !untracked.isEmpty();\n }\n\n private checkoutFailed(run: GitRun): CliExitError {\n return new CliExitError(1, `${SEP}❌ Could not check out main\\n${SEP}\\n`\n + 'git refused the checkout for a reason this command does not resolve on your behalf — its\\n'\n + 'message is above and is the thing to read. The states that reach here:\\n\\n'\n + ' • a merge or rebase is in progress — finish it or `git merge --abort` / `git rebase\\n'\n + ' --abort`, then re-run\\n'\n + ' • unmerged paths from a conflict — resolve them and `git add` them, then re-run\\n'\n + ' • no local `main` and no `origin/main` to create it from — check `git remote -v`\\n\\n'\n + `git's output:\\n${run.output}`);\n }\n\n /** Appended to a failure that happens AFTER the stash, so the stash is never silently forgotten. */\n private alsoStashed(stashed: StashedFiles): string {\n if (stashed.isEmpty()) return '';\n return '\\nALSO: THESE UNTRACKED FILES WERE STASHED TO GET HERE — `git stash pop` RETURNS THEM:\\n\\n'\n + this.list(stashed.paths);\n }\n\n private list(paths: readonly string[]): string {\n return paths.map((path: string): string => ` ${path}\\n`).join('');\n }\n\n /** git piped, then echoed back verbatim — for the one command whose text is decided on. */\n private async captureAndEcho(repoRoot: string, args: string[]): Promise<GitRun> {\n const result = await this.git.run(['-C', repoRoot, ...args]);\n process.stdout.write(result.stdout);\n process.stderr.write(result.stderr);\n return new GitRun(result.code, `${result.stdout}${result.stderr}`);\n }\n\n /** git with its output going straight to the terminal — for the commands whose progress is the point. */\n private async passThrough(repoRoot: string, args: string[]): Promise<number> {\n return (await this.git.passThrough(['-C', repoRoot, ...args])).code;\n }\n}\n"]}
|
|
@@ -71,29 +71,28 @@ let PushDevCommand = class PushDevCommand {
|
|
|
71
71
|
// A resolve already in flight owns the checkout; starting a second one would strand the first.
|
|
72
72
|
this.assertNoResolveInProgress(repoRoot);
|
|
73
73
|
if (opts.list) {
|
|
74
|
-
this.list(repoRoot, cfg);
|
|
75
|
-
return
|
|
74
|
+
await this.list(repoRoot, cfg);
|
|
75
|
+
return;
|
|
76
76
|
}
|
|
77
77
|
const branch = this.refs.currentBranch(repoRoot);
|
|
78
78
|
this.refs.assertPushable(cfg, branch);
|
|
79
79
|
const targetRef = cfg.copyRefFor(branch);
|
|
80
80
|
if (opts.remove) {
|
|
81
|
-
this.remove(repoRoot, cfg, branch, targetRef);
|
|
82
|
-
return
|
|
81
|
+
await this.remove(repoRoot, cfg, branch, targetRef);
|
|
82
|
+
return;
|
|
83
83
|
}
|
|
84
84
|
// Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing
|
|
85
85
|
// else. The tooling never commits for you.
|
|
86
|
-
this.gitExec.assertCleanTree(repoRoot);
|
|
86
|
+
await this.gitExec.assertCleanTree(repoRoot);
|
|
87
87
|
if (opts.resolve) {
|
|
88
|
-
this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);
|
|
89
|
-
return
|
|
88
|
+
await this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);
|
|
89
|
+
return;
|
|
90
90
|
}
|
|
91
|
-
this.publish(repoRoot, cfg, branch, targetRef, opts);
|
|
92
|
-
return Promise.resolve();
|
|
91
|
+
await this.publish(repoRoot, cfg, branch, targetRef, opts);
|
|
93
92
|
}
|
|
94
93
|
/** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
|
|
95
|
-
list(repoRoot, cfg) {
|
|
96
|
-
const copies = this.refs.liveCopies(repoRoot, cfg);
|
|
94
|
+
async list(repoRoot, cfg) {
|
|
95
|
+
const copies = await this.refs.liveCopies(repoRoot, cfg);
|
|
97
96
|
if (copies.length === 0) {
|
|
98
97
|
process.stdout.write(`\nNo dev copies published — nothing matches \`${cfg.copyRefGlob()}\` on origin.\n`
|
|
99
98
|
+ `Publish this branch's with: ${rules_config_1.WP_PUSH_DEV}\n`);
|
|
@@ -107,13 +106,13 @@ let PushDevCommand = class PushDevCommand {
|
|
|
107
106
|
process.stdout.write(out);
|
|
108
107
|
}
|
|
109
108
|
/** `--remove`: delete the remote copy. This IS the rollback — nothing else has to be undone. */
|
|
110
|
-
remove(repoRoot, cfg, branch, targetRef) {
|
|
111
|
-
if (this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
109
|
+
async remove(repoRoot, cfg, branch, targetRef) {
|
|
110
|
+
if (await this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
112
111
|
process.stdout.write(`\nNothing to remove — \`${targetRef}\` is not published.\n`
|
|
113
112
|
+ `List what IS published with: ${rules_config_1.WP_PUSH_DEV} --list\n`);
|
|
114
113
|
return;
|
|
115
114
|
}
|
|
116
|
-
this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`], `Failed to delete the dev copy ${targetRef}`);
|
|
115
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`], `Failed to delete the dev copy ${targetRef}`);
|
|
117
116
|
process.stdout.write('\n' + SEP + `🗑️ Removed ${targetRef}\n` + SEP + '\n'
|
|
118
117
|
+ `\`${branch}\` will drop out of \`${cfg.devBranch}\` on its next composition run. Your branch and any\n`
|
|
119
118
|
+ 'PR on it are untouched.\n');
|
|
@@ -127,22 +126,22 @@ let PushDevCommand = class PushDevCommand {
|
|
|
127
126
|
* default is refusal with two named ways forward — never a "use --force" one-liner, which is how a
|
|
128
127
|
* warning becomes a reflex.
|
|
129
128
|
*/
|
|
130
|
-
publish(repoRoot, cfg, branch, targetRef, opts) {
|
|
131
|
-
const remoteSha = this.refs.remoteSha(repoRoot, targetRef);
|
|
129
|
+
async publish(repoRoot, cfg, branch, targetRef, opts) {
|
|
130
|
+
const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);
|
|
132
131
|
if (remoteSha !== '') {
|
|
133
|
-
this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
134
|
-
const ahead = this.refs.commitsOnlyOnRemote(repoRoot, targetRef);
|
|
132
|
+
await this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
133
|
+
const ahead = await this.refs.commitsOnlyOnRemote(repoRoot, targetRef);
|
|
135
134
|
if (ahead > 0 && opts.rebaseResolution) {
|
|
136
|
-
this.rebaseResolution(repoRoot, branch, targetRef);
|
|
135
|
+
await this.rebaseResolution(repoRoot, branch, targetRef);
|
|
137
136
|
return;
|
|
138
137
|
}
|
|
139
138
|
if (ahead > 0 && !opts.force)
|
|
140
139
|
this.refuseClobber(cfg, branch, targetRef, ahead);
|
|
141
140
|
}
|
|
142
|
-
this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...this.pushSafety(targetRef, remoteSha, opts.force),
|
|
141
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...this.pushSafety(targetRef, remoteSha, opts.force),
|
|
143
142
|
'origin', `HEAD:refs/heads/${targetRef}`], `Failed to publish the dev copy ${targetRef}`);
|
|
144
143
|
// Read AFTER the push, so the sha in the watch hints is provably the one that is now published.
|
|
145
|
-
const published = this.refs.headSha(repoRoot);
|
|
144
|
+
const published = await this.refs.headSha(repoRoot);
|
|
146
145
|
process.stdout.write('\n' + SEP + `✅ Published ${targetRef}\n` + SEP + '\n'
|
|
147
146
|
+ `\`${branch}\` is now in the pool your CI composes \`${cfg.devBranch}\` from — it will be picked up on\n`
|
|
148
147
|
+ 'the next composition run. No PR was opened and nothing landed on main.\n\n'
|
|
@@ -157,12 +156,12 @@ let PushDevCommand = class PushDevCommand {
|
|
|
157
156
|
* replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as
|
|
158
157
|
* any other conflict, rather than inventing a second way to be stuck.
|
|
159
158
|
*/
|
|
160
|
-
rebaseResolution(repoRoot, branch, targetRef) {
|
|
159
|
+
async rebaseResolution(repoRoot, branch, targetRef) {
|
|
161
160
|
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);
|
|
162
161
|
process.stdout.write('\n' + SEP + `♻️ Replaying the published resolution onto \`${branch}\`\n` + SEP + '\n'
|
|
163
162
|
+ `Merging \`${targetRef}\` (which holds the resolution) into your new commits on a throwaway branch.\n`
|
|
164
163
|
+ `Your feature branch \`${branch}\` is not touched.\n\n`);
|
|
165
|
-
this.runner.start(repoRoot, state, 'HEAD', [targetRef]);
|
|
164
|
+
await this.runner.start(repoRoot, state, 'HEAD', [targetRef]);
|
|
166
165
|
}
|
|
167
166
|
/**
|
|
168
167
|
* `--resolve`: compose the other copies onto this one, so what is published is what CI will build.
|
|
@@ -171,13 +170,13 @@ let PushDevCommand = class PushDevCommand {
|
|
|
171
170
|
* local resolution is then a rehearsal of the real composition, not a guess at it. With an argument
|
|
172
171
|
* (the branch a CI conflict message names) it is just that one.
|
|
173
172
|
*/
|
|
174
|
-
startResolve(repoRoot, cfg, branch, targetRef, only) {
|
|
175
|
-
if (this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
173
|
+
async startResolve(repoRoot, cfg, branch, targetRef, only) {
|
|
174
|
+
if (await this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
176
175
|
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` is not published yet\n` + SEP + '\n'
|
|
177
176
|
+ 'There is nothing to compose against. Publish your copy first, then resolve:\n'
|
|
178
177
|
+ ` ${rules_config_1.WP_PUSH_DEV}\n ${rules_config_1.WP_PUSH_DEV} --resolve\n`);
|
|
179
178
|
}
|
|
180
|
-
const queue = this.resolveQueue(repoRoot, cfg, targetRef, only);
|
|
179
|
+
const queue = await this.resolveQueue(repoRoot, cfg, targetRef, only);
|
|
181
180
|
if (queue.length === 0) {
|
|
182
181
|
process.stdout.write(`\nNothing to compose — \`${targetRef}\` is the only copy in \`${cfg.copyRefGlob()}\`.\n`
|
|
183
182
|
+ `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\n`);
|
|
@@ -185,12 +184,12 @@ let PushDevCommand = class PushDevCommand {
|
|
|
185
184
|
}
|
|
186
185
|
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);
|
|
187
186
|
process.stdout.write(this.runner.announce(cfg, state));
|
|
188
|
-
this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);
|
|
187
|
+
await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);
|
|
189
188
|
}
|
|
190
189
|
// The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with
|
|
191
190
|
// or without the namespace prefix, because the CI message that names it may print either.
|
|
192
|
-
resolveQueue(repoRoot, cfg, targetRef, only) {
|
|
193
|
-
const copies = this.refs.liveCopies(repoRoot, cfg);
|
|
191
|
+
async resolveQueue(repoRoot, cfg, targetRef, only) {
|
|
192
|
+
const copies = await this.refs.liveCopies(repoRoot, cfg);
|
|
194
193
|
if (only === '') {
|
|
195
194
|
return copies.filter((c) => c.ref !== targetRef).map((c) => c.ref);
|
|
196
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/push-dev-command.ts"],"names":[],"mappings":";;;;AAAA,0DAOiC;AACjC,yCAA2D;AAE3D,mDAA+C;AAC/C,iEAAqE;AACrE,+DAA6E;AAC7E,uEAAkE;AAClE,+EAAyE;AAEzE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;GAGG;AACH,MAAa,cAAc;IACvB,6CAA6C;IAC7C,MAAM,GAAG,KAAK,CAAC;IACf,sFAAsF;IACtF,IAAI,GAAG,KAAK,CAAC;IACb,qFAAqF;IACrF,KAAK,GAAG,KAAK,CAAC;IACd,uFAAuF;IACvF,gBAAgB,GAAG,KAAK,CAAC;IACzB,gGAAgG;IAChG,OAAO,GAAG,KAAK,CAAC;IAChB,sFAAsF;IACtF,aAAa,GAAG,EAAE,CAAC;CACtB;AAbD,wCAaC;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAEF;IACA;IACA;IACA;IACA;IACA;IANrB,YACqB,cAA8B,EAC9B,OAAgB,EAChB,IAAmB,EACnB,KAAwB,EACxB,MAAwB,EACxB,UAA+B;QAL/B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAe;QACnB,UAAK,GAA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liExitError,\n DevDeployConfig,\n RepoRootFinder,\n WP_FINISH_PUSH_DEV,\n WP_PUSH_DEV,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevCopy, DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from '../workflow/push-dev-state';\nimport { DevResolveRunner } from '../workflow/dev-resolve-runner';\nimport { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields\n * rather than a seven-argument constructor — the bin sets what argv carried and nothing else.\n */\nexport class PushDevOptions {\n /** Delete the remote copy — the rollback. */\n remove = false;\n /** List the live copies and stop. The one mode that needs no branch preconditions. */\n list = false;\n /** Discard a conflict resolution already published on the copy, and overwrite it. */\n force = false;\n /** Replay that resolution on top of the new local commits instead of discarding it. */\n rebaseResolution = false;\n /** Compose the other copies onto this one so the shared environment can build them together. */\n resolve = false;\n /** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */\n resolveTarget = '';\n}\n\n/**\n * `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,\n * without landing anything on `main` and without opening a PR.\n *\n * WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no\n * exceptions, by design. Its own fix-hint offers \"ask a human to run the push\" for out-of-band cases —\n * which is the right answer for a genuine exception and the wrong one for a routine daily action. Without\n * a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the\n * feature was undoable rather than merely awkward.\n *\n * WHY THERE IS NO BUILD, deliberately unlike `wp-start-upsert-pr`: the shared environment's CI builds the\n * COMPOSED tree (main + every listed branch). A local build here proves the branch compiles against\n * `main` alone, which is not the question — it would be both slower and reassuring about the wrong thing.\n * The gate that matters runs on the composition, in CI, where it belongs.\n *\n * WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy\n * exists to hold conflict resolutions that must not reach the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly runner: DevResolveRunner,\n private readonly watchHints: DevDeployWatchHints,\n ) {}\n\n async run(opts: PushDevOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it is present + current for any failure message to cite —\n // same reason every other wp-* command opens this way.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n\n // A resolve already in flight owns the checkout; starting a second one would strand the first.\n this.assertNoResolveInProgress(repoRoot);\n\n if (opts.list) {\n this.list(repoRoot, cfg);\n return Promise.resolve();\n }\n\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n const targetRef = cfg.copyRefFor(branch);\n\n if (opts.remove) {\n this.remove(repoRoot, cfg, branch, targetRef);\n return Promise.resolve();\n }\n // Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing\n // else. The tooling never commits for you.\n this.gitExec.assertCleanTree(repoRoot);\n\n if (opts.resolve) {\n this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);\n return Promise.resolve();\n }\n this.publish(repoRoot, cfg, branch, targetRef, opts);\n return Promise.resolve();\n }\n\n /** `--list`: exactly the live copies, straight from the remote — never a cached local view. */\n private list(repoRoot: string, cfg: DevDeployConfig): void {\n const copies = this.refs.liveCopies(repoRoot, cfg);\n if (copies.length === 0) {\n process.stdout.write(\n `\\nNo dev copies published — nothing matches \\`${cfg.copyRefGlob()}\\` on origin.\\n`\n + `Publish this branch's with: ${WP_PUSH_DEV}\\n`);\n return;\n }\n let out = '\\n' + SEP + `📋 ${String(copies.length)} dev cop${copies.length === 1 ? 'y' : 'ies'} on origin\\n` + SEP + '\\n';\n for (const copy of copies) out += ` ${copy.sha.slice(0, 8)} ${copy.ref}\\n`;\n out += `\\nYour CI composes \\`${cfg.devBranch}\\` from origin/main plus every ref above, on every run.\\n`\n + `Remove yours with: ${WP_PUSH_DEV} --remove\\n`;\n process.stdout.write(out);\n }\n\n /** `--remove`: delete the remote copy. This IS the rollback — nothing else has to be undone. */\n private remove(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string): void {\n if (this.refs.remoteSha(repoRoot, targetRef) === '') {\n process.stdout.write(\n `\\nNothing to remove — \\`${targetRef}\\` is not published.\\n`\n + `List what IS published with: ${WP_PUSH_DEV} --list\\n`);\n return;\n }\n this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`],\n `Failed to delete the dev copy ${targetRef}`);\n process.stdout.write(\n '\\n' + SEP + `🗑️ Removed ${targetRef}\\n` + SEP + '\\n'\n + `\\`${branch}\\` will drop out of \\`${cfg.devBranch}\\` on its next composition run. Your branch and any\\n`\n + 'PR on it are untouched.\\n');\n }\n\n /**\n * The ordinary path: publish HEAD as `<namespace>/<branch>`.\n *\n * THE CLOBBER GUARD is the whole of the interesting logic here. If the remote copy holds commits the\n * local branch does not, somebody (quite possibly this developer, days ago) resolved a real conflict\n * over there. A silent force-push destroys work that cost a human a genuine merge resolution, so the\n * default is refusal with two named ways forward — never a \"use --force\" one-liner, which is how a\n * warning becomes a reflex.\n */\n private publish(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, opts: PushDevOptions): void {\n const remoteSha = this.refs.remoteSha(repoRoot, targetRef);\n if (remoteSha !== '') {\n this.refs.fetchCopies(repoRoot, [targetRef]);\n const ahead = this.refs.commitsOnlyOnRemote(repoRoot, targetRef);\n if (ahead > 0 && opts.rebaseResolution) {\n this.rebaseResolution(repoRoot, branch, targetRef);\n return;\n }\n if (ahead > 0 && !opts.force) this.refuseClobber(cfg, branch, targetRef, ahead);\n }\n this.gitExec.runGitChecked(\n ['-C', repoRoot, 'push', ...this.pushSafety(targetRef, remoteSha, opts.force),\n 'origin', `HEAD:refs/heads/${targetRef}`],\n `Failed to publish the dev copy ${targetRef}`);\n // Read AFTER the push, so the sha in the watch hints is provably the one that is now published.\n const published = this.refs.headSha(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${targetRef}\\n` + SEP + '\\n'\n + `\\`${branch}\\` is now in the pool your CI composes \\`${cfg.devBranch}\\` from — it will be picked up on\\n`\n + 'the next composition run. No PR was opened and nothing landed on main.\\n\\n'\n + ` ${WP_PUSH_DEV} --list ← what else is in the pool\\n`\n + ` ${WP_PUSH_DEV} --remove ← take this branch back out\\n`\n + this.watchHints.render(cfg, targetRef, published));\n }\n\n /**\n * `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.\n *\n * Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a\n * replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as\n * any other conflict, rather than inventing a second way to be stuck.\n */\n private rebaseResolution(repoRoot: string, branch: string, targetRef: string): void {\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);\n process.stdout.write(\n '\\n' + SEP + `♻️ Replaying the published resolution onto \\`${branch}\\`\\n` + SEP + '\\n'\n + `Merging \\`${targetRef}\\` (which holds the resolution) into your new commits on a throwaway branch.\\n`\n + `Your feature branch \\`${branch}\\` is not touched.\\n\\n`);\n this.runner.start(repoRoot, state, 'HEAD', [targetRef]);\n }\n\n /**\n * `--resolve`: compose the other copies onto this one, so what is published is what CI will build.\n *\n * With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the\n * local resolution is then a rehearsal of the real composition, not a guess at it. With an argument\n * (the branch a CI conflict message names) it is just that one.\n */\n private startResolve(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, only: string): void {\n if (this.refs.remoteSha(repoRoot, targetRef) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` is not published yet\\n` + SEP + '\\n'\n + 'There is nothing to compose against. Publish your copy first, then resolve:\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --resolve\\n`);\n }\n const queue = this.resolveQueue(repoRoot, cfg, targetRef, only);\n if (queue.length === 0) {\n process.stdout.write(\n `\\nNothing to compose — \\`${targetRef}\\` is the only copy in \\`${cfg.copyRefGlob()}\\`.\\n`\n + `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\\n`);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);\n process.stdout.write(this.runner.announce(cfg, state));\n this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);\n }\n\n // The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with\n // or without the namespace prefix, because the CI message that names it may print either.\n private resolveQueue(repoRoot: string, cfg: DevDeployConfig, targetRef: string, only: string): string[] {\n const copies = this.refs.liveCopies(repoRoot, cfg);\n if (only === '') {\n return copies.filter((c: DevCopy): boolean => c.ref !== targetRef).map((c: DevCopy): string => c.ref);\n }\n const wanted = only.startsWith(`${cfg.branchNamespace}/`) ? only : cfg.copyRefFor(only);\n if (wanted === targetRef) {\n throw new CliExitError(2, `\\n⛔ \\`${only}\\` is your own copy — there is nothing to compose it with.\\n`);\n }\n if (!copies.some((c: DevCopy): boolean => c.ref === wanted)) {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ No published copy \\`${wanted}\\`\\n` + SEP + '\\n'\n + `Live copies (${WP_PUSH_DEV} --list):\\n`\n + copies.map((c: DevCopy): string => ` ${c.ref}`).join('\\n') + '\\n');\n }\n return [wanted];\n }\n\n /**\n * `--force-with-lease` pinned to the sha we just inspected, so the clobber guard's verdict cannot go\n * stale between the check and the push. Plain `--force` only when the caller explicitly asked to\n * discard, and no force at all for a brand-new copy.\n */\n private pushSafety(targetRef: string, remoteSha: string, force: boolean): string[] {\n if (remoteSha === '') return [];\n if (force) return ['--force'];\n return [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];\n }\n\n private refuseClobber(cfg: DevDeployConfig, branch: string, targetRef: string, ahead: number): never {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` holds ${String(ahead)} commit(s) your branch does not\\n` + SEP + '\\n'\n + 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\\n'\n + `developer's branch so \\`${cfg.devBranch}\\` could build, and that work exists ONLY on the copy —\\n`\n + 'by design, because it must never reach your feature branch or your PR.\\n\\n'\n + 'Publishing now would force-push over it and destroy it, so this command refuses. Pick one:\\n\\n'\n + ` ${WP_PUSH_DEV} --rebase-resolution\\n`\n + ' Replay that resolution on top of your new commits. Keeps the work; may ask you to\\n'\n + ' re-resolve the parts your new commits actually changed.\\n\\n'\n + ` ${WP_PUSH_DEV} --force\\n`\n + ' Discard it and publish your branch as-is. The composition breaks again until someone\\n'\n + ` re-resolves it with \\`${WP_PUSH_DEV} --resolve\\`.\\n\\n`\n + `See what is on the copy: git log --oneline ${branch}..refs/remotes/origin/${targetRef}\\n`);\n }\n\n // A half-finished resolve owns the checkout — it is parked on a throwaway branch, so \"the current\n // branch\" is not the feature branch this command would otherwise act on.\n private assertNoResolveInProgress(repoRoot: string): void {\n const state = this.store.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ A dev-deploy resolve is already in progress\\n' + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\`, mid-composition. Finish it or bail out:\\n`\n + ` ${WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"push-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/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;cAChG,KAAK,0BAAW,wBAAwB;cACxC,2FAA2F;cAC3F,mEAAmE;cACnE,KAAK,0BAAW,YAAY;cAC5B,8FAA8F;cAC9F,+BAA+B,0BAAW,mBAAmB;cAC7D,+CAA+C,MAAM,yBAAyB,SAAS,IAAI,CAAC,CAAC;IACvG,CAAC;IAED,kGAAkG;IAClG,yEAAyE;IACjE,yBAAyB,CAAC,QAAgB;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO;QAC3B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,iDAAiD,GAAG,GAAG,GAAG,IAAI;cACzE,qCAAqC,KAAK,CAAC,SAAS,+CAA+C;cACnG,KAAK,iCAAkB,kEAAkE;cACzF,KAAK,iCAAkB,gDAAgD,KAAK,CAAC,cAAc,MAAM,CAAC,CAAC;IAC7G,CAAC;CACJ,CAAA;AAnNY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QAChB,qCAAgB;QACZ,4CAAmB;GAP3C,cAAc,CAmN1B","sourcesContent":["import {\n CliExitError,\n DevDeployConfig,\n RepoRootFinder,\n WP_FINISH_PUSH_DEV,\n WP_PUSH_DEV,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevCopy, DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from '../workflow/push-dev-state';\nimport { DevResolveRunner } from '../workflow/dev-resolve-runner';\nimport { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields\n * rather than a seven-argument constructor — the bin sets what argv carried and nothing else.\n */\nexport class PushDevOptions {\n /** Delete the remote copy — the rollback. */\n remove = false;\n /** List the live copies and stop. The one mode that needs no branch preconditions. */\n list = false;\n /** Discard a conflict resolution already published on the copy, and overwrite it. */\n force = false;\n /** Replay that resolution on top of the new local commits instead of discarding it. */\n rebaseResolution = false;\n /** Compose the other copies onto this one so the shared environment can build them together. */\n resolve = false;\n /** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */\n resolveTarget = '';\n}\n\n/**\n * `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,\n * without landing anything on `main` and without opening a PR.\n *\n * WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no\n * exceptions, by design. Its own fix-hint offers \"ask a human to run the push\" for out-of-band cases —\n * which is the right answer for a genuine exception and the wrong one for a routine daily action. Without\n * a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the\n * feature was undoable rather than merely awkward.\n *\n * WHY THERE IS NO BUILD, deliberately unlike `wp-start-upsert-pr`: the shared environment's CI builds the\n * COMPOSED tree (main + every listed branch). A local build here proves the branch compiles against\n * `main` alone, which is not the question — it would be both slower and reassuring about the wrong thing.\n * The gate that matters runs on the composition, in CI, where it belongs.\n *\n * WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy\n * exists to hold conflict resolutions that must not reach the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly runner: DevResolveRunner,\n private readonly watchHints: DevDeployWatchHints,\n ) {}\n\n async run(opts: PushDevOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it is present + current for any failure message to cite —\n // same reason every other wp-* command opens this way.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n\n // A resolve already in flight owns the checkout; starting a second one would strand the first.\n this.assertNoResolveInProgress(repoRoot);\n\n if (opts.list) {\n await this.list(repoRoot, cfg);\n return;\n }\n\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n const targetRef = cfg.copyRefFor(branch);\n\n if (opts.remove) {\n await this.remove(repoRoot, cfg, branch, targetRef);\n return;\n }\n // Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing\n // else. The tooling never commits for you.\n await this.gitExec.assertCleanTree(repoRoot);\n\n if (opts.resolve) {\n await this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);\n return;\n }\n await this.publish(repoRoot, cfg, branch, targetRef, opts);\n }\n\n /** `--list`: exactly the live copies, straight from the remote — never a cached local view. */\n private async list(repoRoot: string, cfg: DevDeployConfig): Promise<void> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (copies.length === 0) {\n process.stdout.write(\n `\\nNo dev copies published — nothing matches \\`${cfg.copyRefGlob()}\\` on origin.\\n`\n + `Publish this branch's with: ${WP_PUSH_DEV}\\n`);\n return;\n }\n let out = '\\n' + SEP + `📋 ${String(copies.length)} dev cop${copies.length === 1 ? 'y' : 'ies'} on origin\\n` + SEP + '\\n';\n for (const copy of copies) out += ` ${copy.sha.slice(0, 8)} ${copy.ref}\\n`;\n out += `\\nYour CI composes \\`${cfg.devBranch}\\` from origin/main plus every ref above, on every run.\\n`\n + `Remove yours with: ${WP_PUSH_DEV} --remove\\n`;\n process.stdout.write(out);\n }\n\n /** `--remove`: delete the remote copy. This IS the rollback — nothing else has to be undone. */\n private async remove(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n process.stdout.write(\n `\\nNothing to remove — \\`${targetRef}\\` is not published.\\n`\n + `List what IS published with: ${WP_PUSH_DEV} --list\\n`);\n return;\n }\n await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`],\n `Failed to delete the dev copy ${targetRef}`);\n process.stdout.write(\n '\\n' + SEP + `🗑️ Removed ${targetRef}\\n` + SEP + '\\n'\n + `\\`${branch}\\` will drop out of \\`${cfg.devBranch}\\` on its next composition run. Your branch and any\\n`\n + 'PR on it are untouched.\\n');\n }\n\n /**\n * The ordinary path: publish HEAD as `<namespace>/<branch>`.\n *\n * THE CLOBBER GUARD is the whole of the interesting logic here. If the remote copy holds commits the\n * local branch does not, somebody (quite possibly this developer, days ago) resolved a real conflict\n * over there. A silent force-push destroys work that cost a human a genuine merge resolution, so the\n * default is refusal with two named ways forward — never a \"use --force\" one-liner, which is how a\n * warning becomes a reflex.\n */\n private async publish(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, opts: PushDevOptions): Promise<void> {\n const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);\n if (remoteSha !== '') {\n await this.refs.fetchCopies(repoRoot, [targetRef]);\n const ahead = await this.refs.commitsOnlyOnRemote(repoRoot, targetRef);\n if (ahead > 0 && opts.rebaseResolution) {\n await this.rebaseResolution(repoRoot, branch, targetRef);\n return;\n }\n if (ahead > 0 && !opts.force) this.refuseClobber(cfg, branch, targetRef, ahead);\n }\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'push', ...this.pushSafety(targetRef, remoteSha, opts.force),\n 'origin', `HEAD:refs/heads/${targetRef}`],\n `Failed to publish the dev copy ${targetRef}`);\n // Read AFTER the push, so the sha in the watch hints is provably the one that is now published.\n const published = await this.refs.headSha(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${targetRef}\\n` + SEP + '\\n'\n + `\\`${branch}\\` is now in the pool your CI composes \\`${cfg.devBranch}\\` from — it will be picked up on\\n`\n + 'the next composition run. No PR was opened and nothing landed on main.\\n\\n'\n + ` ${WP_PUSH_DEV} --list ← what else is in the pool\\n`\n + ` ${WP_PUSH_DEV} --remove ← take this branch back out\\n`\n + this.watchHints.render(cfg, targetRef, published));\n }\n\n /**\n * `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.\n *\n * Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a\n * replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as\n * any other conflict, rather than inventing a second way to be stuck.\n */\n private async rebaseResolution(repoRoot: string, branch: string, targetRef: string): Promise<void> {\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);\n process.stdout.write(\n '\\n' + SEP + `♻️ Replaying the published resolution onto \\`${branch}\\`\\n` + SEP + '\\n'\n + `Merging \\`${targetRef}\\` (which holds the resolution) into your new commits on a throwaway branch.\\n`\n + `Your feature branch \\`${branch}\\` is not touched.\\n\\n`);\n await this.runner.start(repoRoot, state, 'HEAD', [targetRef]);\n }\n\n /**\n * `--resolve`: compose the other copies onto this one, so what is published is what CI will build.\n *\n * With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the\n * local resolution is then a rehearsal of the real composition, not a guess at it. With an argument\n * (the branch a CI conflict message names) it is just that one.\n */\n private async startResolve(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, only: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` is not published yet\\n` + SEP + '\\n'\n + 'There is nothing to compose against. Publish your copy first, then resolve:\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --resolve\\n`);\n }\n const queue = await this.resolveQueue(repoRoot, cfg, targetRef, only);\n if (queue.length === 0) {\n process.stdout.write(\n `\\nNothing to compose — \\`${targetRef}\\` is the only copy in \\`${cfg.copyRefGlob()}\\`.\\n`\n + `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\\n`);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);\n process.stdout.write(this.runner.announce(cfg, state));\n await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);\n }\n\n // The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with\n // or without the namespace prefix, because the CI message that names it may print either.\n private async resolveQueue(repoRoot: string, cfg: DevDeployConfig, targetRef: string, only: string): Promise<string[]> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (only === '') {\n return copies.filter((c: DevCopy): boolean => c.ref !== targetRef).map((c: DevCopy): string => c.ref);\n }\n const wanted = only.startsWith(`${cfg.branchNamespace}/`) ? only : cfg.copyRefFor(only);\n if (wanted === targetRef) {\n throw new CliExitError(2, `\\n⛔ \\`${only}\\` is your own copy — there is nothing to compose it with.\\n`);\n }\n if (!copies.some((c: DevCopy): boolean => c.ref === wanted)) {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ No published copy \\`${wanted}\\`\\n` + SEP + '\\n'\n + `Live copies (${WP_PUSH_DEV} --list):\\n`\n + copies.map((c: DevCopy): string => ` ${c.ref}`).join('\\n') + '\\n');\n }\n return [wanted];\n }\n\n /**\n * `--force-with-lease` pinned to the sha we just inspected, so the clobber guard's verdict cannot go\n * stale between the check and the push. Plain `--force` only when the caller explicitly asked to\n * discard, and no force at all for a brand-new copy.\n */\n private pushSafety(targetRef: string, remoteSha: string, force: boolean): string[] {\n if (remoteSha === '') return [];\n if (force) return ['--force'];\n return [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];\n }\n\n private refuseClobber(cfg: DevDeployConfig, branch: string, targetRef: string, ahead: number): never {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` holds ${String(ahead)} commit(s) your branch does not\\n` + SEP + '\\n'\n + 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\\n'\n + `developer's branch so \\`${cfg.devBranch}\\` could build, and that work exists ONLY on the copy —\\n`\n + 'by design, because it must never reach your feature branch or your PR.\\n\\n'\n + 'Publishing now would force-push over it and destroy it, so this command refuses. Pick one:\\n\\n'\n + ` ${WP_PUSH_DEV} --rebase-resolution\\n`\n + ' Replay that resolution on top of your new commits. Keeps the work; may ask you to\\n'\n + ' re-resolve the parts your new commits actually changed.\\n\\n'\n + ` ${WP_PUSH_DEV} --force\\n`\n + ' Discard it and publish your branch as-is. The composition breaks again until someone\\n'\n + ` re-resolves it with \\`${WP_PUSH_DEV} --resolve\\`.\\n\\n`\n + `See what is on the copy: git log --oneline ${branch}..refs/remotes/origin/${targetRef}\\n`);\n }\n\n // A half-finished resolve owns the checkout — it is parked on a throwaway branch, so \"the current\n // branch\" is not the feature branch this command would otherwise act on.\n private assertNoResolveInProgress(repoRoot: string): void {\n const state = this.store.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ A dev-deploy resolve is already in progress\\n' + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\`, mid-composition. Finish it or bail out:\\n`\n + ` ${WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n`);\n }\n}\n"]}
|
|
@@ -48,16 +48,15 @@ let ReapWorktreeCommand = class ReapWorktreeCommand {
|
|
|
48
48
|
* remove". The token is the last thing written, and LandedWorktreeReaper strips it before printing.
|
|
49
49
|
*/
|
|
50
50
|
async run(args) {
|
|
51
|
-
await Promise.resolve();
|
|
52
51
|
const request = this.parse(args);
|
|
53
52
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
54
|
-
const target = this.resolveTarget(repoRoot, request);
|
|
53
|
+
const target = await this.resolveTarget(repoRoot, request);
|
|
55
54
|
if (target === null) {
|
|
56
55
|
process.stdout.write(this.signal.line(reap_outcome_1.REAP_OUTCOME_REFUSED));
|
|
57
56
|
return;
|
|
58
57
|
}
|
|
59
58
|
const retention = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.landPr.branchRetention;
|
|
60
|
-
const result = this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);
|
|
59
|
+
const result = await this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);
|
|
61
60
|
process.stdout.write(this.render(repoRoot, result));
|
|
62
61
|
process.stdout.write(this.signal.line(this.outcomeOf(result)));
|
|
63
62
|
}
|
|
@@ -77,11 +76,11 @@ let ReapWorktreeCommand = class ReapWorktreeCommand {
|
|
|
77
76
|
* successful landing would report a landed PR as a failed command. That is exactly why `run` also
|
|
78
77
|
* emits a ReapOutcomeSignal — the caller must be able to tell this exit 0 from a successful one.
|
|
79
78
|
*/
|
|
80
|
-
resolveTarget(repoRoot, request) {
|
|
79
|
+
async resolveTarget(repoRoot, request) {
|
|
81
80
|
const wanted = path.resolve(request.worktreePath);
|
|
82
81
|
// `false`: this reaps ONE named worktree after its PR landed, and it is not the place to
|
|
83
82
|
// override anybody's lock — a lock still standing here is exactly the refusal this prints.
|
|
84
|
-
const target = this.worktreeSection.verdicts(repoRoot, false)
|
|
83
|
+
const target = (await this.worktreeSection.verdicts(repoRoot, false))
|
|
85
84
|
.find((tree) => path.resolve(tree.path) === wanted);
|
|
86
85
|
if (target === undefined) {
|
|
87
86
|
process.stdout.write(`\n ℹ️ ${request.worktreePath} is not a removable worktree of this repo (it may be the\n`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reap-worktree-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/reap-worktree-command.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAC7B,sEAAiH;AACjH,8DAA0D;AAC1D,0DAA0E;AAC1E,yCAA2D;AAE3D,2DAKkC;AAElC,yDAA4D;AAE5D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAm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GAAG,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,IAAc;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,YAAY,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACtD,MAAM,IAAI,8BAAa,CACnB,IAAI,GAAG,GAAG,GAAG,yCAAyC,GAAG,GAAG,GAAG,IAAI;kBACjE,yEAAyE;kBACzE,qFAAqF;kBACrF,qFAAqF,GAAG,GAAG,CAAC,CAAC;QACvG,CAAC;QACD,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAlIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACb,yCAAsB;QAC/B,gCAAiB;QACd,oCAAe;GALtC,mBAAmB,CAkI/B;AAED,uFAAuF;AACvF,MAAM,WAAW;IACb,YAAY,CAAS;IACrB,MAAM,CAAS;IACf,2FAA2F;IAC3F,IAAI,CAAS;IAEb,YAAY,YAAoB,EAAE,MAAc,EAAE,IAAY;QAC1D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ","sourcesContent":["import * as path from 'path';\nimport { DeletableWorktree, Worktree, WorktreeReapResult, WorktreeService } from '@webpieces/repo-workflow-core';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { RepoRootFinder, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport {\n ReapOutcomeSignal,\n REAP_OUTCOME_FAILED,\n REAP_OUTCOME_REFUSED,\n REAP_OUTCOME_REMOVED,\n} from '../workflow/reap-outcome';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The CHILD side of `wp-land-pr`'s re-exec: reap ONE named worktree, from a process whose cwd is the\n * primary clone.\n *\n * It is not a published `bin`. Nothing about it is a verb a human should reach for — `pnpm wp-cleanup`\n * is that verb, and it does strictly more. This exists so the parent can hand off a SINGLE, already\n * identified corpse without also reaping every other agent's worktree as a side effect of landing one\n * PR. LandedWorktreeReaper spawns it by absolute path; see that class for why a child rather than a\n * `process.chdir`.\n *\n * WHAT IT WILL NOT TAKE ON TRUST. The parent tells it a path, a branch and the HEAD sha it selected the\n * tree by; it believes none of the three.\n * The verdict is recomputed here, from scratch, by the same MergedBranchesService that backs\n * `wp-cleanup` — so a worktree is removed only when it is PROVABLY dead (its PR is merged), and never\n * because a caller said so. That is what keeps \"never remove a tree still holding unmerged work\" true\n * even if the parent is wrong, out of date, or someone runs this by hand.\n *\n * The primary clone can never be a target: `classifyWorktrees` drops the main worktree from the\n * verdicts outright, so a path pointing at it simply does not resolve to a target — and WorktreeReaper\n * refuses it a second time by name. Neither rail is load-bearing alone.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReapWorktreeCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly worktreeSection: WorktreeCleanupSection,\n private readonly signal: ReapOutcomeSignal,\n private readonly worktrees: WorktreeService,\n ) {}\n\n /**\n * Every exit from here states an OUTCOME, because the exit code cannot: refusals exit 0 (see\n * `resolveTarget`), so a parent with only a status has no way to tell \"removed\" from \"declined to\n * remove\". The token is the last thing written, and LandedWorktreeReaper strips it before printing.\n */\n async run(args: string[]): Promise<void> {\n await Promise.resolve();\n const request = this.parse(args);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const target = this.resolveTarget(repoRoot, request);\n if (target === null) {\n process.stdout.write(this.signal.line(REAP_OUTCOME_REFUSED));\n return;\n }\n\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n const result = this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);\n process.stdout.write(this.render(repoRoot, result));\n process.stdout.write(this.signal.line(this.outcomeOf(result)));\n }\n\n /**\n * `reaped` is the only entry that means the DIRECTORY is gone. A tree that reached the reaper and\n * came back in neither list was spared by one of WorktreeReaper's own rails (it is the cwd, it is\n * the primary clone) — nothing was attempted, which is a refusal, not a failure.\n */\n private outcomeOf(result: WorktreeReapResult): string {\n if (result.reaped.length > 0) return REAP_OUTCOME_REMOVED;\n return result.failed.length > 0 ? REAP_OUTCOME_FAILED : REAP_OUTCOME_REFUSED;\n }\n\n /**\n * The verdict for the requested path, or null after printing WHY it is not reapable. Refusals are\n * printed rather than thrown: the PR they follow is already merged, and exiting non-zero after a\n * successful landing would report a landed PR as a failed command. That is exactly why `run` also\n * emits a ReapOutcomeSignal — the caller must be able to tell this exit 0 from a successful one.\n */\n private resolveTarget(repoRoot: string, request: ReapRequest): DeletableWorktree | null {\n const wanted = path.resolve(request.worktreePath);\n // `false`: this reaps ONE named worktree after its PR landed, and it is not the place to\n // override anybody's lock — a lock still standing here is exactly the refusal this prints.\n const target = this.worktreeSection.verdicts(repoRoot, false)\n .find((tree: DeletableWorktree): boolean => path.resolve(tree.path) === wanted);\n\n if (target === undefined) {\n process.stdout.write(\n `\\n ℹ️ ${request.worktreePath} is not a removable worktree of this repo (it may be the\\n`\n + ' primary clone, or already gone). Nothing removed.\\n');\n return null;\n }\n // The branch moved under us between landing and reaping — somebody checked something else out\n // there. Whatever that is, it is not the corpse we were asked to bury.\n if (target.branch !== request.branch) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} now holds '${target.branch}', not '${request.branch}'.\\n`\n + ' Refusing to remove a worktree whose branch changed since the PR landed.\\n');\n return null;\n }\n // …and the NAME is not the identity. The parent selected this directory because its HEAD was the\n // exact commit GitHub squashed; that selection is recomputed here from git rather than taken on\n // trust, so a commit made in that tree between landing and reaping — work the archive tag of the\n // squashed tip does not contain — stops the removal instead of being buried with it.\n const here = this.headOf(repoRoot, wanted);\n if (here !== request.head) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is at ${here === '' ? '(unknown)' : here}, not the landed\\n`\n + ` commit ${request.head}.\\n`\n + ' Refusing to remove a worktree whose HEAD moved since the PR landed.\\n');\n return null;\n }\n if (!target.deletable) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is not provably dead: ${target.reason}\\n`\n + ' Refusing to remove a worktree that may still hold unmerged work.\\n');\n return null;\n }\n return target;\n }\n\n /**\n * That worktree's HEAD as git reports it right now, '' when git cannot place the path at all.\n * '' can never equal a real sha, so \"git would not answer\" fails SAFE — it declines the removal.\n */\n private headOf(repoRoot: string, resolvedPath: string): string {\n const tree = this.worktrees.listWorktrees(repoRoot)\n .find((candidate: Worktree): boolean => path.resolve(candidate.path) === resolvedPath);\n return tree?.head ?? '';\n }\n\n // The reap report, plus the spared case — which report() renders as '' because from wp-cleanup's\n // point of view \"nothing happened\" is a whole answer. Here it never is: we asked for exactly one.\n private render(repoRoot: string, result: WorktreeReapResult): string {\n if (result.reaped.length === 0 && result.failed.length === 0) {\n let out = '\\n' + SEP + '🛑 Nothing removed\\n' + SEP + '\\n';\n for (const tree of result.spared) out += ` · ${tree.path} — ${tree.reason}\\n`;\n return out;\n }\n return this.worktreeSection.report(repoRoot, result);\n }\n\n /**\n * `<worktree-path> <branch> <head-sha>`, all three required. The sha is not optional and has no\n * default: a defaulted '' would mean \"do not check\", i.e. exactly the name-only removal both\n * processes exist to refuse, so a caller that omits it must fail to run rather than run wider.\n *\n * Thrown rather than printed: bad argv means the caller is broken, and there is no landed PR in this\n * process whose success a non-zero exit could misreport.\n */\n private parse(args: string[]): ReapRequest {\n const worktreePath = args[0] ?? '';\n const branch = args[1] ?? '';\n const head = args[2] ?? '';\n if (worktreePath === '' || branch === '' || head === '') {\n throw new InformAiError(\n '\\n' + SEP + '❌ wp-reap-worktree: missing arguments\\n' + SEP + '\\n'\n + 'Usage: node wp-reap-worktree.js <worktree-path> <branch> <head-sha>\\n\\n'\n + 'This is an INTERNAL entry point, spawned by `pnpm wp-land-pr` with cwd set to the\\n'\n + 'primary clone. To clean up by hand, run `pnpm wp-cleanup` from the primary clone.\\n' + SEP);\n }\n return new ReapRequest(worktreePath, branch, head);\n }\n}\n\n// Data-only (per CLAUDE.md, classes for data): the argv values this entry point takes.\nclass ReapRequest {\n worktreePath: string;\n branch: string;\n /** The commit the parent proved this worktree was at — re-verified here, never trusted. */\n head: string;\n\n constructor(worktreePath: string, branch: string, head: string) {\n this.worktreePath = worktreePath;\n this.branch = branch;\n this.head = head;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reap-worktree-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/reap-worktree-command.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAC7B,sEAAiH;AACjH,8DAA0D;AAC1D,0DAA0E;AAC1E,yCAA2D;AAE3D,2DAKkC;AAElC,yDAA4D;AAE5D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,eAAuC,EACvC,MAAyB,EACzB,SAA0B;QAH1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAwB;QACvC,WAAM,GAAN,MAAM,CAAmB;QACzB,cAAS,GAAT,SA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C,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,YAAY,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACtD,MAAM,IAAI,8BAAa,CACnB,IAAI,GAAG,GAAG,GAAG,yCAAyC,GAAG,GAAG,GAAG,IAAI;kBACjE,yEAAyE;kBACzE,qFAAqF;kBACrF,qFAAqF,GAAG,GAAG,CAAC,CAAC;QACvG,CAAC;QACD,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAjIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACb,yCAAsB;QAC/B,gCAAiB;QACd,oCAAe;GALtC,mBAAmB,CAiI/B;AAED,uFAAuF;AACvF,MAAM,WAAW;IACb,YAAY,CAAS;IACrB,MAAM,CAAS;IACf,2FAA2F;IAC3F,IAAI,CAAS;IAEb,YAAY,YAAoB,EAAE,MAAc,EAAE,IAAY;QAC1D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ","sourcesContent":["import * as path from 'path';\nimport { DeletableWorktree, Worktree, WorktreeReapResult, WorktreeService } from '@webpieces/repo-workflow-core';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { RepoRootFinder, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport {\n ReapOutcomeSignal,\n REAP_OUTCOME_FAILED,\n REAP_OUTCOME_REFUSED,\n REAP_OUTCOME_REMOVED,\n} from '../workflow/reap-outcome';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The CHILD side of `wp-land-pr`'s re-exec: reap ONE named worktree, from a process whose cwd is the\n * primary clone.\n *\n * It is not a published `bin`. Nothing about it is a verb a human should reach for — `pnpm wp-cleanup`\n * is that verb, and it does strictly more. This exists so the parent can hand off a SINGLE, already\n * identified corpse without also reaping every other agent's worktree as a side effect of landing one\n * PR. LandedWorktreeReaper spawns it by absolute path; see that class for why a child rather than a\n * `process.chdir`.\n *\n * WHAT IT WILL NOT TAKE ON TRUST. The parent tells it a path, a branch and the HEAD sha it selected the\n * tree by; it believes none of the three.\n * The verdict is recomputed here, from scratch, by the same MergedBranchesService that backs\n * `wp-cleanup` — so a worktree is removed only when it is PROVABLY dead (its PR is merged), and never\n * because a caller said so. That is what keeps \"never remove a tree still holding unmerged work\" true\n * even if the parent is wrong, out of date, or someone runs this by hand.\n *\n * The primary clone can never be a target: `classifyWorktrees` drops the main worktree from the\n * verdicts outright, so a path pointing at it simply does not resolve to a target — and WorktreeReaper\n * refuses it a second time by name. Neither rail is load-bearing alone.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReapWorktreeCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly worktreeSection: WorktreeCleanupSection,\n private readonly signal: ReapOutcomeSignal,\n private readonly worktrees: WorktreeService,\n ) {}\n\n /**\n * Every exit from here states an OUTCOME, because the exit code cannot: refusals exit 0 (see\n * `resolveTarget`), so a parent with only a status has no way to tell \"removed\" from \"declined to\n * remove\". The token is the last thing written, and LandedWorktreeReaper strips it before printing.\n */\n async run(args: string[]): Promise<void> {\n const request = this.parse(args);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const target = await this.resolveTarget(repoRoot, request);\n if (target === null) {\n process.stdout.write(this.signal.line(REAP_OUTCOME_REFUSED));\n return;\n }\n\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n const result = await this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);\n process.stdout.write(this.render(repoRoot, result));\n process.stdout.write(this.signal.line(this.outcomeOf(result)));\n }\n\n /**\n * `reaped` is the only entry that means the DIRECTORY is gone. A tree that reached the reaper and\n * came back in neither list was spared by one of WorktreeReaper's own rails (it is the cwd, it is\n * the primary clone) — nothing was attempted, which is a refusal, not a failure.\n */\n private outcomeOf(result: WorktreeReapResult): string {\n if (result.reaped.length > 0) return REAP_OUTCOME_REMOVED;\n return result.failed.length > 0 ? REAP_OUTCOME_FAILED : REAP_OUTCOME_REFUSED;\n }\n\n /**\n * The verdict for the requested path, or null after printing WHY it is not reapable. Refusals are\n * printed rather than thrown: the PR they follow is already merged, and exiting non-zero after a\n * successful landing would report a landed PR as a failed command. That is exactly why `run` also\n * emits a ReapOutcomeSignal — the caller must be able to tell this exit 0 from a successful one.\n */\n private async resolveTarget(repoRoot: string, request: ReapRequest): Promise<DeletableWorktree | null> {\n const wanted = path.resolve(request.worktreePath);\n // `false`: this reaps ONE named worktree after its PR landed, and it is not the place to\n // override anybody's lock — a lock still standing here is exactly the refusal this prints.\n const target = (await this.worktreeSection.verdicts(repoRoot, false))\n .find((tree: DeletableWorktree): boolean => path.resolve(tree.path) === wanted);\n\n if (target === undefined) {\n process.stdout.write(\n `\\n ℹ️ ${request.worktreePath} is not a removable worktree of this repo (it may be the\\n`\n + ' primary clone, or already gone). Nothing removed.\\n');\n return null;\n }\n // The branch moved under us between landing and reaping — somebody checked something else out\n // there. Whatever that is, it is not the corpse we were asked to bury.\n if (target.branch !== request.branch) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} now holds '${target.branch}', not '${request.branch}'.\\n`\n + ' Refusing to remove a worktree whose branch changed since the PR landed.\\n');\n return null;\n }\n // …and the NAME is not the identity. The parent selected this directory because its HEAD was the\n // exact commit GitHub squashed; that selection is recomputed here from git rather than taken on\n // trust, so a commit made in that tree between landing and reaping — work the archive tag of the\n // squashed tip does not contain — stops the removal instead of being buried with it.\n const here = this.headOf(repoRoot, wanted);\n if (here !== request.head) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is at ${here === '' ? '(unknown)' : here}, not the landed\\n`\n + ` commit ${request.head}.\\n`\n + ' Refusing to remove a worktree whose HEAD moved since the PR landed.\\n');\n return null;\n }\n if (!target.deletable) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is not provably dead: ${target.reason}\\n`\n + ' Refusing to remove a worktree that may still hold unmerged work.\\n');\n return null;\n }\n return target;\n }\n\n /**\n * That worktree's HEAD as git reports it right now, '' when git cannot place the path at all.\n * '' can never equal a real sha, so \"git would not answer\" fails SAFE — it declines the removal.\n */\n private headOf(repoRoot: string, resolvedPath: string): string {\n const tree = this.worktrees.listWorktrees(repoRoot)\n .find((candidate: Worktree): boolean => path.resolve(candidate.path) === resolvedPath);\n return tree?.head ?? '';\n }\n\n // The reap report, plus the spared case — which report() renders as '' because from wp-cleanup's\n // point of view \"nothing happened\" is a whole answer. Here it never is: we asked for exactly one.\n private render(repoRoot: string, result: WorktreeReapResult): string {\n if (result.reaped.length === 0 && result.failed.length === 0) {\n let out = '\\n' + SEP + '🛑 Nothing removed\\n' + SEP + '\\n';\n for (const tree of result.spared) out += ` · ${tree.path} — ${tree.reason}\\n`;\n return out;\n }\n return this.worktreeSection.report(repoRoot, result);\n }\n\n /**\n * `<worktree-path> <branch> <head-sha>`, all three required. The sha is not optional and has no\n * default: a defaulted '' would mean \"do not check\", i.e. exactly the name-only removal both\n * processes exist to refuse, so a caller that omits it must fail to run rather than run wider.\n *\n * Thrown rather than printed: bad argv means the caller is broken, and there is no landed PR in this\n * process whose success a non-zero exit could misreport.\n */\n private parse(args: string[]): ReapRequest {\n const worktreePath = args[0] ?? '';\n const branch = args[1] ?? '';\n const head = args[2] ?? '';\n if (worktreePath === '' || branch === '' || head === '') {\n throw new InformAiError(\n '\\n' + SEP + '❌ wp-reap-worktree: missing arguments\\n' + SEP + '\\n'\n + 'Usage: node wp-reap-worktree.js <worktree-path> <branch> <head-sha>\\n\\n'\n + 'This is an INTERNAL entry point, spawned by `pnpm wp-land-pr` with cwd set to the\\n'\n + 'primary clone. To clean up by hand, run `pnpm wp-cleanup` from the primary clone.\\n' + SEP);\n }\n return new ReapRequest(worktreePath, branch, head);\n }\n}\n\n// Data-only (per CLAUDE.md, classes for data): the argv values this entry point takes.\nclass ReapRequest {\n worktreePath: string;\n branch: string;\n /** The commit the parent proved this worktree was at — re-verified here, never trusted. */\n head: string;\n\n constructor(worktreePath: string, branch: string, head: string) {\n this.worktreePath = worktreePath;\n this.branch = branch;\n this.head = head;\n }\n}\n"]}
|
|
@@ -111,14 +111,14 @@ let ReviewUpsertPrCommand = class ReviewUpsertPrCommand {
|
|
|
111
111
|
async runStage(repoRoot) {
|
|
112
112
|
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
113
113
|
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.review-checklists.md');
|
|
114
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
114
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
115
115
|
const config = (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
|
|
116
116
|
const mergeValidated = await this.finalizeAnyInProgressMerge(repoRoot);
|
|
117
|
-
this.gitExec.assertCleanTree(repoRoot);
|
|
117
|
+
await this.gitExec.assertCleanTree(repoRoot);
|
|
118
118
|
const buildPassedAt = await this.runBuildGate(repoRoot);
|
|
119
|
-
const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(config.maxReviewerRounds, false, '')); // '' — THIS command writes the context itself, after materializing
|
|
119
|
+
const scan = await this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(config.maxReviewerRounds, false, '')); // '' — THIS command writes the context itself, after materializing
|
|
120
120
|
const previousReceipt = this.receipts.read(repoRoot, featureName);
|
|
121
|
-
const plan = this.rounds.plan(repoRoot, scan.summaryPath, previousReceipt, config.maxReviewerRounds, scan.basis);
|
|
121
|
+
const plan = await this.rounds.plan(repoRoot, scan.summaryPath, previousReceipt, config.maxReviewerRounds, scan.basis);
|
|
122
122
|
if (plan.action === review_round_state_1.ROUND_ACTION_RESUME && previousReceipt !== null) {
|
|
123
123
|
this.resumeRound(repoRoot, featureName, scan, previousReceipt, mergeValidated, buildPassedAt);
|
|
124
124
|
this.reportActiveHatches(repoRoot);
|
|
@@ -128,7 +128,7 @@ let ReviewUpsertPrCommand = class ReviewUpsertPrCommand {
|
|
|
128
128
|
}
|
|
129
129
|
const shouldBrief = plan.action === review_round_state_1.ROUND_ACTION_REVIEW;
|
|
130
130
|
const briefings = shouldBrief
|
|
131
|
-
? this.briefReviewers(repoRoot, featureName, scan, config, plan)
|
|
131
|
+
? await this.briefReviewers(repoRoot, featureName, scan, config, plan)
|
|
132
132
|
: [];
|
|
133
133
|
const recordedReviewers = briefings.map((b) => b.checklistId);
|
|
134
134
|
if (shouldBrief) {
|
|
@@ -203,7 +203,7 @@ let ReviewUpsertPrCommand = class ReviewUpsertPrCommand {
|
|
|
203
203
|
* false when validation fails, so the receipt can never record an unvalidated merge as validated.
|
|
204
204
|
*/
|
|
205
205
|
async finalizeAnyInProgressMerge(repoRoot) {
|
|
206
|
-
const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());
|
|
206
|
+
const home = this.mergeState.mergeDirFor(repoRoot, await this.aiBranchName.getFeatureName());
|
|
207
207
|
const activeDir = this.mergeState.findActiveMergeRunDir(home);
|
|
208
208
|
const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;
|
|
209
209
|
if (!activeDir || !marker || marker.validated)
|
|
@@ -224,7 +224,7 @@ let ReviewUpsertPrCommand = class ReviewUpsertPrCommand {
|
|
|
224
224
|
// finish, because this is the stage that ran buildCommand and is therefore holding the dirty
|
|
225
225
|
// tree at the exact moment the question is answerable. Replaces the per-project
|
|
226
226
|
// validate-di-graph-unchanged nx target — see BuildArtifactGate for why that one had to go.
|
|
227
|
-
this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);
|
|
227
|
+
await this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);
|
|
228
228
|
return new Date().toISOString();
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
@@ -233,17 +233,17 @@ let ReviewUpsertPrCommand = class ReviewUpsertPrCommand {
|
|
|
233
233
|
* The changed-file set and the basis both come off the SCAN rather than being recomputed, so the diff a
|
|
234
234
|
* reviewer reads covers exactly the files its checklist matched against.
|
|
235
235
|
*/
|
|
236
|
-
briefReviewers(repoRoot, featureName, scan, config, plan) {
|
|
236
|
+
async briefReviewers(repoRoot, featureName, scan, config, plan) {
|
|
237
237
|
if (plan.basis.unresolved)
|
|
238
238
|
return [];
|
|
239
239
|
const changedFiles = plan.round > 1 ? plan.changedFiles : scan.changedFiles;
|
|
240
|
-
const manifest = this.materializer.materialize(repoRoot, featureName, plan.basis, changedFiles, config.reviewDiffExclude);
|
|
240
|
+
const manifest = await this.materializer.materialize(repoRoot, featureName, plan.basis, changedFiles, config.reviewDiffExclude);
|
|
241
241
|
const diffDir = this.materializer.diffDirFor(repoRoot, featureName);
|
|
242
242
|
// Write pr-context.json ONCE, here — after materializing, so `diffDir` is populated on the first
|
|
243
243
|
// write. The scan deliberately did not write it (ChecklistScanOptions.contextStage === ''); it used
|
|
244
244
|
// to, which meant this command wrote the same file twice, the first time with an empty diffDir.
|
|
245
245
|
// `scan.changedFiles` is passed through so the context is not recomputed from a second git call.
|
|
246
|
-
scan.context = this.prContextWriter.ensure(repoRoot, featureName, plan.basis, 'stage2-review', changedFiles, diffDir);
|
|
246
|
+
scan.context = await this.prContextWriter.ensure(repoRoot, featureName, plan.basis, 'stage2-review', changedFiles, diffDir);
|
|
247
247
|
// ONLY the checklists still owed a verdict (issue #863). A green or yellow CARRIES whatever changed
|
|
248
248
|
// since (issue #1053) — the scan left it in `reviewed` — so briefing it again would pay a reviewer to
|
|
249
249
|
// re-read code it already judged. A later round re-briefs exactly the previous round's REDS.
|