@leitwerk-dev/coding 0.1.8 → 0.2.0
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/README.md +7 -2
- package/dist/auto-work-branch.js +86 -86
- package/dist/auto-work-branch.js.map +1 -1
- package/dist/{chunk-YWGLBUFT.js → chunk-73LKROYK.js} +162 -154
- package/dist/chunk-73LKROYK.js.map +1 -0
- package/dist/{chunk-RZ54IVY5.js → chunk-EP3ZC37F.js} +1 -4
- package/dist/chunk-EP3ZC37F.js.map +1 -0
- package/dist/{chunk-RWCLBBB2.js → chunk-WQEPA35Z.js} +1 -4
- package/dist/chunk-WQEPA35Z.js.map +1 -0
- package/dist/finalization-git.d.ts +6 -1
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +13 -559
- package/dist/finalization-git.js.map +1 -1
- package/dist/index.js +650 -6
- package/dist/index.js.map +1 -1
- package/dist/repository-change-launch.js +17 -182
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-state.js +12 -51
- package/dist/repository-change-state.js.map +1 -1
- package/dist/turns/generate-commit-message.js +9 -38
- package/dist/turns/generate-commit-message.js.map +1 -1
- package/dist/turns/generate-plan.js +7 -19
- package/dist/turns/generate-plan.js.map +1 -1
- package/dist/turns/implement.js +7 -17
- package/dist/turns/implement.js.map +1 -1
- package/dist/turns/resolve-merge-conflict.js +7 -21
- package/dist/turns/resolve-merge-conflict.js.map +1 -1
- package/dist/turns/review-implementation.d.ts +0 -1
- package/dist/turns/review-implementation.d.ts.map +1 -1
- package/dist/turns/review-implementation.js +7 -27
- package/dist/turns/review-implementation.js.map +1 -1
- package/dist/turns/review-plan.d.ts +0 -1
- package/dist/turns/review-plan.d.ts.map +1 -1
- package/dist/turns/review-plan.js +7 -21
- package/dist/turns/review-plan.js.map +1 -1
- package/dist/turns/simplify-implementation.js +7 -7
- package/dist/turns/simplify-implementation.js.map +1 -1
- package/package.json +5 -4
- package/src/finalization-git.ts +209 -166
- package/src/repository-change-process.ts +85 -249
- package/src/turns/review-implementation.ts +0 -3
- package/src/turns/review-plan.ts +0 -3
- package/dist/actions.js +0 -45
- package/dist/actions.js.map +0 -1
- package/dist/chunk-RWCLBBB2.js.map +0 -1
- package/dist/chunk-RZ54IVY5.js.map +0 -1
- package/dist/chunk-YWGLBUFT.js.map +0 -1
- package/dist/repository-change-process.js +0 -757
- package/dist/repository-change-process.js.map +0 -1
package/src/finalization-git.ts
CHANGED
|
@@ -14,6 +14,11 @@ import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
|
14
14
|
|
|
15
15
|
export type DeterministicFinalizationMergeMode = "noop" | "fast_forward" | "merge_commit";
|
|
16
16
|
|
|
17
|
+
export interface GitIdentity {
|
|
18
|
+
name: string;
|
|
19
|
+
email: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
interface DeterministicFinalizationInput {
|
|
18
23
|
repoPath: string;
|
|
19
24
|
workspaceClonePath: string;
|
|
@@ -22,6 +27,7 @@ interface DeterministicFinalizationInput {
|
|
|
22
27
|
expectedPostConflictHeadSha?: string | null;
|
|
23
28
|
usedConflictResolution?: boolean;
|
|
24
29
|
commitMessage: string;
|
|
30
|
+
gitIdentity?: GitIdentity;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
export type DeterministicFinalizationResult =
|
|
@@ -57,7 +63,6 @@ interface GitExecResult {
|
|
|
57
63
|
ok: boolean;
|
|
58
64
|
stdout: string;
|
|
59
65
|
stderr: string;
|
|
60
|
-
status: number | null;
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
interface LocalSourceRepo {
|
|
@@ -106,9 +111,19 @@ function gitConfigIdentityEnv(): NodeJS.ProcessEnv {
|
|
|
106
111
|
return env;
|
|
107
112
|
}
|
|
108
113
|
|
|
109
|
-
function
|
|
114
|
+
function gitIdentityArgs(identity: GitIdentity): string[] {
|
|
115
|
+
const name = trimToNull(identity.name);
|
|
116
|
+
const email = trimToNull(identity.email);
|
|
117
|
+
if (!name || !email || /[\r\n\0]/.test(name) || /[\r\n\0]/.test(email)) {
|
|
118
|
+
throw new DeterministicGitError("Git identity requires a valid name and email");
|
|
119
|
+
}
|
|
120
|
+
return ["-c", `user.name=${name}`, "-c", `user.email=${email}`];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function runGit(repoPath: string, args: readonly string[], identity?: GitIdentity): GitExecResult {
|
|
124
|
+
const trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;
|
|
110
125
|
try {
|
|
111
|
-
const stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(
|
|
126
|
+
const stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {
|
|
112
127
|
cwd: repoPath,
|
|
113
128
|
encoding: "utf8",
|
|
114
129
|
env: gitConfigIdentityEnv(),
|
|
@@ -118,42 +133,40 @@ function runGit(repoPath: string, args: readonly string[]): GitExecResult {
|
|
|
118
133
|
ok: true,
|
|
119
134
|
stdout,
|
|
120
135
|
stderr: "",
|
|
121
|
-
status: 0,
|
|
122
136
|
};
|
|
123
137
|
} catch (error) {
|
|
124
138
|
const execError = error as {
|
|
125
|
-
status?: number | null;
|
|
126
139
|
stdout?: string | Buffer;
|
|
127
140
|
stderr?: string | Buffer;
|
|
128
141
|
message?: string;
|
|
129
142
|
};
|
|
130
143
|
return {
|
|
131
144
|
ok: false,
|
|
132
|
-
stdout:
|
|
133
|
-
|
|
134
|
-
? execError.stdout
|
|
135
|
-
: execError.stdout
|
|
136
|
-
? execError.stdout.toString("utf8")
|
|
137
|
-
: "",
|
|
138
|
-
stderr:
|
|
139
|
-
typeof execError.stderr === "string"
|
|
140
|
-
? execError.stderr
|
|
141
|
-
: execError.stderr
|
|
142
|
-
? execError.stderr.toString("utf8")
|
|
143
|
-
: (trimToNull(execError.message) ?? ""),
|
|
144
|
-
status: execError.status ?? null,
|
|
145
|
+
stdout: execError.stdout?.toString() ?? "",
|
|
146
|
+
stderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? "",
|
|
145
147
|
};
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
+
function gitFailureDetail(result: GitExecResult): string {
|
|
152
|
+
return trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function checkedGit(
|
|
156
|
+
repoPath: string,
|
|
157
|
+
args: readonly string[],
|
|
158
|
+
failureMessage: string,
|
|
159
|
+
identity?: GitIdentity,
|
|
160
|
+
): string {
|
|
161
|
+
const result = runGit(repoPath, args, identity);
|
|
151
162
|
if (!result.ok) {
|
|
152
|
-
throw new DeterministicGitError(
|
|
153
|
-
`git ${args.join(" ")} failed in '${repoPath}': ${trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error"}`,
|
|
154
|
-
);
|
|
163
|
+
throw new DeterministicGitError(`${failureMessage}: ${gitFailureDetail(result)}`);
|
|
155
164
|
}
|
|
156
|
-
return result.stdout
|
|
165
|
+
return result.stdout;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function git(repoPath: string, ...args: string[]): string {
|
|
169
|
+
return checkedGit(repoPath, args, `git ${args.join(" ")} failed in '${repoPath}'`).trim();
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
function gitOrNull(repoPath: string, ...args: string[]): string | null {
|
|
@@ -232,15 +245,14 @@ function resolveLocalSourceRepo(repoPath: string): LocalSourceRepo | null {
|
|
|
232
245
|
};
|
|
233
246
|
}
|
|
234
247
|
|
|
235
|
-
function workingTreeStatus(repoPath: string):
|
|
248
|
+
function workingTreeStatus(repoPath: string): string[] {
|
|
236
249
|
const rawStatus = gitOrNull(repoPath, "status", "--porcelain");
|
|
237
|
-
|
|
250
|
+
return (rawStatus ?? "")
|
|
238
251
|
.split(/\r?\n/)
|
|
239
252
|
.map((line) => line.replace(/\s+$/, ""))
|
|
240
253
|
.filter((line) => line !== "")
|
|
241
254
|
.map((line) => line.slice(2).trim())
|
|
242
255
|
.filter((line) => line !== "");
|
|
243
|
-
return { dirtyFiles };
|
|
244
256
|
}
|
|
245
257
|
|
|
246
258
|
function conflictedFiles(repoPath: string): string[] {
|
|
@@ -265,46 +277,66 @@ function assertExpectedCheckout(repoPath: string, workBranch: string): void {
|
|
|
265
277
|
}
|
|
266
278
|
}
|
|
267
279
|
|
|
268
|
-
function
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
280
|
+
function assertFinalizationCheckout(input: {
|
|
281
|
+
repoPath: string;
|
|
282
|
+
workBranch: string;
|
|
283
|
+
commitMessage: string;
|
|
284
|
+
missingCommitMessage: string;
|
|
285
|
+
}): void {
|
|
286
|
+
if (!repoExists(input.repoPath)) {
|
|
272
287
|
throw new DeterministicGitError(
|
|
273
|
-
|
|
288
|
+
`Repository workspace '${input.repoPath}' does not exist or is not a git repository`,
|
|
274
289
|
);
|
|
275
290
|
}
|
|
291
|
+
assertExpectedCheckout(input.repoPath, input.workBranch);
|
|
292
|
+
if (!trimToNull(input.commitMessage)) {
|
|
293
|
+
throw new DeterministicGitError(input.missingCommitMessage);
|
|
294
|
+
}
|
|
276
295
|
}
|
|
277
296
|
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
282
|
-
throw new DeterministicGitError(
|
|
283
|
-
`Failed to stage the completed change: ${trimToNull(addResult.stderr) ?? trimToNull(addResult.stdout) ?? "unknown git error"}`,
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
const commitResult = runGit(repoPath, [
|
|
287
|
-
"-c",
|
|
288
|
-
"core.hooksPath=/dev/null",
|
|
289
|
-
"commit",
|
|
290
|
-
"--no-gpg-sign",
|
|
291
|
-
"-m",
|
|
292
|
-
commitMessage,
|
|
293
|
-
]);
|
|
294
|
-
if (!commitResult.ok) {
|
|
297
|
+
function assertGitIdentity(repoPath: string, identity?: GitIdentity): void {
|
|
298
|
+
const author = runGit(repoPath, ["var", "GIT_AUTHOR_IDENT"], identity);
|
|
299
|
+
const committer = runGit(repoPath, ["var", "GIT_COMMITTER_IDENT"], identity);
|
|
300
|
+
if (!author.ok || !committer.ok) {
|
|
295
301
|
throw new DeterministicGitError(
|
|
296
|
-
|
|
302
|
+
"Git author/committer identity is not configured. Configure user.name and user.email in this repository or the operator's global Git config, then retry finalization.",
|
|
297
303
|
);
|
|
298
304
|
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function commitDirtyWorktree(
|
|
308
|
+
repoPath: string,
|
|
309
|
+
commitMessage: string,
|
|
310
|
+
identity?: GitIdentity,
|
|
311
|
+
): string {
|
|
312
|
+
assertGitIdentity(repoPath, identity);
|
|
313
|
+
checkedGit(repoPath, ["add", "--all"], "Failed to stage the completed change");
|
|
314
|
+
checkedGit(
|
|
315
|
+
repoPath,
|
|
316
|
+
["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", commitMessage],
|
|
317
|
+
"Failed to commit the completed change",
|
|
318
|
+
identity,
|
|
319
|
+
);
|
|
299
320
|
const remaining = workingTreeStatus(repoPath);
|
|
300
|
-
if (remaining.
|
|
321
|
+
if (remaining.length > 0) {
|
|
301
322
|
throw new DeterministicGitError(
|
|
302
|
-
`Deterministic commit left uncommitted changes: ${remaining.
|
|
323
|
+
`Deterministic commit left uncommitted changes: ${remaining.join(", ")}`,
|
|
303
324
|
);
|
|
304
325
|
}
|
|
305
326
|
return currentHeadSha(repoPath);
|
|
306
327
|
}
|
|
307
328
|
|
|
329
|
+
function commitIfDirty(input: {
|
|
330
|
+
repoPath: string;
|
|
331
|
+
commitMessage: string;
|
|
332
|
+
gitIdentity?: GitIdentity;
|
|
333
|
+
}): string {
|
|
334
|
+
const status = workingTreeStatus(input.repoPath);
|
|
335
|
+
return status.length > 0
|
|
336
|
+
? commitDirtyWorktree(input.repoPath, input.commitMessage, input.gitIdentity)
|
|
337
|
+
: currentHeadSha(input.repoPath);
|
|
338
|
+
}
|
|
339
|
+
|
|
308
340
|
function assertPostConflictCheckpoint(
|
|
309
341
|
input: DeterministicFinalizationInput,
|
|
310
342
|
repoPath: string,
|
|
@@ -318,21 +350,16 @@ function assertPostConflictCheckpoint(
|
|
|
318
350
|
);
|
|
319
351
|
}
|
|
320
352
|
const status = workingTreeStatus(repoPath);
|
|
321
|
-
if (status.
|
|
353
|
+
if (status.length > 0) {
|
|
322
354
|
throw new DeterministicGitError(
|
|
323
|
-
`Conflict-resolution helper reported a clean merge, but the repository still has uncommitted changes: ${status.
|
|
355
|
+
`Conflict-resolution helper reported a clean merge, but the repository still has uncommitted changes: ${status.join(", ")}`,
|
|
324
356
|
);
|
|
325
357
|
}
|
|
326
358
|
}
|
|
327
359
|
|
|
328
360
|
function fetchOriginBase(repoPath: string, baseBranch: string): string {
|
|
329
361
|
const ref = originBaseRef(baseBranch);
|
|
330
|
-
|
|
331
|
-
if (!fetchResult.ok) {
|
|
332
|
-
throw new DeterministicGitError(
|
|
333
|
-
`Failed to fetch '${ref}': ${trimToNull(fetchResult.stderr) ?? trimToNull(fetchResult.stdout) ?? "unknown git error"}`,
|
|
334
|
-
);
|
|
335
|
-
}
|
|
362
|
+
checkedGit(repoPath, ["fetch", "origin", baseBranch], `Failed to fetch '${ref}'`);
|
|
336
363
|
const baseSha = gitOrNull(repoPath, "rev-parse", ref);
|
|
337
364
|
if (!baseSha) {
|
|
338
365
|
throw new DeterministicGitError(`Fetched '${ref}' but could not resolve its commit sha`);
|
|
@@ -349,6 +376,7 @@ function deterministicMerge(input: {
|
|
|
349
376
|
baseBranch: string;
|
|
350
377
|
headBefore: string;
|
|
351
378
|
baseSha: string;
|
|
379
|
+
gitIdentity?: GitIdentity;
|
|
352
380
|
}):
|
|
353
381
|
| { ok: true; mergeMode: DeterministicFinalizationMergeMode; headSha: string }
|
|
354
382
|
| { ok: false; conflict: true; headSha: string; conflictedFiles: string[] } {
|
|
@@ -362,12 +390,7 @@ function deterministicMerge(input: {
|
|
|
362
390
|
}
|
|
363
391
|
|
|
364
392
|
if (headIsAncestorOfBase) {
|
|
365
|
-
|
|
366
|
-
if (!ffResult.ok) {
|
|
367
|
-
throw new DeterministicGitError(
|
|
368
|
-
`Fast-forward merge from '${ref}' failed: ${trimToNull(ffResult.stderr) ?? trimToNull(ffResult.stdout) ?? "unknown git error"}`,
|
|
369
|
-
);
|
|
370
|
-
}
|
|
393
|
+
checkedGit(repoPath, ["merge", "--ff-only", ref], `Fast-forward merge from '${ref}' failed`);
|
|
371
394
|
return {
|
|
372
395
|
ok: true,
|
|
373
396
|
mergeMode: "fast_forward",
|
|
@@ -375,15 +398,12 @@ function deterministicMerge(input: {
|
|
|
375
398
|
};
|
|
376
399
|
}
|
|
377
400
|
|
|
378
|
-
assertGitIdentity(repoPath);
|
|
379
|
-
const mergeResult = runGit(
|
|
380
|
-
|
|
381
|
-
"core.hooksPath=/dev/null",
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
"--no-gpg-sign",
|
|
385
|
-
ref,
|
|
386
|
-
]);
|
|
401
|
+
assertGitIdentity(repoPath, input.gitIdentity);
|
|
402
|
+
const mergeResult = runGit(
|
|
403
|
+
repoPath,
|
|
404
|
+
["-c", "core.hooksPath=/dev/null", "merge", "--no-edit", "--no-gpg-sign", ref],
|
|
405
|
+
input.gitIdentity,
|
|
406
|
+
);
|
|
387
407
|
if (!mergeResult.ok) {
|
|
388
408
|
const conflicts = conflictedFiles(repoPath);
|
|
389
409
|
if (mergeInProgress(repoPath) || conflicts.length > 0) {
|
|
@@ -395,7 +415,7 @@ function deterministicMerge(input: {
|
|
|
395
415
|
};
|
|
396
416
|
}
|
|
397
417
|
throw new DeterministicGitError(
|
|
398
|
-
`Deterministic merge from '${ref}' failed: ${
|
|
418
|
+
`Deterministic merge from '${ref}' failed: ${gitFailureDetail(mergeResult)}`,
|
|
399
419
|
);
|
|
400
420
|
}
|
|
401
421
|
|
|
@@ -411,12 +431,19 @@ function branchRef(branch: string): string {
|
|
|
411
431
|
return `refs/heads/${branch}`;
|
|
412
432
|
}
|
|
413
433
|
|
|
414
|
-
function
|
|
434
|
+
function pushAndVerify(repoPath: string, branch: string, expectedHeadSha: string): string {
|
|
415
435
|
const pushTarget = `origin/${branch}`;
|
|
416
|
-
|
|
417
|
-
|
|
436
|
+
checkedGit(
|
|
437
|
+
repoPath,
|
|
438
|
+
["push", "origin", `HEAD:${branchRef(branch)}`],
|
|
439
|
+
`Failed to push HEAD to '${pushTarget}'`,
|
|
440
|
+
);
|
|
441
|
+
const remoteHead = gitOrNull(repoPath, "ls-remote", "--heads", "origin", branchRef(branch))
|
|
442
|
+
?.split(/\s+/)[0]
|
|
443
|
+
?.trim();
|
|
444
|
+
if (remoteHead !== expectedHeadSha) {
|
|
418
445
|
throw new DeterministicGitError(
|
|
419
|
-
`
|
|
446
|
+
`Published '${pushTarget}' resolved to '${remoteHead ?? "missing"}', expected '${expectedHeadSha}'`,
|
|
420
447
|
);
|
|
421
448
|
}
|
|
422
449
|
return pushTarget;
|
|
@@ -471,12 +498,11 @@ function pushLocalSourceBaseBranchToOriginIfPresent(input: {
|
|
|
471
498
|
});
|
|
472
499
|
const ref = branchRef(input.baseBranch);
|
|
473
500
|
const pushTarget = originBaseRef(input.baseBranch);
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
501
|
+
checkedGit(
|
|
502
|
+
input.localSourceRepoPath,
|
|
503
|
+
["push", "origin", `${ref}:${ref}`],
|
|
504
|
+
`Failed to push local source repo '${input.localSourceRepoPath}' base branch '${input.baseBranch}' to '${pushTarget}'`,
|
|
505
|
+
);
|
|
480
506
|
return pushTarget;
|
|
481
507
|
}
|
|
482
508
|
|
|
@@ -497,9 +523,9 @@ function assertLocalBaseRepoReady(
|
|
|
497
523
|
);
|
|
498
524
|
}
|
|
499
525
|
const status = workingTreeStatus(localBaseRepoPath);
|
|
500
|
-
if (status.
|
|
526
|
+
if (status.length > 0) {
|
|
501
527
|
throw new DeterministicGitError(
|
|
502
|
-
`Local source repo '${localBaseRepoPath}' must be clean before finalization updates '${baseBranch}': ${status.
|
|
528
|
+
`Local source repo '${localBaseRepoPath}' must be clean before finalization updates '${baseBranch}': ${status.join(", ")}`,
|
|
503
529
|
);
|
|
504
530
|
}
|
|
505
531
|
const actualBaseSha = currentHeadSha(localBaseRepoPath);
|
|
@@ -518,16 +544,11 @@ function mergeWorkBranchIntoLocalBaseRepo(input: {
|
|
|
518
544
|
expectedHeadSha: string;
|
|
519
545
|
}): void {
|
|
520
546
|
assertLocalBaseRepoReady(input.localBaseRepoPath, input.baseBranch, input.expectedBaseSha);
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
"--ff-only",
|
|
524
|
-
`
|
|
525
|
-
|
|
526
|
-
if (!mergeResult.ok) {
|
|
527
|
-
throw new DeterministicGitError(
|
|
528
|
-
`Failed to fast-forward local source repo '${input.localBaseRepoPath}' branch '${input.baseBranch}' from '${input.workBranch}': ${trimToNull(mergeResult.stderr) ?? trimToNull(mergeResult.stdout) ?? "unknown git error"}`,
|
|
529
|
-
);
|
|
530
|
-
}
|
|
547
|
+
checkedGit(
|
|
548
|
+
input.localBaseRepoPath,
|
|
549
|
+
["merge", "--ff-only", `refs/heads/${input.workBranch}`],
|
|
550
|
+
`Failed to fast-forward local source repo '${input.localBaseRepoPath}' branch '${input.baseBranch}' from '${input.workBranch}'`,
|
|
551
|
+
);
|
|
531
552
|
const actualHeadSha = currentHeadSha(input.localBaseRepoPath);
|
|
532
553
|
if (actualHeadSha !== input.expectedHeadSha) {
|
|
533
554
|
throw new DeterministicGitError(
|
|
@@ -541,12 +562,11 @@ function updateLocalBaseRef(repoPath: string, baseBranch: string): void {
|
|
|
541
562
|
if (branch === baseBranch) {
|
|
542
563
|
return;
|
|
543
564
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
565
|
+
checkedGit(
|
|
566
|
+
repoPath,
|
|
567
|
+
["branch", "--force", baseBranch, "HEAD"],
|
|
568
|
+
`Failed to update the local '${baseBranch}' ref to the finalized HEAD`,
|
|
569
|
+
);
|
|
550
570
|
}
|
|
551
571
|
|
|
552
572
|
function buildFinalizationMarkdown(input: {
|
|
@@ -610,49 +630,65 @@ export function commitAndPushWorkBranch(input: {
|
|
|
610
630
|
repoPath: string;
|
|
611
631
|
workBranch: string;
|
|
612
632
|
commitMessage: string;
|
|
633
|
+
gitIdentity: GitIdentity;
|
|
613
634
|
}) {
|
|
614
635
|
const repoPath = path.resolve(input.repoPath);
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if (!trimToNull(input.commitMessage)) {
|
|
622
|
-
throw new DeterministicGitError("A generated commit message is required before publication");
|
|
623
|
-
}
|
|
636
|
+
assertFinalizationCheckout({
|
|
637
|
+
repoPath,
|
|
638
|
+
workBranch: input.workBranch,
|
|
639
|
+
commitMessage: input.commitMessage,
|
|
640
|
+
missingCommitMessage: "A generated commit message is required before publication",
|
|
641
|
+
});
|
|
624
642
|
const conflicts = conflictedFiles(repoPath);
|
|
625
643
|
if (mergeInProgress(repoPath) || conflicts.length > 0) {
|
|
626
644
|
throw new DeterministicGitError(
|
|
627
645
|
`Cannot publish a work branch with unresolved conflicts: ${conflicts.join(", ") || "merge in progress"}`,
|
|
628
646
|
);
|
|
629
647
|
}
|
|
630
|
-
const
|
|
631
|
-
const headSha = dirty
|
|
632
|
-
? commitDirtyWorktree(repoPath, input.commitMessage)
|
|
633
|
-
: currentHeadSha(repoPath);
|
|
634
|
-
const pushTarget = pushHeadToBranch(repoPath, input.workBranch);
|
|
635
|
-
const remoteHead = gitOrNull(
|
|
648
|
+
const headSha = commitIfDirty({
|
|
636
649
|
repoPath,
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
)
|
|
642
|
-
?.split(/\s+/)[0]
|
|
643
|
-
?.trim();
|
|
644
|
-
if (remoteHead !== headSha) {
|
|
645
|
-
throw new DeterministicGitError(
|
|
646
|
-
`Published '${pushTarget}' resolved to '${remoteHead ?? "missing"}', expected '${headSha}'`,
|
|
647
|
-
);
|
|
648
|
-
}
|
|
650
|
+
commitMessage: input.commitMessage,
|
|
651
|
+
gitIdentity: input.gitIdentity,
|
|
652
|
+
});
|
|
653
|
+
const pushTarget = pushAndVerify(repoPath, input.workBranch, headSha);
|
|
649
654
|
return { headSha, pushTarget };
|
|
650
655
|
}
|
|
651
656
|
|
|
652
657
|
export function runDeterministicFinalization<
|
|
653
658
|
TParams,
|
|
654
659
|
TState extends RepositoryChangeFinalizationContextState,
|
|
655
|
-
>(
|
|
660
|
+
>(
|
|
661
|
+
ctx: FlowAutomaticRunContext<TParams, TState>,
|
|
662
|
+
gitIdentity?: GitIdentity,
|
|
663
|
+
): DeterministicFinalizationResult {
|
|
664
|
+
const progressSteps = [
|
|
665
|
+
["validate_checkout", "Validate the repository checkout"],
|
|
666
|
+
["fetch_base", "Fetch and verify the latest base branch"],
|
|
667
|
+
["commit_merge", "Commit changes and integrate the base branch"],
|
|
668
|
+
["publish", "Push the finalized branch"],
|
|
669
|
+
] as const;
|
|
670
|
+
const reportProgress = (
|
|
671
|
+
activeIndex: number | null,
|
|
672
|
+
completedCount: number,
|
|
673
|
+
failure?: { index: number; detail: string },
|
|
674
|
+
) =>
|
|
675
|
+
ctx.reportProgress?.({
|
|
676
|
+
title: "Finalization progress",
|
|
677
|
+
steps: progressSteps.map(([id, label], index) => ({
|
|
678
|
+
id,
|
|
679
|
+
label,
|
|
680
|
+
status:
|
|
681
|
+
index === failure?.index
|
|
682
|
+
? "failed"
|
|
683
|
+
: index < completedCount
|
|
684
|
+
? "completed"
|
|
685
|
+
: index === activeIndex
|
|
686
|
+
? "in_progress"
|
|
687
|
+
: "incomplete",
|
|
688
|
+
...(index === failure?.index ? { detail: failure.detail } : {}),
|
|
689
|
+
})),
|
|
690
|
+
});
|
|
691
|
+
reportProgress(0, 0);
|
|
656
692
|
const repo = ctx.repo.get("repo");
|
|
657
693
|
const input: DeterministicFinalizationInput = {
|
|
658
694
|
repoPath: repo.fsPath,
|
|
@@ -662,24 +698,26 @@ export function runDeterministicFinalization<
|
|
|
662
698
|
expectedPostConflictHeadSha: ctx.state.finalization.expectedPostConflictHeadSha,
|
|
663
699
|
usedConflictResolution: ctx.state.finalization.usedConflictResolution,
|
|
664
700
|
commitMessage: ctx.state.finalization.generatedCommitMessage ?? "",
|
|
701
|
+
gitIdentity,
|
|
665
702
|
};
|
|
666
703
|
const repoPath = path.resolve(input.repoPath);
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
assertExpectedCheckout(repoPath, input.workBranch);
|
|
673
|
-
if (!trimToNull(input.commitMessage)) {
|
|
674
|
-
throw new DeterministicGitError(
|
|
704
|
+
assertFinalizationCheckout({
|
|
705
|
+
repoPath,
|
|
706
|
+
workBranch: input.workBranch,
|
|
707
|
+
commitMessage: input.commitMessage,
|
|
708
|
+
missingCommitMessage:
|
|
675
709
|
"No generated commit message is available; retry commit-message generation before finalization",
|
|
676
|
-
|
|
677
|
-
}
|
|
710
|
+
});
|
|
678
711
|
assertPostConflictCheckpoint(input, repoPath);
|
|
712
|
+
reportProgress(1, 1);
|
|
679
713
|
|
|
680
714
|
let headSha = currentHeadSha(repoPath);
|
|
681
715
|
const conflicts = conflictedFiles(repoPath);
|
|
682
716
|
if (mergeInProgress(repoPath) || conflicts.length > 0) {
|
|
717
|
+
reportProgress(null, 1, {
|
|
718
|
+
index: 2,
|
|
719
|
+
detail: "The checkout already contains merge conflicts",
|
|
720
|
+
});
|
|
683
721
|
return {
|
|
684
722
|
outcome: "merge_conflict",
|
|
685
723
|
params: {
|
|
@@ -697,18 +735,25 @@ export function runDeterministicFinalization<
|
|
|
697
735
|
} else if (localSourceRepo?.kind === "bare") {
|
|
698
736
|
assertLocalBareSourceRepoReady(localSourceRepo.path, input.baseBranch, baseSha);
|
|
699
737
|
}
|
|
738
|
+
reportProgress(2, 2);
|
|
700
739
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
740
|
+
headSha = commitIfDirty({
|
|
741
|
+
repoPath,
|
|
742
|
+
commitMessage: input.commitMessage,
|
|
743
|
+
gitIdentity: input.gitIdentity,
|
|
744
|
+
});
|
|
705
745
|
const mergeResult = deterministicMerge({
|
|
706
746
|
repoPath,
|
|
707
747
|
baseBranch: input.baseBranch,
|
|
708
748
|
headBefore: headSha,
|
|
709
749
|
baseSha,
|
|
750
|
+
gitIdentity: input.gitIdentity,
|
|
710
751
|
});
|
|
711
752
|
if (!mergeResult.ok) {
|
|
753
|
+
reportProgress(null, 2, {
|
|
754
|
+
index: 2,
|
|
755
|
+
detail: "Base integration produced merge conflicts",
|
|
756
|
+
});
|
|
712
757
|
return {
|
|
713
758
|
outcome: "merge_conflict",
|
|
714
759
|
params: {
|
|
@@ -719,39 +764,37 @@ export function runDeterministicFinalization<
|
|
|
719
764
|
};
|
|
720
765
|
}
|
|
721
766
|
|
|
767
|
+
reportProgress(3, 3);
|
|
722
768
|
let pushTarget: string;
|
|
723
769
|
let workspacePushTarget: string | null = null;
|
|
724
770
|
let sourceOriginPushTarget: string | null = null;
|
|
725
|
-
if (localSourceRepo
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
771
|
+
if (localSourceRepo) {
|
|
772
|
+
if (localSourceRepo.kind === "non_bare") {
|
|
773
|
+
assertLocalBaseRepoReady(localSourceRepo.path, input.baseBranch, baseSha);
|
|
774
|
+
workspacePushTarget = pushAndVerify(repoPath, input.workBranch, mergeResult.headSha);
|
|
775
|
+
mergeWorkBranchIntoLocalBaseRepo({
|
|
776
|
+
localBaseRepoPath: localSourceRepo.path,
|
|
777
|
+
baseBranch: input.baseBranch,
|
|
778
|
+
workBranch: input.workBranch,
|
|
779
|
+
expectedBaseSha: baseSha,
|
|
780
|
+
expectedHeadSha: mergeResult.headSha,
|
|
781
|
+
});
|
|
782
|
+
} else {
|
|
783
|
+
assertLocalBareSourceRepoReady(localSourceRepo.path, input.baseBranch, baseSha);
|
|
784
|
+
workspacePushTarget = pushAndVerify(repoPath, input.baseBranch, mergeResult.headSha);
|
|
785
|
+
}
|
|
735
786
|
sourceOriginPushTarget = pushLocalSourceBaseBranchToOriginIfPresent({
|
|
736
787
|
localSourceRepoPath: localSourceRepo.path,
|
|
737
788
|
baseBranch: input.baseBranch,
|
|
738
789
|
expectedHeadSha: mergeResult.headSha,
|
|
739
790
|
});
|
|
740
791
|
pushTarget = sourceOriginPushTarget ?? originBaseRef(input.baseBranch);
|
|
741
|
-
} else if (localSourceRepo?.kind === "bare") {
|
|
742
|
-
assertLocalBareSourceRepoReady(localSourceRepo.path, input.baseBranch, baseSha);
|
|
743
|
-
workspacePushTarget = pushHeadToBranch(repoPath, input.baseBranch);
|
|
744
|
-
sourceOriginPushTarget = pushLocalSourceBaseBranchToOriginIfPresent({
|
|
745
|
-
localSourceRepoPath: localSourceRepo.path,
|
|
746
|
-
baseBranch: input.baseBranch,
|
|
747
|
-
expectedHeadSha: mergeResult.headSha,
|
|
748
|
-
});
|
|
749
|
-
pushTarget = sourceOriginPushTarget ?? workspacePushTarget;
|
|
750
792
|
} else {
|
|
751
|
-
pushTarget =
|
|
793
|
+
pushTarget = pushAndVerify(repoPath, input.baseBranch, mergeResult.headSha);
|
|
752
794
|
}
|
|
753
795
|
updateLocalBaseRef(repoPath, input.baseBranch);
|
|
754
796
|
const finalHeadSha = currentHeadSha(repoPath);
|
|
797
|
+
reportProgress(null, 4);
|
|
755
798
|
return {
|
|
756
799
|
outcome: "finalized",
|
|
757
800
|
params: {
|