@webpieces/pr-gate 0.4.983 → 0.4.985
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 +8 -8
- package/src/scripts/commands/build-push-dev-command.d.ts +61 -0
- package/src/scripts/commands/build-push-dev-command.js +159 -0
- package/src/scripts/commands/build-push-dev-command.js.map +1 -0
- package/src/scripts/commands/finish-push-dev-command.d.ts +73 -17
- package/src/scripts/commands/finish-push-dev-command.js +187 -31
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/start-push-dev-command.d.ts +43 -0
- package/src/scripts/commands/start-push-dev-command.js +111 -0
- package/src/scripts/commands/start-push-dev-command.js.map +1 -0
- package/src/scripts/pr-gate-app.d.ts +18 -18
- package/src/scripts/pr-gate-app.js +27 -26
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.d.ts +2 -2
- package/src/scripts/pr-gate-cli-app.js +20 -29
- package/src/scripts/pr-gate-cli-app.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.js +2 -2
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/dev-build.js +2 -2
- package/src/scripts/workflow/dev-build.js.map +1 -1
- package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
- package/src/scripts/workflow/dev-copy-on-main.js +99 -0
- package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
- package/src/scripts/workflow/dev-deploy-refs.d.ts +4 -17
- package/src/scripts/workflow/dev-deploy-refs.js +5 -21
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +43 -73
- package/src/scripts/workflow/dev-resolve-runner.js +117 -181
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/main-freshness.d.ts +16 -0
- package/src/scripts/workflow/main-freshness.js +33 -0
- package/src/scripts/workflow/main-freshness.js.map +1 -0
- package/src/scripts/workflow/push-dev-state.d.ts +12 -35
- package/src/scripts/workflow/push-dev-state.js +31 -62
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/workflow/verified-dev-copy.d.ts +46 -0
- package/src/scripts/workflow/verified-dev-copy.js +89 -0
- package/src/scripts/workflow/verified-dev-copy.js.map +1 -0
- package/src/scripts/{wp-build-dev.js → wp-build-push-dev.js} +2 -2
- package/src/scripts/wp-build-push-dev.js.map +1 -0
- package/src/scripts/{wp-push-dev.js → wp-start-push-dev.js} +2 -2
- package/src/scripts/wp-start-push-dev.js.map +1 -0
- package/src/scripts/commands/build-dev-command.d.ts +0 -27
- package/src/scripts/commands/build-dev-command.js +0 -99
- package/src/scripts/commands/build-dev-command.js.map +0 -1
- package/src/scripts/commands/push-dev-command.d.ts +0 -124
- package/src/scripts/commands/push-dev-command.js +0 -318
- package/src/scripts/commands/push-dev-command.js.map +0 -1
- package/src/scripts/wp-build-dev.js.map +0 -1
- package/src/scripts/wp-push-dev.js.map +0 -1
- /package/src/scripts/{wp-build-dev.d.ts → wp-build-push-dev.d.ts} +0 -0
- /package/src/scripts/{wp-push-dev.d.ts → wp-start-push-dev.d.ts} +0 -0
|
@@ -3,187 +3,145 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DevResolveRunner = exports.RESOLUTION_SUBJECT = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
7
|
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
7
8
|
const inversify_1 = require("inversify");
|
|
8
9
|
const git_exec_1 = require("./git-exec");
|
|
9
10
|
const dev_deploy_refs_1 = require("./dev-deploy-refs");
|
|
10
11
|
const push_dev_state_1 = require("./push-dev-state");
|
|
11
|
-
const dev_deploy_watch_hints_1 = require("./dev-deploy-watch-hints");
|
|
12
12
|
const dev_build_1 = require("./dev-build");
|
|
13
|
+
const verified_dev_copy_1 = require("./verified-dev-copy");
|
|
13
14
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
14
15
|
/**
|
|
15
16
|
* The subject prefix of the ONE commit this flow writes onto a copy: the recorded conflict resolution.
|
|
16
|
-
* The clobber guard reads it — a remote-only commit with this subject is re-derived by the next publish's
|
|
17
|
-
* check against dev, so replacing it destroys nothing; any other remote-only commit is somebody's work.
|
|
18
17
|
*/
|
|
19
18
|
exports.RESOLUTION_SUBJECT = 'Dev-deploy: conflict resolution for';
|
|
20
19
|
/**
|
|
21
|
-
* The
|
|
22
|
-
* `
|
|
20
|
+
* The engine behind `wp-build-push-dev` (#1403): merge `origin/<devBranch>` into a THROWAWAY branch, stop
|
|
21
|
+
* on a conflict, `pnpm install`, run the dev build, and record the copy `wp-finish-push-dev` publishes.
|
|
23
22
|
*
|
|
24
|
-
* ONE class owns every git WRITE
|
|
23
|
+
* ONE class owns every git WRITE of the check, and that is a hard requirement rather than tidiness:
|
|
25
24
|
* `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and
|
|
26
|
-
* `
|
|
25
|
+
* `merge-in-progress-guard` blocks `git commit`. So an AI cannot be told "now run `git commit`" or
|
|
27
26
|
* "`git merge --continue`" — those instructions are unrunnable by the only party reading them. The command
|
|
28
|
-
* owns the
|
|
29
|
-
*
|
|
27
|
+
* owns the merge and the commits (as child processes the hooks never see); the AI's entire job is editing
|
|
28
|
+
* the conflicted files and `git add`-ing them, neither of which is blocked.
|
|
29
|
+
*
|
|
30
|
+
* It NEVER writes to the feature branch: every merge lands on a throwaway that is deleted at the end, so no
|
|
31
|
+
* other developer's commits can reach the PR head even if the check is abandoned halfway.
|
|
30
32
|
*/
|
|
31
33
|
let DevResolveRunner = class DevResolveRunner {
|
|
32
34
|
gitExec;
|
|
33
35
|
refs;
|
|
34
36
|
store;
|
|
35
|
-
|
|
37
|
+
verified;
|
|
36
38
|
devBuild;
|
|
37
|
-
|
|
39
|
+
processes;
|
|
40
|
+
constructor(gitExec, refs, store, verified, devBuild, processes) {
|
|
38
41
|
this.gitExec = gitExec;
|
|
39
42
|
this.refs = refs;
|
|
40
43
|
this.store = store;
|
|
41
|
-
this.
|
|
44
|
+
this.verified = verified;
|
|
42
45
|
this.devBuild = devBuild;
|
|
46
|
+
this.processes = processes;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
|
-
* Start
|
|
46
|
-
*
|
|
47
|
-
* The checkout is `-B <tmp> <base>` and NEVER the feature branch, which is the cardinal constraint made
|
|
48
|
-
* mechanical — every merge below lands on a branch that is deleted at the end, so no other developer's
|
|
49
|
-
* commits can reach the PR head even if the resolve is abandoned halfway.
|
|
50
|
-
*
|
|
51
|
-
* `base` differs between the callers and the difference IS the semantics. A plain publish starts at the
|
|
52
|
-
* LOCAL HEAD and merges `origin/<devBranch>` in (does this copy merge and build against what is already
|
|
53
|
-
* on dev?). `--resolve` starts at the published copy and merges the other copies in (compose what CI
|
|
54
|
-
* will build). `--rebase-resolution` starts at the LOCAL HEAD and merges the published copy in (replay
|
|
55
|
-
* an existing resolution on top of the new commits, instead of force-pushing over it). What is finally
|
|
56
|
-
* PUBLISHED is the state's DevResolveMode's decision — see finalize.
|
|
57
|
-
*
|
|
58
|
-
* `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is
|
|
59
|
-
* also its push destination, so "everything to fetch" and "everything to merge" are not the same list.
|
|
49
|
+
* Start the check: park on a throwaway branch at the feature head, merge `origin/<devBranch>` into it,
|
|
50
|
+
* and either halt on a conflict or go straight on to install, build and record.
|
|
60
51
|
*/
|
|
61
|
-
async start(repoRoot, state
|
|
62
|
-
await this.refs.fetchCopies(repoRoot,
|
|
63
|
-
// Pinned to a SHA
|
|
64
|
-
//
|
|
65
|
-
state.baseSha = await this.refs.headSha(repoRoot,
|
|
52
|
+
async start(repoRoot, state) {
|
|
53
|
+
await this.refs.fetchCopies(repoRoot, [state.devBranch]);
|
|
54
|
+
// Pinned to a SHA: the resolution is recorded on top of exactly what was merged, and stage ③
|
|
55
|
+
// refuses to publish when the feature branch has moved since.
|
|
56
|
+
state.baseSha = await this.refs.headSha(repoRoot, 'HEAD');
|
|
66
57
|
this.store.write(repoRoot, state);
|
|
67
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch,
|
|
68
|
-
await this.
|
|
58
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, 'HEAD'], `Failed to create the throwaway branch ${state.tmpBranch}`);
|
|
59
|
+
const merged = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
60
|
+
`Dev-deploy: merge ${state.devBranch} into ${state.targetRef}`, `refs/remotes/origin/${state.devBranch}`], repoRoot);
|
|
61
|
+
if (!merged.ok)
|
|
62
|
+
await this.halt(repoRoot, state);
|
|
63
|
+
process.stdout.write(` ✓ merged origin/${state.devBranch}\n`);
|
|
64
|
+
await this.finish(repoRoot, state);
|
|
69
65
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Resume after the human/AI has resolved the halted merge: commit it, then keep draining.
|
|
72
|
-
*
|
|
73
|
-
* REFETCHES the remaining queue first. A resolution session can run long, and queuing against refs
|
|
74
|
-
* fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling
|
|
75
|
-
* update flow is still known to have (only its stage ① ever fetches).
|
|
76
|
-
*/
|
|
66
|
+
/** Resume after the conflicted files were resolved and `git add`-ed: commit the merge, then finish. */
|
|
77
67
|
async resume(repoRoot, state) {
|
|
78
|
-
await this.assertNoUnmergedPaths(repoRoot
|
|
68
|
+
await this.assertNoUnmergedPaths(repoRoot);
|
|
79
69
|
await this.gitExec.assertNoUntracked(repoRoot);
|
|
80
70
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');
|
|
81
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of
|
|
82
|
-
process.stdout.write(`✅ Committed the resolution of
|
|
83
|
-
|
|
84
|
-
await this.refs.fetchCopies(repoRoot, state.queue);
|
|
85
|
-
await this.drain(repoRoot, state);
|
|
71
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of the merge with origin/${state.devBranch}`);
|
|
72
|
+
process.stdout.write(`✅ Committed the resolution of the merge with origin/${state.devBranch}.\n`);
|
|
73
|
+
await this.finish(repoRoot, state);
|
|
86
74
|
}
|
|
87
75
|
/**
|
|
88
|
-
* Throw the whole
|
|
89
|
-
* throwaway branch and the state file. Nothing
|
|
76
|
+
* Throw the whole check away: undo any halted merge, go back to the original branch, delete the
|
|
77
|
+
* throwaway branch and the state file. Nothing verified, nothing on the feature branch.
|
|
90
78
|
*/
|
|
91
79
|
async abort(repoRoot, state) {
|
|
92
|
-
// Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is
|
|
93
|
-
// not an error condition — the rest of the teardown must still run.
|
|
94
|
-
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
95
80
|
await this.restore(repoRoot, state);
|
|
96
|
-
process.stdout.write('\n' + SEP + '🛑 Dev-deploy
|
|
81
|
+
process.stdout.write('\n' + SEP + '🛑 Dev-deploy check aborted\n' + SEP + '\n'
|
|
97
82
|
+ `You are back on \`${state.originalBranch}\`; \`${state.tmpBranch}\` and the state file are gone.\n`
|
|
98
|
-
+ `
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).
|
|
102
|
-
*
|
|
103
|
-
* A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a
|
|
104
|
-
* single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.
|
|
105
|
-
*/
|
|
106
|
-
async drain(repoRoot, state) {
|
|
107
|
-
while (state.queue.length > 0) {
|
|
108
|
-
const ref = state.queue[0];
|
|
109
|
-
state.queue = state.queue.slice(1);
|
|
110
|
-
const outcome = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
111
|
-
`Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`], repoRoot);
|
|
112
|
-
if (outcome.ok) {
|
|
113
|
-
process.stdout.write(` ✓ merged ${ref}\n`);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
state.current = ref;
|
|
117
|
-
await this.halt(repoRoot, state);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
await this.finalize(repoRoot, state);
|
|
83
|
+
+ `Nothing was published, and your feature branch is untouched.\n`);
|
|
121
84
|
}
|
|
122
85
|
/** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = "your turn". */
|
|
123
86
|
async halt(repoRoot, state) {
|
|
124
87
|
const conflicted = await this.unmergedPaths(repoRoot);
|
|
125
88
|
// Remembered so the finish records EXACTLY these files as the resolution — and nothing else the
|
|
126
89
|
// merge brought in, which is other developers' work.
|
|
127
|
-
|
|
128
|
-
if (!state.resolvedPaths.includes(file))
|
|
129
|
-
state.resolvedPaths.push(file);
|
|
90
|
+
state.resolvedPaths = conflicted;
|
|
130
91
|
this.store.write(repoRoot, state);
|
|
131
|
-
|
|
132
|
-
? `\nStill queued after this one: ${state.queue.join(', ')}\n`
|
|
133
|
-
+ `\`${rules_config_1.WP_FINISH_PUSH_DEV}\` resumes the queue, so it may stop again on a later ref.\n`
|
|
134
|
-
: '';
|
|
135
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ CONFLICT merging ${state.current}\n` + SEP + '\n'
|
|
92
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ CONFLICT merging origin/${state.devBranch}\n` + SEP + '\n'
|
|
136
93
|
+ `You are on the throwaway branch \`${state.tmpBranch}\` — NOT \`${state.originalBranch}\`. Nothing here\n`
|
|
137
94
|
+ 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\n\n'
|
|
138
95
|
+ 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\n'
|
|
139
96
|
+ conflicted.map((f) => ` ${f}`).join('\n') + '\n'
|
|
140
|
-
+ remaining
|
|
141
97
|
+ '\nThen run ONE of:\n'
|
|
142
|
-
+ ` ${rules_config_1.
|
|
143
|
-
+ ` ${rules_config_1.
|
|
98
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV} ← commit the resolution, pnpm install, run the dev build\n`
|
|
99
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV} --abort ← throw it away and go back to \`${state.originalBranch}\`\n\n`
|
|
144
100
|
+ 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\n'
|
|
145
|
-
+ 'the
|
|
101
|
+
+ 'the commands above do them for you.\n');
|
|
146
102
|
}
|
|
147
103
|
/**
|
|
148
|
-
*
|
|
104
|
+
* The merge is complete. Install and build the MERGED tree, then turn the throwaway into the copy and
|
|
105
|
+
* record it for `wp-finish-push-dev`.
|
|
149
106
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* publishes the merge, as it always has.
|
|
107
|
+
* `pnpm install` runs AFTER the merge, never before: other copies already on dev can add workspace
|
|
108
|
+
* packages main does not have yet, so the feature branch's `node_modules` does not link the merged
|
|
109
|
+
* tree (#1403 — a 30-commits-behind branch failed six minutes into its build on exactly that).
|
|
154
110
|
*/
|
|
155
|
-
async
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
process.stdout.write('\n' + SEP + `✅ ${state.targetRef} composes cleanly — nothing to publish\n` + SEP + '\n'
|
|
166
|
-
+ 'Every other copy merged onto it without a conflict, so your CI composes it as it is. The copy\n'
|
|
167
|
-
+ `is unchanged, and you are back on \`${state.originalBranch}\`.\n`);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...this.pushSafety(state), 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`], `Failed to publish the dev copy ${state.targetRef}`);
|
|
111
|
+
async finish(repoRoot, state) {
|
|
112
|
+
await this.onThrowaway(repoRoot, state, () => this.install(repoRoot, state));
|
|
113
|
+
await this.onThrowaway(repoRoot, state, () => this.devBuild.run(repoRoot, rules_config_1.WP_BUILD_PUSH_DEV));
|
|
114
|
+
// The install may rewrite the lockfile on the throwaway; drop that before the throwaway moves.
|
|
115
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'reset', '--hard', 'HEAD'], `Failed to discard what pnpm install changed on ${state.tmpBranch}`);
|
|
116
|
+
await this.recordResolution(repoRoot, state);
|
|
117
|
+
const copySha = await this.refs.headSha(repoRoot, state.tmpBranch);
|
|
118
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'update-ref', this.verified.keepRef(state.originalBranch), copySha], `Failed to keep the verified copy ${copySha.slice(0, 8)} reachable`);
|
|
119
|
+
const devSha = await this.refs.headSha(repoRoot, `refs/remotes/origin/${state.devBranch}`);
|
|
120
|
+
this.verified.write(repoRoot, new verified_dev_copy_1.VerifiedDevCopy(state.originalBranch, state.baseSha, copySha, state.targetRef, state.leaseSha, devSha));
|
|
171
121
|
await this.restore(repoRoot, state);
|
|
172
|
-
process.stdout.write(this.
|
|
173
|
-
|
|
122
|
+
process.stdout.write(this.verifiedBanner(state, devSha));
|
|
123
|
+
}
|
|
124
|
+
async install(repoRoot, state) {
|
|
125
|
+
process.stdout.write(`\nRunning pnpm install on the merged throwaway \`${state.tmpBranch}\`.\n`);
|
|
126
|
+
const result = await this.processes.passThrough('pnpm', ['install'], repoRoot);
|
|
127
|
+
if (result.ok)
|
|
128
|
+
return;
|
|
129
|
+
throw new rules_config_1.CliExitError(1, '\n' + SEP + `⛔ pnpm install failed on the merge with origin/${state.devBranch}\n` + SEP + '\n'
|
|
130
|
+
+ `\`pnpm install\` exited ${String(result.code)} on the merged tree (its output is above). No build ran and\n`
|
|
131
|
+
+ `nothing was verified; you are back on \`${state.originalBranch}\`. Fix what it reported, then re-run:\n`
|
|
132
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV}\n`);
|
|
174
133
|
}
|
|
175
134
|
/**
|
|
176
|
-
* Run
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
135
|
+
* Run one step on the throwaway. On a failure, put the checkout back first — the fix belongs on the
|
|
136
|
+
* feature branch, and a developer left parked on a throwaway would make the next `wp-*` command act on
|
|
137
|
+
* the wrong branch — then let the step's own failure (a build's carries its `FullLog :` pointer) reach
|
|
138
|
+
* the top-level handler unchanged.
|
|
180
139
|
*/
|
|
181
|
-
async
|
|
182
|
-
|
|
183
|
-
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the build passed; the build's own CliExitError is re-thrown unchanged
|
|
140
|
+
async onThrowaway(repoRoot, state, step) {
|
|
141
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the step passed; the step's own error is re-thrown unchanged
|
|
184
142
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
185
143
|
try {
|
|
186
|
-
await
|
|
144
|
+
await step();
|
|
187
145
|
}
|
|
188
146
|
catch (err) {
|
|
189
147
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -192,14 +150,14 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
192
150
|
}
|
|
193
151
|
}
|
|
194
152
|
/**
|
|
195
|
-
* Turn the throwaway into
|
|
196
|
-
*
|
|
153
|
+
* Turn the throwaway into the copy: the base sha plus, when anything conflicted, ONE commit that sets
|
|
154
|
+
* each resolved file to its resolved content.
|
|
197
155
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
156
|
+
* The merge is used for the conflict check and the build only, and is never published. Publishing it
|
|
157
|
+
* would make every other copy an ancestor of this one, so a later `--remove` of that copy would leave
|
|
158
|
+
* its commits on dev through ours. The resolution commit has exactly one parent, the base, so the only
|
|
159
|
+
* thing it can carry of anybody else's work is the text of the hunks that were resolved — content,
|
|
160
|
+
* never history.
|
|
203
161
|
*/
|
|
204
162
|
async recordResolution(repoRoot, state) {
|
|
205
163
|
const merged = await this.refs.headSha(repoRoot, state.tmpBranch);
|
|
@@ -221,60 +179,49 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
221
179
|
+ 'This commit carries only the files that conflicted and were resolved:\n'
|
|
222
180
|
+ state.resolvedPaths.map((f) => ` ${f}`).join('\n') + '\n'], `Failed to commit the recorded resolution for ${state.targetRef}`);
|
|
223
181
|
}
|
|
224
|
-
/** Back to the original branch; the throwaway and the state file are gone. */
|
|
182
|
+
/** Back to the original branch; any halted merge, the throwaway and the state file are gone. */
|
|
225
183
|
async restore(repoRoot, state) {
|
|
184
|
+
// Only ever on the throwaway: a reset anywhere else could destroy somebody's uncommitted work.
|
|
185
|
+
// Both allowed to fail: there is no merge to abort once it completed, and nothing to reset on a
|
|
186
|
+
// clean tree. Neither is an error — the rest of the teardown must still run.
|
|
187
|
+
if (await this.gitExec.currentBranch(repoRoot) === state.tmpBranch) {
|
|
188
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
189
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'reset', '--hard', 'HEAD'], repoRoot);
|
|
190
|
+
}
|
|
226
191
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
|
|
227
192
|
await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
|
|
228
193
|
this.store.clear(repoRoot);
|
|
229
194
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// The halt message names the build only where the finish will actually run one.
|
|
242
|
-
buildStep(state) {
|
|
243
|
-
return state.mode === push_dev_state_1.DevResolveMode.PREBUILD ? 'run the dev build, ' : '';
|
|
244
|
-
}
|
|
245
|
-
publishedBanner(state) {
|
|
246
|
-
const what = state.mode === push_dev_state_1.DevResolveMode.REPLAY
|
|
247
|
-
? 'your new commits merged with the copy\'s earlier resolution'
|
|
248
|
-
: state.resolvedPaths.length === 0
|
|
249
|
-
? 'your branch exactly as it is'
|
|
250
|
-
: `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy became part of its history`;
|
|
251
|
-
return '\n' + SEP + `✅ Published ${state.targetRef}\n` + SEP + '\n'
|
|
252
|
-
+ `The copy is ${what}.\n`
|
|
253
|
-
+ `You are back on \`${state.originalBranch}\`, which was never modified — verify with:\n`
|
|
254
|
-
+ ` git log --oneline ${state.originalBranch}\n`
|
|
255
|
-
+ 'Your CI will pick the copy up on its next composition run.\n'
|
|
256
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --list ← what else is in the pool\n`
|
|
257
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --remove ← take this branch back out\n`;
|
|
195
|
+
verifiedBanner(state, devSha) {
|
|
196
|
+
const what = state.resolvedPaths.length === 0
|
|
197
|
+
? 'your branch exactly as it is'
|
|
198
|
+
: `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy becomes part of its history`;
|
|
199
|
+
return '\n' + SEP + `✅ ${state.targetRef} is verified against origin/${state.devBranch}\n` + SEP + '\n'
|
|
200
|
+
+ `It merges with origin/${state.devBranch} (${devSha.slice(0, 8)}), pnpm install ran on the merged tree, and the dev\n`
|
|
201
|
+
+ `build is green. The copy to publish is ${what}.\n`
|
|
202
|
+
+ `You are back on \`${state.originalBranch}\`, which this check never modified.\n\n`
|
|
203
|
+
+ `▶ NEXT run: ${rules_config_1.WP_FINISH_PUSH_DEV}\n`
|
|
204
|
+
+ ` It publishes the verified copy as \`${state.targetRef}\`. It refuses if \`${state.originalBranch}\`\n`
|
|
205
|
+
+ ' moves before then — a new commit means a new check.\n';
|
|
258
206
|
}
|
|
259
207
|
/** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */
|
|
260
208
|
async unmergedPaths(repoRoot) {
|
|
261
209
|
const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot, 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');
|
|
262
210
|
return out.split('\n').filter((l) => l.trim() !== '');
|
|
263
211
|
}
|
|
264
|
-
// The gate on
|
|
265
|
-
async assertNoUnmergedPaths(repoRoot
|
|
212
|
+
// The gate on resuming: refuse (and re-print the list) while anything is still unmerged.
|
|
213
|
+
async assertNoUnmergedPaths(repoRoot) {
|
|
266
214
|
const conflicted = await this.unmergedPaths(repoRoot);
|
|
267
215
|
if (conflicted.length === 0)
|
|
268
216
|
return;
|
|
269
217
|
throw new rules_config_1.CliExitError(2, '\n' + SEP + '⛔ Conflicts are NOT resolved yet\n' + SEP + '\n'
|
|
270
|
-
+ `${rules_config_1.
|
|
218
|
+
+ `${rules_config_1.WP_BUILD_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\n`
|
|
271
219
|
+ 'unmerged (edit until no conflict markers remain, then `git add` each one):\n'
|
|
272
220
|
+ conflicted.map((f) => ` ${f}`).join('\n') + '\n\n'
|
|
273
|
-
+ `
|
|
274
|
-
+ `Give up instead with: ${rules_config_1.WP_FINISH_PUSH_DEV} --abort\n`);
|
|
221
|
+
+ `Give up instead with: ${rules_config_1.WP_BUILD_PUSH_DEV} --abort\n`);
|
|
275
222
|
}
|
|
276
223
|
/**
|
|
277
|
-
* The name of the throwaway branch for a
|
|
224
|
+
* The name of the throwaway branch for a check of `branch`.
|
|
278
225
|
*
|
|
279
226
|
* Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`
|
|
280
227
|
* convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.
|
|
@@ -282,25 +229,13 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
282
229
|
tmpBranchFor(branch) {
|
|
283
230
|
return `${branch}DevResolve`;
|
|
284
231
|
}
|
|
285
|
-
/** The banner
|
|
232
|
+
/** The banner `wp-build-push-dev` prints before its check against dev. */
|
|
286
233
|
announce(cfg, state) {
|
|
287
|
-
return '\n' + SEP +
|
|
288
|
-
+ `Merging
|
|
289
|
-
+
|
|
290
|
-
+
|
|
291
|
-
+
|
|
292
|
-
+ `Your feature branch \`${state.originalBranch}\` is not touched by any of this.\n`
|
|
293
|
-
+ 'A clean run publishes nothing (CI already composes it). A resolved conflict is published as your copy\n'
|
|
294
|
-
+ 'plus ONE commit holding the resolved files — never a merge, so no other copy enters its history.\n'
|
|
295
|
-
+ `${rules_config_1.WP_FINISH_PUSH_DEV} is only needed if a merge stops.\n\n`;
|
|
296
|
-
}
|
|
297
|
-
/** The banner plain `wp-push-dev` prints before its check against dev (#1397). */
|
|
298
|
-
announcePrebuild(cfg, state) {
|
|
299
|
-
return '\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch} before publishing\n` + SEP + '\n'
|
|
300
|
-
+ `Merging origin/${cfg.devBranch} into the throwaway branch \`${state.tmpBranch}\`, then running\n`
|
|
301
|
-
+ '`commands.push-dev.buildCommand` on the merged tree. Only if both pass is the copy published — as\n'
|
|
302
|
-
+ 'your branch, plus ONE commit holding any resolved files. The merge itself is never published, so a\n'
|
|
303
|
-
+ `later \`${rules_config_1.WP_PUSH_DEV} --remove\` of somebody else's copy cannot leave it on dev through yours.\n`
|
|
234
|
+
return '\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch}\n` + SEP + '\n'
|
|
235
|
+
+ `Merging origin/${cfg.devBranch} into the throwaway branch \`${state.tmpBranch}\`, then running \`pnpm install\`\n`
|
|
236
|
+
+ 'and `commands.push-dev.buildCommand` on the merged tree. Nothing is published here — when both pass,\n'
|
|
237
|
+
+ `${rules_config_1.WP_FINISH_PUSH_DEV} publishes your branch, plus ONE commit holding any resolved files. The merge\n`
|
|
238
|
+
+ 'itself is never published.\n'
|
|
304
239
|
+ `Your feature branch \`${state.originalBranch}\` is not touched by any of this.\n\n`;
|
|
305
240
|
}
|
|
306
241
|
};
|
|
@@ -310,7 +245,8 @@ exports.DevResolveRunner = DevResolveRunner = tslib_1.__decorate([
|
|
|
310
245
|
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec,
|
|
311
246
|
dev_deploy_refs_1.DevDeployRefs,
|
|
312
247
|
push_dev_state_1.PushDevStateStore,
|
|
313
|
-
|
|
314
|
-
dev_build_1.DevBuild
|
|
248
|
+
verified_dev_copy_1.VerifiedDevCopyStore,
|
|
249
|
+
dev_build_1.DevBuild,
|
|
250
|
+
tooling_common_1.NativeProcessApi])
|
|
315
251
|
], DevResolveRunner);
|
|
316
252
|
//# sourceMappingURL=dev-resolve-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-resolve-runner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-resolve-runner.ts"],"names":[],"mappings":";;;;AAAA,0DAAyG;AACzG,iEAA6D;AAC7D,yCAA2D;AAE3D,yCAAqC;AACrC,uDAAkD;AAClD,qDAAmF;AACnF,qEAA+D;AAC/D,2CAAuC;AAEvC,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,qCAAqC,CAAC;AAExE;;;;;;;;;;GAUG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IACA;IACA;IACA;IALrB,YACqB,OAAgB,EAChB,IAAmB,EACnB,KAAwB,EACxB,UAA+B,EAC/B,QAAkB;QAJlB,YAA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CAAC;IAED,kFAAkF;IAClF,gBAAgB,CAAC,GAAoB,EAAE,KAAmB;QACtD,OAAO,IAAI,GAAG,GAAG,GAAG,eAAe,KAAK,CAAC,SAAS,mBAAmB,GAAG,CAAC,SAAS,sBAAsB,GAAG,GAAG,GAAG,IAAI;cAC/G,kBAAkB,GAAG,CAAC,SAAS,gCAAgC,KAAK,CAAC,SAAS,oBAAoB;cAClG,qGAAqG;cACrG,sGAAsG;cACtG,WAAW,0BAAW,6EAA6E;cACnG,yBAAyB,KAAK,CAAC,cAAc,uCAAuC,CAAC;IAC/F,CAAC;CACJ,CAAA;AAtSY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QACZ,4CAAmB;QACrB,oBAAQ;GAN9B,gBAAgB,CAsS5B","sourcesContent":["import { CliExitError, DevDeployConfig, WP_FINISH_PUSH_DEV, WP_PUSH_DEV } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\nimport { DevDeployRefs } from './dev-deploy-refs';\nimport { DevResolveMode, PushDevState, PushDevStateStore } from './push-dev-state';\nimport { DevDeployWatchHints } from './dev-deploy-watch-hints';\nimport { DevBuild } from './dev-build';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The subject prefix of the ONE commit this flow writes onto a copy: the recorded conflict resolution.\n * The clobber guard reads it — a remote-only commit with this subject is re-derived by the next publish's\n * check against dev, so replacing it destroys nothing; any other remote-only commit is somebody's work.\n */\nexport const RESOLUTION_SUBJECT = 'Dev-deploy: conflict resolution for';\n\n/**\n * The queue-draining engine behind `wp-push-dev` (its pre-publish check against dev, #1397),\n * `wp-push-dev --resolve`, `--rebase-resolution`, and `wp-finish-push-dev`.\n *\n * ONE class owns every git WRITE in the resolve flow, and that is a hard requirement rather than tidiness:\n * `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and\n * `pr-creation-or-push-guard` blocks every `git push`. So an AI cannot be told \"now run `git commit`\" or\n * \"`git merge --continue`\" — those instructions are unrunnable by the only party reading them. The command\n * owns the merges, the commit and the push (as child processes the hooks never see); the AI's entire job is\n * editing the conflicted files and `git add`-ing them, neither of which is blocked.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevResolveRunner {\n constructor(\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly watchHints: DevDeployWatchHints,\n private readonly devBuild: DevBuild,\n ) {}\n\n /**\n * Start a resolve: park on a throwaway branch at the current copy, then drain the queue.\n *\n * The checkout is `-B <tmp> <base>` and NEVER the feature branch, which is the cardinal constraint made\n * mechanical — every merge below lands on a branch that is deleted at the end, so no other developer's\n * commits can reach the PR head even if the resolve is abandoned halfway.\n *\n * `base` differs between the callers and the difference IS the semantics. A plain publish starts at the\n * LOCAL HEAD and merges `origin/<devBranch>` in (does this copy merge and build against what is already\n * on dev?). `--resolve` starts at the published copy and merges the other copies in (compose what CI\n * will build). `--rebase-resolution` starts at the LOCAL HEAD and merges the published copy in (replay\n * an existing resolution on top of the new commits, instead of force-pushing over it). What is finally\n * PUBLISHED is the state's DevResolveMode's decision — see finalize.\n *\n * `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is\n * also its push destination, so \"everything to fetch\" and \"everything to merge\" are not the same list.\n */\n async start(repoRoot: string, state: PushDevState, base: string, fetchRefs: string[]): Promise<void> {\n await this.refs.fetchCopies(repoRoot, fetchRefs);\n // Pinned to a SHA after the fetch: the resolution is recorded on top of exactly what was merged,\n // even if the copy (or the feature branch) moves while a conflict is being resolved.\n state.baseSha = await this.refs.headSha(repoRoot, base);\n this.store.write(repoRoot, state);\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'checkout', '-B', state.tmpBranch, base],\n `Failed to create the throwaway resolve branch ${state.tmpBranch}`);\n await this.drain(repoRoot, state);\n }\n\n /**\n * Resume after the human/AI has resolved the halted merge: commit it, then keep draining.\n *\n * REFETCHES the remaining queue first. A resolution session can run long, and queuing against refs\n * fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling\n * update flow is still known to have (only its stage ① ever fetches).\n */\n async resume(repoRoot: string, state: PushDevState): Promise<void> {\n await this.assertNoUnmergedPaths(repoRoot, state);\n await this.gitExec.assertNoUntracked(repoRoot);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');\n await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'],\n `Failed to commit the resolution of ${state.current}`);\n process.stdout.write(`✅ Committed the resolution of ${state.current}.\\n`);\n state.current = '';\n await this.refs.fetchCopies(repoRoot, state.queue);\n await this.drain(repoRoot, state);\n }\n\n /**\n * Throw the whole resolve away: undo any halted merge, go back to the original branch, delete the\n * throwaway branch and the state file. Nothing published, nothing on the feature branch.\n */\n async abort(repoRoot: string, state: PushDevState): Promise<void> {\n // Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is\n // not an error condition — the rest of the teardown must still run.\n await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n await this.restore(repoRoot, state);\n process.stdout.write(\n '\\n' + SEP + '🛑 Dev-deploy resolve aborted\\n' + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`; \\`${state.tmpBranch}\\` and the state file are gone.\\n`\n + `The remote copy \\`${state.targetRef}\\` is untouched, and so is your feature branch.\\n`);\n }\n\n /**\n * Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).\n *\n * A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a\n * single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.\n */\n private async drain(repoRoot: string, state: PushDevState): Promise<void> {\n while (state.queue.length > 0) {\n const ref = state.queue[0];\n state.queue = state.queue.slice(1);\n const outcome = await this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`],\n repoRoot);\n if (outcome.ok) {\n process.stdout.write(` ✓ merged ${ref}\\n`);\n continue;\n }\n state.current = ref;\n await this.halt(repoRoot, state);\n return;\n }\n await this.finalize(repoRoot, state);\n }\n\n /** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = \"your turn\". */\n private async halt(repoRoot: string, state: PushDevState): Promise<never> {\n const conflicted = await this.unmergedPaths(repoRoot);\n // Remembered so the finish records EXACTLY these files as the resolution — and nothing else the\n // merge brought in, which is other developers' work.\n for (const file of conflicted) if (!state.resolvedPaths.includes(file)) state.resolvedPaths.push(file);\n this.store.write(repoRoot, state);\n const remaining = state.queue.length > 0\n ? `\\nStill queued after this one: ${state.queue.join(', ')}\\n`\n + `\\`${WP_FINISH_PUSH_DEV}\\` resumes the queue, so it may stop again on a later ref.\\n`\n : '';\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ CONFLICT merging ${state.current}\\n` + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\` — NOT \\`${state.originalBranch}\\`. Nothing here\\n`\n + 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\\n\\n'\n + 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n'\n + remaining\n + '\\nThen run ONE of:\\n'\n + ` ${WP_FINISH_PUSH_DEV} ← commit, resume the queue, ${this.buildStep(state)}publish the copy\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n\\n`\n + 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\\n'\n + 'the finish command above does all three for you.\\n');\n }\n\n /**\n * Queue empty. What happens next is the mode's (see DevResolveMode):\n *\n * - PREBUILD runs the dev build on the MERGED tree first, so a red build stops before anything is\n * published.\n * - PREBUILD and COMPOSE then publish the BASE plus the recorded resolution — never the merge. REPLAY\n * publishes the merge, as it always has.\n */\n private async finalize(repoRoot: string, state: PushDevState): Promise<void> {\n if (state.mode === DevResolveMode.PREBUILD) await this.buildOrRestore(repoRoot, state);\n if (state.mode !== DevResolveMode.REPLAY) await this.recordResolution(repoRoot, state);\n // Captured BEFORE the tmp branch is deleted — it is the sha the watch hints are about, and after\n // the restore HEAD is the feature branch, which may be a different commit.\n const published = await this.refs.headSha(repoRoot, state.tmpBranch);\n if (state.mode === DevResolveMode.COMPOSE && published === state.baseSha) {\n await this.restore(repoRoot, state);\n process.stdout.write(\n '\\n' + SEP + `✅ ${state.targetRef} composes cleanly — nothing to publish\\n` + SEP + '\\n'\n + 'Every other copy merged onto it without a conflict, so your CI composes it as it is. The copy\\n'\n + `is unchanged, and you are back on \\`${state.originalBranch}\\`.\\n`);\n return;\n }\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'push', ...this.pushSafety(state), 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`],\n `Failed to publish the dev copy ${state.targetRef}`);\n await this.restore(repoRoot, state);\n process.stdout.write(this.publishedBanner(state)\n + this.watchHints.render(this.refs.config(repoRoot), state.targetRef, published));\n }\n\n /**\n * Run the dev build on the merged throwaway. On a red build, put the checkout back first — the fix\n * belongs on the feature branch, and a developer left parked on a throwaway would make the next\n * `wp-*` command act on the wrong branch — then let the build's own failure (with its `FullLog :`\n * pointer) reach the top-level handler unchanged.\n */\n private async buildOrRestore(repoRoot: string, state: PushDevState): Promise<void> {\n process.stdout.write(`\\nBuilding the merged throwaway \\`${state.tmpBranch}\\` before publishing.\\n`);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the build passed; the build's own CliExitError is re-thrown unchanged\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await this.devBuild.run(repoRoot, WP_PUSH_DEV);\n } catch (err: unknown) {\n const error = toError(err);\n await this.restore(repoRoot, state);\n throw error;\n }\n }\n\n /**\n * Turn the throwaway into what gets PUBLISHED: the base sha plus, when anything conflicted, ONE commit\n * that sets each resolved file to its resolved content.\n *\n * This is issue #1397's option (a): the merge is used for the conflict check and the build only, and\n * is never published. Publishing it would make every other copy an ancestor of this one, so a later\n * `--remove` of that copy would leave its commits on dev through ours. The resolution commit has\n * exactly one parent, the base, so the only thing it can carry of anybody else's work is the text of\n * the hunks that were resolved — content, never history.\n */\n private async recordResolution(repoRoot: string, state: PushDevState): Promise<void> {\n const merged = await this.refs.headSha(repoRoot, state.tmpBranch);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, state.baseSha],\n `Failed to move ${state.tmpBranch} back to ${state.baseSha.slice(0, 8)} to record the resolution`);\n if (state.resolvedPaths.length === 0) return;\n for (const file of state.resolvedPaths) {\n const inMerge = await this.gitExec.tryGit(['-C', repoRoot, 'cat-file', '-e', `${merged}:${file}`], repoRoot);\n await this.gitExec.runGitChecked(\n inMerge.ok\n ? ['-C', repoRoot, 'checkout', merged, '--', file]\n : ['-C', repoRoot, 'rm', '-q', '--ignore-unmatch', '--', file],\n `Failed to record the resolution of ${file}`);\n }\n // Resolved to exactly what the base already had (\"keep mine\") is a resolution with nothing to record.\n const unchanged = await this.gitExec.tryGit(['-C', repoRoot, 'diff', '--cached', '--quiet'], repoRoot);\n if (unchanged.ok) return;\n await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '-m',\n `${RESOLUTION_SUBJECT} ${state.targetRef}\\n\\n`\n + 'This commit carries only the files that conflicted and were resolved:\\n'\n + state.resolvedPaths.map((f: string): string => ` ${f}`).join('\\n') + '\\n'],\n `Failed to commit the recorded resolution for ${state.targetRef}`);\n }\n\n /** Back to the original branch; the throwaway and the state file are gone. */\n private async restore(repoRoot: string, state: PushDevState): Promise<void> {\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n }\n\n /**\n * PREBUILD leases against the sha the clobber guard inspected (plain `--force` only when asked); the\n * other two modes overwrite the copy they themselves started from, as they always have.\n */\n private pushSafety(state: PushDevState): string[] {\n if (state.mode !== DevResolveMode.PREBUILD || state.force) return ['--force'];\n if (state.leaseSha === '') return [];\n return [`--force-with-lease=refs/heads/${state.targetRef}:${state.leaseSha}`];\n }\n\n // The halt message names the build only where the finish will actually run one.\n private buildStep(state: PushDevState): string {\n return state.mode === DevResolveMode.PREBUILD ? 'run the dev build, ' : '';\n }\n\n private publishedBanner(state: PushDevState): string {\n const what = state.mode === DevResolveMode.REPLAY\n ? 'your new commits merged with the copy\\'s earlier resolution'\n : state.resolvedPaths.length === 0\n ? 'your branch exactly as it is'\n : `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy became part of its history`;\n return '\\n' + SEP + `✅ Published ${state.targetRef}\\n` + SEP + '\\n'\n + `The copy is ${what}.\\n`\n + `You are back on \\`${state.originalBranch}\\`, which was never modified — verify with:\\n`\n + ` git log --oneline ${state.originalBranch}\\n`\n + 'Your CI will pick the copy up on its next composition run.\\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 }\n\n /** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */\n private async unmergedPaths(repoRoot: string): Promise<string[]> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n return out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n }\n\n // The gate on `wp-finish-push-dev`: refuse (and re-print the list) while anything is still unmerged.\n private async assertNoUnmergedPaths(repoRoot: string, state: PushDevState): Promise<void> {\n const conflicted = await this.unmergedPaths(repoRoot);\n if (conflicted.length === 0) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ Conflicts are NOT resolved yet\\n' + SEP + '\\n'\n + `${WP_FINISH_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\\n`\n + 'unmerged (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n\\n'\n + `Merging: ${state.current === '' ? '(none)' : state.current}\\n`\n + `Give up instead with: ${WP_FINISH_PUSH_DEV} --abort\\n`);\n }\n\n /**\n * The name of the throwaway branch for a resolve of `branch`.\n *\n * Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`\n * convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.\n */\n tmpBranchFor(branch: string): string {\n return `${branch}DevResolve`;\n }\n\n /** The banner `--resolve` prints before the first merge, so the queue is visible before it halts. */\n announce(cfg: DevDeployConfig, state: PushDevState): string {\n return '\\n' + SEP + `🔀 Resolving the dev composition for ${state.targetRef}\\n` + SEP + '\\n'\n + `Merging ${String(state.queue.length)} other cop${state.queue.length === 1 ? 'y' : 'ies'} from `\n + `\\`${cfg.copyRefGlob()}\\`, in the order your CI composes\\n\\`${cfg.devBranch}\\`, onto the throwaway branch `\n + `\\`${state.tmpBranch}\\`:\\n`\n + state.queue.map((r: string): string => ` ${r}`).join('\\n') + '\\n\\n'\n + `Your feature branch \\`${state.originalBranch}\\` is not touched by any of this.\\n`\n + 'A clean run publishes nothing (CI already composes it). A resolved conflict is published as your copy\\n'\n + 'plus ONE commit holding the resolved files — never a merge, so no other copy enters its history.\\n'\n + `${WP_FINISH_PUSH_DEV} is only needed if a merge stops.\\n\\n`;\n }\n\n /** The banner plain `wp-push-dev` prints before its check against dev (#1397). */\n announcePrebuild(cfg: DevDeployConfig, state: PushDevState): string {\n return '\\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch} before publishing\\n` + SEP + '\\n'\n + `Merging origin/${cfg.devBranch} into the throwaway branch \\`${state.tmpBranch}\\`, then running\\n`\n + '`commands.push-dev.buildCommand` on the merged tree. Only if both pass is the copy published — as\\n'\n + 'your branch, plus ONE commit holding any resolved files. The merge itself is never published, so a\\n'\n + `later \\`${WP_PUSH_DEV} --remove\\` of somebody else's copy cannot leave it on dev through yours.\\n`\n + `Your feature branch \\`${state.originalBranch}\\` is not touched by any of this.\\n\\n`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dev-resolve-runner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-resolve-runner.ts"],"names":[],"mappings":";;;;AAAA,0DAA+G;AAC/G,8DAA6D;AAC7D,iEAA6D;AAC7D,yCAA2D;AAE3D,yCAAqC;AACrC,uDAAkD;AAClD,qDAAmE;AACnE,2CAAuC;AACvC,2DAA4E;AAE5E,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;GAEG;AACU,QAAA,kBAAkB,GAAG,qCAAqC,CAAC;AAExE;;;;;;;;;;;;;GAaG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IACA;IACA;IACA;IACA;IANrB,YACqB,OAAgB,EAChB,IAAmB,EACnB,KAAwB,EACxB,QAA8B,EAC9B,QAAkB,EAClB,SAA2B;QAL3B,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAe;QACnB,UAAK,GAAL,KAAK,CAAmB;QACxB,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAkB;IAC7C,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,KAAmB;QAC7C,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QACzD,6FAA6F;QAC7F,8DAA8D;QAC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AgB,CAqO5B","sourcesContent":["import { CliExitError, DevDeployConfig, WP_BUILD_PUSH_DEV, WP_FINISH_PUSH_DEV } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\nimport { DevDeployRefs } from './dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from './push-dev-state';\nimport { DevBuild } from './dev-build';\nimport { VerifiedDevCopy, VerifiedDevCopyStore } from './verified-dev-copy';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The subject prefix of the ONE commit this flow writes onto a copy: the recorded conflict resolution.\n */\nexport const RESOLUTION_SUBJECT = 'Dev-deploy: conflict resolution for';\n\n/**\n * The engine behind `wp-build-push-dev` (#1403): merge `origin/<devBranch>` into a THROWAWAY branch, stop\n * on a conflict, `pnpm install`, run the dev build, and record the copy `wp-finish-push-dev` publishes.\n *\n * ONE class owns every git WRITE of the check, and that is a hard requirement rather than tidiness:\n * `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and\n * `merge-in-progress-guard` blocks `git commit`. So an AI cannot be told \"now run `git commit`\" or\n * \"`git merge --continue`\" — those instructions are unrunnable by the only party reading them. The command\n * owns the merge and the commits (as child processes the hooks never see); the AI's entire job is editing\n * the conflicted files and `git add`-ing them, neither of which is blocked.\n *\n * It NEVER writes to the feature branch: every merge lands on a throwaway that is deleted at the end, so no\n * other developer's commits can reach the PR head even if the check is abandoned halfway.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevResolveRunner {\n constructor(\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly verified: VerifiedDevCopyStore,\n private readonly devBuild: DevBuild,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /**\n * Start the check: park on a throwaway branch at the feature head, merge `origin/<devBranch>` into it,\n * and either halt on a conflict or go straight on to install, build and record.\n */\n async start(repoRoot: string, state: PushDevState): Promise<void> {\n await this.refs.fetchCopies(repoRoot, [state.devBranch]);\n // Pinned to a SHA: the resolution is recorded on top of exactly what was merged, and stage ③\n // refuses to publish when the feature branch has moved since.\n state.baseSha = await this.refs.headSha(repoRoot, 'HEAD');\n this.store.write(repoRoot, state);\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'checkout', '-B', state.tmpBranch, 'HEAD'],\n `Failed to create the throwaway branch ${state.tmpBranch}`);\n const merged = await this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-deploy: merge ${state.devBranch} into ${state.targetRef}`, `refs/remotes/origin/${state.devBranch}`],\n repoRoot);\n if (!merged.ok) await this.halt(repoRoot, state);\n process.stdout.write(` ✓ merged origin/${state.devBranch}\\n`);\n await this.finish(repoRoot, state);\n }\n\n /** Resume after the conflicted files were resolved and `git add`-ed: commit the merge, then finish. */\n async resume(repoRoot: string, state: PushDevState): Promise<void> {\n await this.assertNoUnmergedPaths(repoRoot);\n await this.gitExec.assertNoUntracked(repoRoot);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');\n await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'],\n `Failed to commit the resolution of the merge with origin/${state.devBranch}`);\n process.stdout.write(`✅ Committed the resolution of the merge with origin/${state.devBranch}.\\n`);\n await this.finish(repoRoot, state);\n }\n\n /**\n * Throw the whole check away: undo any halted merge, go back to the original branch, delete the\n * throwaway branch and the state file. Nothing verified, nothing on the feature branch.\n */\n async abort(repoRoot: string, state: PushDevState): Promise<void> {\n await this.restore(repoRoot, state);\n process.stdout.write(\n '\\n' + SEP + '🛑 Dev-deploy check aborted\\n' + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`; \\`${state.tmpBranch}\\` and the state file are gone.\\n`\n + `Nothing was published, and your feature branch is untouched.\\n`);\n }\n\n /** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = \"your turn\". */\n private async halt(repoRoot: string, state: PushDevState): Promise<never> {\n const conflicted = await this.unmergedPaths(repoRoot);\n // Remembered so the finish records EXACTLY these files as the resolution — and nothing else the\n // merge brought in, which is other developers' work.\n state.resolvedPaths = conflicted;\n this.store.write(repoRoot, state);\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ CONFLICT merging origin/${state.devBranch}\\n` + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\` — NOT \\`${state.originalBranch}\\`. Nothing here\\n`\n + 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\\n\\n'\n + 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n'\n + '\\nThen run ONE of:\\n'\n + ` ${WP_BUILD_PUSH_DEV} ← commit the resolution, pnpm install, run the dev build\\n`\n + ` ${WP_BUILD_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n\\n`\n + 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\\n'\n + 'the commands above do them for you.\\n');\n }\n\n /**\n * The merge is complete. Install and build the MERGED tree, then turn the throwaway into the copy and\n * record it for `wp-finish-push-dev`.\n *\n * `pnpm install` runs AFTER the merge, never before: other copies already on dev can add workspace\n * packages main does not have yet, so the feature branch's `node_modules` does not link the merged\n * tree (#1403 — a 30-commits-behind branch failed six minutes into its build on exactly that).\n */\n private async finish(repoRoot: string, state: PushDevState): Promise<void> {\n await this.onThrowaway(repoRoot, state, (): Promise<void> => this.install(repoRoot, state));\n await this.onThrowaway(repoRoot, state, (): Promise<void> => this.devBuild.run(repoRoot, WP_BUILD_PUSH_DEV));\n // The install may rewrite the lockfile on the throwaway; drop that before the throwaway moves.\n await this.gitExec.runGitChecked(['-C', repoRoot, 'reset', '--hard', 'HEAD'],\n `Failed to discard what pnpm install changed on ${state.tmpBranch}`);\n await this.recordResolution(repoRoot, state);\n const copySha = await this.refs.headSha(repoRoot, state.tmpBranch);\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'update-ref', this.verified.keepRef(state.originalBranch), copySha],\n `Failed to keep the verified copy ${copySha.slice(0, 8)} reachable`);\n const devSha = await this.refs.headSha(repoRoot, `refs/remotes/origin/${state.devBranch}`);\n this.verified.write(repoRoot, new VerifiedDevCopy(\n state.originalBranch, state.baseSha, copySha, state.targetRef, state.leaseSha, devSha));\n await this.restore(repoRoot, state);\n process.stdout.write(this.verifiedBanner(state, devSha));\n }\n\n private async install(repoRoot: string, state: PushDevState): Promise<void> {\n process.stdout.write(`\\nRunning pnpm install on the merged throwaway \\`${state.tmpBranch}\\`.\\n`);\n const result = await this.processes.passThrough('pnpm', ['install'], repoRoot);\n if (result.ok) return;\n throw new CliExitError(1,\n '\\n' + SEP + `⛔ pnpm install failed on the merge with origin/${state.devBranch}\\n` + SEP + '\\n'\n + `\\`pnpm install\\` exited ${String(result.code)} on the merged tree (its output is above). No build ran and\\n`\n + `nothing was verified; you are back on \\`${state.originalBranch}\\`. Fix what it reported, then re-run:\\n`\n + ` ${WP_BUILD_PUSH_DEV}\\n`);\n }\n\n /**\n * Run one step on the throwaway. On a failure, put the checkout back first — the fix belongs on the\n * feature branch, and a developer left parked on a throwaway would make the next `wp-*` command act on\n * the wrong branch — then let the step's own failure (a build's carries its `FullLog :` pointer) reach\n * the top-level handler unchanged.\n */\n private async onThrowaway(repoRoot: string, state: PushDevState, step: () => Promise<void>): Promise<void> {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the step passed; the step's own error is re-thrown unchanged\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await step();\n } catch (err: unknown) {\n const error = toError(err);\n await this.restore(repoRoot, state);\n throw error;\n }\n }\n\n /**\n * Turn the throwaway into the copy: the base sha plus, when anything conflicted, ONE commit that sets\n * each resolved file to its resolved content.\n *\n * The merge is used for the conflict check and the build only, and is never published. Publishing it\n * would make every other copy an ancestor of this one, so a later `--remove` of that copy would leave\n * its commits on dev through ours. The resolution commit has exactly one parent, the base, so the only\n * thing it can carry of anybody else's work is the text of the hunks that were resolved — content,\n * never history.\n */\n private async recordResolution(repoRoot: string, state: PushDevState): Promise<void> {\n const merged = await this.refs.headSha(repoRoot, state.tmpBranch);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, state.baseSha],\n `Failed to move ${state.tmpBranch} back to ${state.baseSha.slice(0, 8)} to record the resolution`);\n if (state.resolvedPaths.length === 0) return;\n for (const file of state.resolvedPaths) {\n const inMerge = await this.gitExec.tryGit(['-C', repoRoot, 'cat-file', '-e', `${merged}:${file}`], repoRoot);\n await this.gitExec.runGitChecked(\n inMerge.ok\n ? ['-C', repoRoot, 'checkout', merged, '--', file]\n : ['-C', repoRoot, 'rm', '-q', '--ignore-unmatch', '--', file],\n `Failed to record the resolution of ${file}`);\n }\n // Resolved to exactly what the base already had (\"keep mine\") is a resolution with nothing to record.\n const unchanged = await this.gitExec.tryGit(['-C', repoRoot, 'diff', '--cached', '--quiet'], repoRoot);\n if (unchanged.ok) return;\n await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '-m',\n `${RESOLUTION_SUBJECT} ${state.targetRef}\\n\\n`\n + 'This commit carries only the files that conflicted and were resolved:\\n'\n + state.resolvedPaths.map((f: string): string => ` ${f}`).join('\\n') + '\\n'],\n `Failed to commit the recorded resolution for ${state.targetRef}`);\n }\n\n /** Back to the original branch; any halted merge, the throwaway and the state file are gone. */\n private async restore(repoRoot: string, state: PushDevState): Promise<void> {\n // Only ever on the throwaway: a reset anywhere else could destroy somebody's uncommitted work.\n // Both allowed to fail: there is no merge to abort once it completed, and nothing to reset on a\n // clean tree. Neither is an error — the rest of the teardown must still run.\n if (await this.gitExec.currentBranch(repoRoot) === state.tmpBranch) {\n await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n await this.gitExec.tryGit(['-C', repoRoot, 'reset', '--hard', 'HEAD'], repoRoot);\n }\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n }\n\n private verifiedBanner(state: PushDevState, devSha: string): string {\n const what = state.resolvedPaths.length === 0\n ? 'your branch exactly as it is'\n : `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy becomes part of its history`;\n return '\\n' + SEP + `✅ ${state.targetRef} is verified against origin/${state.devBranch}\\n` + SEP + '\\n'\n + `It merges with origin/${state.devBranch} (${devSha.slice(0, 8)}), pnpm install ran on the merged tree, and the dev\\n`\n + `build is green. The copy to publish is ${what}.\\n`\n + `You are back on \\`${state.originalBranch}\\`, which this check never modified.\\n\\n`\n + `▶ NEXT run: ${WP_FINISH_PUSH_DEV}\\n`\n + ` It publishes the verified copy as \\`${state.targetRef}\\`. It refuses if \\`${state.originalBranch}\\`\\n`\n + ' moves before then — a new commit means a new check.\\n';\n }\n\n /** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */\n private async unmergedPaths(repoRoot: string): Promise<string[]> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n return out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n }\n\n // The gate on resuming: refuse (and re-print the list) while anything is still unmerged.\n private async assertNoUnmergedPaths(repoRoot: string): Promise<void> {\n const conflicted = await this.unmergedPaths(repoRoot);\n if (conflicted.length === 0) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ Conflicts are NOT resolved yet\\n' + SEP + '\\n'\n + `${WP_BUILD_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\\n`\n + 'unmerged (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n\\n'\n + `Give up instead with: ${WP_BUILD_PUSH_DEV} --abort\\n`);\n }\n\n /**\n * The name of the throwaway branch for a check of `branch`.\n *\n * Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`\n * convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.\n */\n tmpBranchFor(branch: string): string {\n return `${branch}DevResolve`;\n }\n\n /** The banner `wp-build-push-dev` prints before its check against dev. */\n announce(cfg: DevDeployConfig, state: PushDevState): string {\n return '\\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch}\\n` + SEP + '\\n'\n + `Merging origin/${cfg.devBranch} into the throwaway branch \\`${state.tmpBranch}\\`, then running \\`pnpm install\\`\\n`\n + 'and `commands.push-dev.buildCommand` on the merged tree. Nothing is published here — when both pass,\\n'\n + `${WP_FINISH_PUSH_DEV} publishes your branch, plus ONE commit holding any resolved files. The merge\\n`\n + 'itself is never published.\\n'\n + `Your feature branch \\`${state.originalBranch}\\` is not touched by any of this.\\n\\n`;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GitExec } from './git-exec';
|
|
2
|
+
/**
|
|
3
|
+
* "Does this branch already contain the latest `origin/main`?" — the question both ends of the dev-deploy
|
|
4
|
+
* flow ask (#1403). `wp-start-push-dev` asks it to decide whether to run the 3-point merge at all (it runs
|
|
5
|
+
* ONLY when the branch is behind), and `wp-build-push-dev` asks it to refuse a copy built from a stale
|
|
6
|
+
* fork point: such a copy builds against a `node_modules` missing whatever main added since, while dev
|
|
7
|
+
* already contains it.
|
|
8
|
+
*
|
|
9
|
+
* Always FETCHES first. A local `origin/main` from last week answers "contains main" confidently and
|
|
10
|
+
* wrongly, which is the exact staleness this check exists to catch.
|
|
11
|
+
*/
|
|
12
|
+
export declare class MainFreshness {
|
|
13
|
+
private readonly gitExec;
|
|
14
|
+
constructor(gitExec: GitExec);
|
|
15
|
+
containsLatestMain(repoRoot: string): Promise<boolean>;
|
|
16
|
+
}
|