@memnexus-ai/mx-agent-cli 0.1.305 → 0.1.307
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/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +1 -1
- package/dist/agent-config/agents/git-expert.md +23 -2
- package/dist/agent-config/claude-md/CLAUDE.core.md +1 -1
- package/dist/agent-config/skills/mx-post-merge-sync/SKILL.md +8 -3
- package/dist/lib/coordination-worktree.d.ts +26 -0
- package/dist/lib/coordination-worktree.d.ts.map +1 -1
- package/dist/lib/coordination-worktree.js +3 -1
- package/dist/lib/coordination-worktree.js.map +1 -1
- package/dist/lib/team-restore.d.ts +56 -1
- package/dist/lib/team-restore.d.ts.map +1 -1
- package/dist/lib/team-restore.js +289 -4
- package/dist/lib/team-restore.js.map +1 -1
- package/dist/lib/worktree-sync.d.ts +119 -17
- package/dist/lib/worktree-sync.d.ts.map +1 -1
- package/dist/lib/worktree-sync.js +270 -40
- package/dist/lib/worktree-sync.js.map +1 -1
- package/dist/standards/decision-request.md +3 -7
- package/dist/standards/report-format.md +0 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-sync.d.ts","sourceRoot":"","sources":["../../src/lib/worktree-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AA+BH;gFACgF;AAChF,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AAEzD;gEACgE;AAChE,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"worktree-sync.d.ts","sourceRoot":"","sources":["../../src/lib/worktree-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;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;IACjC,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CA8b1E"}
|
|
@@ -63,7 +63,8 @@ export const CHECKPOINT_RETENTION_DAYS = 14;
|
|
|
63
63
|
/** Audit log path component. One line per run, every path including refusals. */
|
|
64
64
|
export const AUDIT_LOG_FILENAME = 'worktree-sync.jsonl';
|
|
65
65
|
/**
|
|
66
|
-
* The eleven fields the plan's Audit section names, plus `runId`,
|
|
66
|
+
* The eleven fields the plan's Audit section names, plus `runId`, plus the
|
|
67
|
+
* four #1159 added (`squashPr`, `via`, `backupRef`, `dropped`), in written
|
|
67
68
|
* order.
|
|
68
69
|
*
|
|
69
70
|
* `runId` is the twelfth and it is required by the crash-durability fix (red
|
|
@@ -89,6 +90,10 @@ export const AUDIT_FIELDS = [
|
|
|
89
90
|
'headAfter',
|
|
90
91
|
'checkpointRef',
|
|
91
92
|
'syncBranch',
|
|
93
|
+
'squashPr',
|
|
94
|
+
'via',
|
|
95
|
+
'backupRef',
|
|
96
|
+
'dropped',
|
|
92
97
|
'refsPruned',
|
|
93
98
|
'outcome',
|
|
94
99
|
];
|
|
@@ -524,6 +529,9 @@ export function restoreCheckpoint(cwd, restoreCommit, deps = {}, indexCommit = n
|
|
|
524
529
|
}
|
|
525
530
|
return { outcome: conflicted ? 'conflict' : 'error', detail };
|
|
526
531
|
}
|
|
532
|
+
/** `<epoch-ms>-<rand6>` or `<epoch-ms>-<rand6>-head`, the last segment of a
|
|
533
|
+
* ref this module writes. */
|
|
534
|
+
const CHECKPOINT_NAME_RE = /^(\d{13})-[0-9a-f]{6}(?:-head)?$/;
|
|
527
535
|
export function listCheckpoints(cwd, worktreeName, deps = {}) {
|
|
528
536
|
const r = runGit(cwd, ['for-each-ref', '--format=%(refname) %(committerdate:unix)', checkpointRefPattern(worktreeName)], deps);
|
|
529
537
|
if (r.status !== 0)
|
|
@@ -537,7 +545,13 @@ export function listCheckpoints(cwd, worktreeName, deps = {}) {
|
|
|
537
545
|
if (sep === -1)
|
|
538
546
|
continue;
|
|
539
547
|
const ref = trimmed.slice(0, sep);
|
|
540
|
-
|
|
548
|
+
// #1159 security Should Fix: age by the time the ref was WRITTEN, from
|
|
549
|
+
// its name. A `-head` backup points at an existing HEAD commit, so its
|
|
550
|
+
// committer date can be weeks old, and dating by it pruned a backup at
|
|
551
|
+
// the next sync, seconds after it was written. The committer date is the
|
|
552
|
+
// fallback only for a name this module did not write.
|
|
553
|
+
const named = CHECKPOINT_NAME_RE.exec(ref.slice(ref.lastIndexOf('/') + 1));
|
|
554
|
+
const committedAt = named ? Math.floor(Number(named[1]) / 1000) : Number(trimmed.slice(sep + 1));
|
|
541
555
|
if (!ref || !Number.isFinite(committedAt))
|
|
542
556
|
continue;
|
|
543
557
|
out.push({ ref, committedAt });
|
|
@@ -1006,18 +1020,27 @@ function lookupByBranchName(cwd, repo, branch, baseBranch, deps) {
|
|
|
1006
1020
|
* that fails the re-check in `lastCommitOfPr`: `refused-pr-lookup-failed`.
|
|
1007
1021
|
* A 404 is never read as "no pull request".
|
|
1008
1022
|
* - No merged pull request within the cap, by commit or by branch name:
|
|
1009
|
-
* `
|
|
1023
|
+
* `no-pull-request`, naming the commits walked. The caller carries them
|
|
1024
|
+
* forward (#1159).
|
|
1025
|
+
* - A pull request found by branch name whose head commit is not an ancestor
|
|
1026
|
+
* of HEAD is no match (#1159). Branch names are reused, and a worktree
|
|
1027
|
+
* branch realigned to main since that pull request merged does not contain
|
|
1028
|
+
* its head, so it says nothing about the commits on HEAD now. It is
|
|
1029
|
+
* reported in `ignoredByName`. The same check on the by-commit path stays a
|
|
1030
|
+
* refusal in the caller, because there a commit on HEAD named the pull
|
|
1031
|
+
* request.
|
|
1010
1032
|
*
|
|
1011
1033
|
* A "rebase and merge" pull request lands on the base under NEW SHAs, so a
|
|
1012
|
-
* lookup that finds nothing for the local SHAs
|
|
1013
|
-
*
|
|
1034
|
+
* lookup that finds nothing for the local SHAs returns `no-pull-request`, and
|
|
1035
|
+
* the carry-forward drops those commits as already on the base.
|
|
1014
1036
|
*/
|
|
1015
1037
|
export function findSquashPoint(cwd, options, deps = {}) {
|
|
1016
|
-
const fail = (outcome, detail, unaccounted = []) => ({
|
|
1038
|
+
const fail = (outcome, detail, unaccounted = [], ignoredByName = null) => ({
|
|
1017
1039
|
ok: false,
|
|
1018
1040
|
outcome,
|
|
1019
1041
|
detail,
|
|
1020
1042
|
unaccounted,
|
|
1043
|
+
ignoredByName,
|
|
1021
1044
|
});
|
|
1022
1045
|
const remote = runGit(cwd, ['remote', 'get-url', 'origin'], deps);
|
|
1023
1046
|
const repo = remote.status === 0 ? parseGitHubRepo(remote.stdout) : null;
|
|
@@ -1040,16 +1063,26 @@ export function findSquashPoint(cwd, options, deps = {}) {
|
|
|
1040
1063
|
const byName = lookupByBranchName(cwd, repo, options.branch, options.baseBranch, deps);
|
|
1041
1064
|
if (byName.kind === 'fail')
|
|
1042
1065
|
return fail(byName.outcome, byName.detail);
|
|
1066
|
+
let ignoredByName = null;
|
|
1043
1067
|
if (byName.kind === 'found') {
|
|
1044
1068
|
const last = lastCommitOfPr(cwd, repo, byName.pr, options.baseBranch, deps);
|
|
1045
1069
|
if (!last.ok)
|
|
1046
1070
|
return fail(last.outcome, last.detail);
|
|
1047
|
-
|
|
1071
|
+
// #1159. A pull request found only by branch NAME whose head is not on
|
|
1072
|
+
// HEAD's history is a stranger: an older use of a reused name. Any
|
|
1073
|
+
// non-zero exit is "not an ancestor", including 128 for an object this
|
|
1074
|
+
// clone never fetched. That is the safe reading: the caller then carries
|
|
1075
|
+
// the commits forward, which discards nothing, rather than replaying a
|
|
1076
|
+
// range this branch does not contain.
|
|
1077
|
+
const anc = runGit(cwd, ['merge-base', '--is-ancestor', last.oid, 'HEAD'], deps);
|
|
1078
|
+
if (anc.status === 0)
|
|
1079
|
+
return { ok: true, oid: last.oid, pr: byName.pr, via: 'branch-name' };
|
|
1080
|
+
ignoredByName = { pr: byName.pr, oid: last.oid };
|
|
1048
1081
|
}
|
|
1049
1082
|
const capped = options.commits.length > SQUASH_WALK_CAP;
|
|
1050
|
-
return fail('
|
|
1083
|
+
return fail('no-pull-request', capped
|
|
1051
1084
|
? `no pull request merged into ${options.baseBranch} contains any of the newest ${SQUASH_WALK_CAP} commits, and more lie beyond the walk cap`
|
|
1052
|
-
: `no pull request merged into ${options.baseBranch} contains any of these ${walked.length} commit(s)`, walked);
|
|
1085
|
+
: `no pull request merged into ${options.baseBranch} contains any of these ${walked.length} commit(s)`, walked, ignoredByName);
|
|
1053
1086
|
}
|
|
1054
1087
|
/**
|
|
1055
1088
|
* True when some multi-step git operation is half-finished in this worktree.
|
|
@@ -1090,6 +1123,127 @@ export function rebaseInProgress(cwd, deps = {}) {
|
|
|
1090
1123
|
}
|
|
1091
1124
|
return false;
|
|
1092
1125
|
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Everything the carry-forward needs before the in-progress record: the merge
|
|
1128
|
+
* base, the full list of pre-sync local commits, and a ref holding HEAD.
|
|
1129
|
+
*
|
|
1130
|
+
* The backup ref is a SEPARATE ref, not the step-5 checkpoint. The checkpoint
|
|
1131
|
+
* exists only on a dirty tree, and it points at a working-tree commit whose
|
|
1132
|
+
* first parent is HEAD, not at HEAD itself. The backup is
|
|
1133
|
+
* `refs/mx/checkpoint/<worktree>/<epoch-ms>-<rand6>-head`, in the same
|
|
1134
|
+
* namespace so the same retention applies (step 3 reserves a slot for it).
|
|
1135
|
+
* It is created with an empty old value, so `update-ref` refuses rather than
|
|
1136
|
+
* overwrite an existing ref, and it is read back before anything mutates.
|
|
1137
|
+
*/
|
|
1138
|
+
export function prepareCarryForward(cwd, options, deps = {}) {
|
|
1139
|
+
const { baseRef, worktreeName, headBefore } = options;
|
|
1140
|
+
const fail = (outcome, detail, unverified = []) => ({ ok: false, outcome, detail, unverified });
|
|
1141
|
+
if (!headBefore || !OID_RE.test(headBefore)) {
|
|
1142
|
+
return fail('error', 'HEAD did not resolve to a commit, so it cannot be backed up');
|
|
1143
|
+
}
|
|
1144
|
+
const mb = runGit(cwd, ['merge-base', '--end-of-options', baseRef, 'HEAD'], deps);
|
|
1145
|
+
const mergeBase = mb.stdout.trim();
|
|
1146
|
+
if (mb.status !== 0 || !OID_RE.test(mergeBase)) {
|
|
1147
|
+
return fail('error', `HEAD and ${baseRef} have no merge base that git could report`);
|
|
1148
|
+
}
|
|
1149
|
+
const list = runGit(cwd, ['rev-list', '--end-of-options', `${baseRef}..HEAD`], deps);
|
|
1150
|
+
const preCommits = list.stdout.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
1151
|
+
if (list.status !== 0 || preCommits.length === 0 || !preCommits.every((c) => OID_RE.test(c))) {
|
|
1152
|
+
return fail('error', `could not list the commits in ${baseRef}..HEAD`);
|
|
1153
|
+
}
|
|
1154
|
+
// #1159 lead decision (red-team finding 3). The carry-forward replays only
|
|
1155
|
+
// commits the lookup could vouch for: none in a merged pull request. Two
|
|
1156
|
+
// conditions break that, and each refuses before anything is written.
|
|
1157
|
+
// (a) The walk stopped at the cap, so older commits were never asked about.
|
|
1158
|
+
if (options.capped) {
|
|
1159
|
+
return fail('refused-unverified-commits', `more than ${SQUASH_WALK_CAP} commits are on HEAD and not on ${baseRef}, so the pull-request lookup did not check them all`);
|
|
1160
|
+
}
|
|
1161
|
+
// (b) A commit is on another remote-tracking branch, so it was pushed for a
|
|
1162
|
+
// pull request the lookup may have missed. The worktree branch's own remote
|
|
1163
|
+
// ref is excluded: a drafts commit pushed there alone still carries forward.
|
|
1164
|
+
const ownRemote = `refs/remotes/origin/${options.branch}`;
|
|
1165
|
+
const unverified = [];
|
|
1166
|
+
for (const sha of preCommits) {
|
|
1167
|
+
const r = runGit(cwd, ['for-each-ref', '--format=%(refname)', '--contains', sha, 'refs/remotes/'], deps);
|
|
1168
|
+
if (r.status !== 0) {
|
|
1169
|
+
return fail('refused-unverified-commits', `could not check which remote branches hold ${sha}`);
|
|
1170
|
+
}
|
|
1171
|
+
const refs = r.stdout.split('\n').map((l) => l.trim()).filter((l) => l && l !== ownRemote);
|
|
1172
|
+
if (refs.length > 0)
|
|
1173
|
+
unverified.push({ sha, refs });
|
|
1174
|
+
}
|
|
1175
|
+
if (unverified.length > 0) {
|
|
1176
|
+
return fail('refused-unverified-commits', `${unverified.length} commit(s) to carry forward are also on another remote branch, so they may belong to a merged pull request the lookup did not find`, unverified);
|
|
1177
|
+
}
|
|
1178
|
+
const backupRef = `${buildCheckpointRef(worktreeName, dep(deps.now, Date.now)(), dep(deps.rand6, defaultRand6)())}-head`;
|
|
1179
|
+
if (!isValidRefName(backupRef, cwd, deps)) {
|
|
1180
|
+
return fail('refused-invalid-checkpoint-ref', `git check-ref-format rejects "${backupRef}"`);
|
|
1181
|
+
}
|
|
1182
|
+
const ur = runGit(cwd, ['update-ref', '-m', 'mx-agent worktree sync: HEAD before carry-forward', backupRef, headBefore, ''], deps);
|
|
1183
|
+
const back = runGit(cwd, ['rev-parse', '--verify', '--quiet', '--end-of-options', backupRef], deps);
|
|
1184
|
+
if (ur.status !== 0 || back.status !== 0 || back.stdout.trim() !== headBefore) {
|
|
1185
|
+
return fail('error', `the HEAD backup ref ${backupRef} could not be written`);
|
|
1186
|
+
}
|
|
1187
|
+
return { ok: true, mergeBase, backupRef, preCommits };
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Pre-sync local commits with no patch-id equivalent on the post-sync side,
|
|
1191
|
+
* from `git cherry HEAD <backup> <merge-base>`. That command lists every commit
|
|
1192
|
+
* in merge-base..backup, marking `-` when a commit with the same patch-id is in
|
|
1193
|
+
* backup..HEAD: either on the base already, or replayed by the carry-forward.
|
|
1194
|
+
* Everything not marked `-` is reported: a commit dropped as empty, a merge
|
|
1195
|
+
* commit the replay linearised, or a commit whose replay changed its patch.
|
|
1196
|
+
* The last is over-reporting, and it is the safe direction, because every
|
|
1197
|
+
* listed commit stays reachable from the backup ref.
|
|
1198
|
+
*
|
|
1199
|
+
* If `git cherry` fails, every pre-sync commit is listed. Unknown is never
|
|
1200
|
+
* reported as "nothing dropped".
|
|
1201
|
+
*/
|
|
1202
|
+
export function droppedByCarryForward(cwd, carry, deps = {}) {
|
|
1203
|
+
const r = runGit(cwd, ['cherry', 'HEAD', carry.backupRef, carry.mergeBase], deps);
|
|
1204
|
+
if (r.status !== 0)
|
|
1205
|
+
return [...carry.preCommits];
|
|
1206
|
+
const equivalent = new Set();
|
|
1207
|
+
for (const line of r.stdout.split('\n')) {
|
|
1208
|
+
const m = /^- ([0-9a-f]{40})$/.exec(line.trim());
|
|
1209
|
+
if (m)
|
|
1210
|
+
equivalent.add(m[1]);
|
|
1211
|
+
}
|
|
1212
|
+
return carry.preCommits.filter((c) => !equivalent.has(c));
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* After a refused carry-forward replay, put the working tree back. The abort
|
|
1216
|
+
* returned HEAD to `headBefore`; the step-5 checkpoint is parented on that same
|
|
1217
|
+
* commit, so the restore applies cleanly. Refuses to restore onto any other
|
|
1218
|
+
* HEAD, or while a rebase is still in progress, and says so.
|
|
1219
|
+
*/
|
|
1220
|
+
function restoreAfterRefusedReplay(cwd, audit, restoreCommit, indexCommit, doRestore, deps) {
|
|
1221
|
+
if (!audit.checkpointRef)
|
|
1222
|
+
return { ok: true, lines: [] };
|
|
1223
|
+
if (audit.headAfter !== audit.headBefore || rebaseInProgress(cwd, deps)) {
|
|
1224
|
+
return {
|
|
1225
|
+
ok: false,
|
|
1226
|
+
lines: [
|
|
1227
|
+
`HEAD is ${audit.headAfter ?? 'unknown'}, not the pre-sync ${audit.headBefore ?? 'unknown'}, so the working tree was not put back.`,
|
|
1228
|
+
`Recover it from ${audit.checkpointRef}: git checkout ${audit.checkpointRef} -- <path>`,
|
|
1229
|
+
],
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
if (!doRestore) {
|
|
1233
|
+
return { ok: true, lines: [`--no-restore: the working tree is left at the committed state. Recover from ${audit.checkpointRef}.`] };
|
|
1234
|
+
}
|
|
1235
|
+
const restored = restoreCheckpoint(cwd, restoreCommit, deps, indexCommit, audit.headBefore);
|
|
1236
|
+
if (restored.outcome === 'restored' || restored.outcome === 'nothing-to-restore') {
|
|
1237
|
+
return { ok: true, lines: ['Put the working tree back as it was before the sync.'] };
|
|
1238
|
+
}
|
|
1239
|
+
return {
|
|
1240
|
+
ok: false,
|
|
1241
|
+
lines: [
|
|
1242
|
+
`The working tree could not be put back: ${restored.detail ?? 'unknown reason'}`,
|
|
1243
|
+
`Nothing is lost. Recover from ${audit.checkpointRef}: git checkout ${audit.checkpointRef} -- <path>`,
|
|
1244
|
+
],
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1093
1247
|
/**
|
|
1094
1248
|
* The nine-step algorithm from #172, in the plan's order.
|
|
1095
1249
|
*
|
|
@@ -1118,6 +1272,10 @@ export function runWorktreeSyncCore(options) {
|
|
|
1118
1272
|
headAfter: null,
|
|
1119
1273
|
checkpointRef: null,
|
|
1120
1274
|
syncBranch: null,
|
|
1275
|
+
squashPr: null,
|
|
1276
|
+
via: null,
|
|
1277
|
+
backupRef: null,
|
|
1278
|
+
dropped: [],
|
|
1121
1279
|
refsPruned: [],
|
|
1122
1280
|
outcome: 'error',
|
|
1123
1281
|
};
|
|
@@ -1197,15 +1355,16 @@ export function runWorktreeSyncCore(options) {
|
|
|
1197
1355
|
return finish('refused-base-ref-missing', 1);
|
|
1198
1356
|
}
|
|
1199
1357
|
// ── step 3 ────────────────────────────────────────────────────────────
|
|
1200
|
-
//
|
|
1201
|
-
//
|
|
1202
|
-
//
|
|
1203
|
-
//
|
|
1204
|
-
//
|
|
1358
|
+
// Two slots are RESERVED: one for the checkpoint this run may write at
|
|
1359
|
+
// step 5, and one for the HEAD backup a carry-forward writes at step 7
|
|
1360
|
+
// (#1159). The plan prunes at step 3 only and caps the namespace at 20;
|
|
1361
|
+
// pruning TO 20 here and then writing refs leaves more than 20, which fails
|
|
1362
|
+
// the cap the plan states. Reserving the slots keeps "at most 20 refs per
|
|
1363
|
+
// worktree" true after every run, at the cost of two slots on a clean sync.
|
|
1205
1364
|
audit.refsPruned = pruneCheckpoints({
|
|
1206
1365
|
cwd,
|
|
1207
1366
|
worktreeName,
|
|
1208
|
-
maxKeep: MAX_CHECKPOINTS_PER_WORKTREE -
|
|
1367
|
+
maxKeep: MAX_CHECKPOINTS_PER_WORKTREE - 2,
|
|
1209
1368
|
deps,
|
|
1210
1369
|
});
|
|
1211
1370
|
if (audit.refsPruned.length > 0) {
|
|
@@ -1284,11 +1443,14 @@ export function runWorktreeSyncCore(options) {
|
|
|
1284
1443
|
// a refusal here never leaves a dangling `in-progress` line.
|
|
1285
1444
|
const diff = runGit(cwd, ['diff', '--quiet', baseRef, 'HEAD'], deps);
|
|
1286
1445
|
let squashPoint = null;
|
|
1446
|
+
/** Set when no merged pull request accounts for the local commits (#1159). */
|
|
1447
|
+
let carry = null;
|
|
1287
1448
|
if (diff.status !== 0) {
|
|
1288
1449
|
// #1131. An EMPTY `origin/<base>..HEAD` means the branch is only behind,
|
|
1289
1450
|
// so the plain rebase is a fast-forward and needs no lookup. A NON-EMPTY
|
|
1290
|
-
// range is synced
|
|
1291
|
-
//
|
|
1451
|
+
// range is synced through a squash point, or, when no merged pull request
|
|
1452
|
+
// accounts for it, carried forward from the merge base (#1159). A failed
|
|
1453
|
+
// lookup refuses. The plain rebase is never the fallback for one.
|
|
1292
1454
|
const range = listFirstParentRange(cwd, baseRef, deps);
|
|
1293
1455
|
if (!range.ok) {
|
|
1294
1456
|
emit(`Refusing to sync: could not list the commits in ${baseRef}..HEAD (${range.detail}). Nothing was mutated.`);
|
|
@@ -1296,34 +1458,68 @@ export function runWorktreeSyncCore(options) {
|
|
|
1296
1458
|
}
|
|
1297
1459
|
if (range.commits.length > 0) {
|
|
1298
1460
|
const found = findSquashPoint(cwd, { baseBranch: options.baseBranch, branch, commits: range.commits }, deps);
|
|
1299
|
-
if (!found.ok) {
|
|
1461
|
+
if (!found.ok && found.outcome !== 'no-pull-request') {
|
|
1300
1462
|
emit(`Refusing to sync: ${found.detail}.`);
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
for (const sha of found.unaccounted)
|
|
1304
|
-
emit(` ${sha}`);
|
|
1305
|
-
emit('Push them and merge a pull request, or move them off this branch, then re-run.');
|
|
1306
|
-
}
|
|
1307
|
-
else {
|
|
1308
|
-
emit('No merged pull request could be looked up, so no squash point is known.');
|
|
1309
|
-
emit('A plain rebase is not the fallback: after a squash merge it replays merged commits and conflicts.');
|
|
1310
|
-
}
|
|
1463
|
+
emit('No merged pull request could be looked up, so no squash point is known.');
|
|
1464
|
+
emit('A plain rebase is not the fallback: after a squash merge it replays merged commits and conflicts.');
|
|
1311
1465
|
emit('Nothing was mutated.');
|
|
1312
1466
|
return finish(found.outcome, 1);
|
|
1313
1467
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1468
|
+
if (!found.ok) {
|
|
1469
|
+
// #1159, PO decision 2026-11-19 (memory 055d30e1): commits in no
|
|
1470
|
+
// merged pull request are carried forward, not refused. Reversed from
|
|
1471
|
+
// #1131, which refused them as `refused-unaccounted-commits`.
|
|
1472
|
+
if (found.ignoredByName) {
|
|
1473
|
+
emit(`Pull request #${found.ignoredByName.pr}, found by branch name, was ignored: its head ${found.ignoredByName.oid} is not an ancestor of HEAD.`);
|
|
1474
|
+
}
|
|
1475
|
+
const prepared = prepareCarryForward(cwd, {
|
|
1476
|
+
baseRef,
|
|
1477
|
+
worktreeName,
|
|
1478
|
+
headBefore: audit.headBefore,
|
|
1479
|
+
branch,
|
|
1480
|
+
capped: range.commits.length > SQUASH_WALK_CAP,
|
|
1481
|
+
}, deps);
|
|
1482
|
+
if (!prepared.ok) {
|
|
1483
|
+
emit(`Refusing to sync: ${prepared.detail}.`);
|
|
1484
|
+
for (const u of prepared.unverified)
|
|
1485
|
+
emit(` ${u.sha} is on ${u.refs.join(', ')}`);
|
|
1486
|
+
if (prepared.outcome === 'refused-unverified-commits') {
|
|
1487
|
+
emit('Replaying them could re-apply work that main has since changed or reverted.');
|
|
1488
|
+
}
|
|
1489
|
+
emit('Nothing was mutated.');
|
|
1490
|
+
return finish(prepared.outcome, 1);
|
|
1491
|
+
}
|
|
1492
|
+
carry = prepared;
|
|
1493
|
+
audit.backupRef = prepared.backupRef;
|
|
1494
|
+
emit(`${found.detail}.`);
|
|
1495
|
+
emit(`Carrying ${prepared.preCommits.length} local commit(s) forward onto ${baseRef}:`);
|
|
1496
|
+
for (const sha of prepared.preCommits)
|
|
1497
|
+
emit(` ${sha}`);
|
|
1498
|
+
emit('HEAD is backed up first:');
|
|
1499
|
+
emit(` backup: ${prepared.backupRef}`);
|
|
1500
|
+
emit(` recover: git log ${prepared.backupRef}`);
|
|
1501
|
+
}
|
|
1502
|
+
else {
|
|
1503
|
+
squashPoint = { oid: found.oid, pr: found.pr };
|
|
1504
|
+
audit.squashPr = found.pr;
|
|
1505
|
+
audit.via = found.via;
|
|
1324
1506
|
}
|
|
1325
1507
|
}
|
|
1326
1508
|
}
|
|
1509
|
+
if (squashPoint) {
|
|
1510
|
+
// `rebase --onto <base> <oid>` replays the range <oid>..HEAD, so an oid
|
|
1511
|
+
// that is NOT an ancestor of HEAD silently replays a stale or foreign
|
|
1512
|
+
// range. Refuse instead (#172 red team Finding 3). Since #1159 this is
|
|
1513
|
+
// reached by the by-commit path only: the branch-name lookup already
|
|
1514
|
+
// treats a non-ancestor head as no match.
|
|
1515
|
+
const anc = runGit(cwd, ['merge-base', '--is-ancestor', squashPoint.oid, 'HEAD'], deps);
|
|
1516
|
+
if (anc.status !== 0) {
|
|
1517
|
+
emit(`Refusing to sync: the squash point from pull request #${squashPoint.pr} is not an ancestor of HEAD.`);
|
|
1518
|
+
emit(` oid: ${squashPoint.oid}`);
|
|
1519
|
+
emit(' `rebase --onto` would replay a range this branch does not contain. Resolve by hand.');
|
|
1520
|
+
return finish('refused-squash-point-not-ancestor', 1);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1327
1523
|
// ── F1: crash durability ──────────────────────────────────────────────
|
|
1328
1524
|
// Everything below this line mutates the repository. Output is buffered in
|
|
1329
1525
|
// memory and the terminal record is written at a return point, so a process
|
|
@@ -1372,13 +1568,25 @@ export function runWorktreeSyncCore(options) {
|
|
|
1372
1568
|
// `--end-of-options` so an oid can never be read as an option. It is
|
|
1373
1569
|
// already constrained to 40 hex characters by OID_RE; this is the
|
|
1374
1570
|
// second of the two independent checks.
|
|
1571
|
+
//
|
|
1572
|
+
// The carry-forward arm (#1159) replays merge-base..HEAD. `--empty=drop`
|
|
1573
|
+
// drops a commit that becomes empty because its content is already on
|
|
1574
|
+
// the base, which is how the commits of a pull request squash-merged
|
|
1575
|
+
// under an unfound number are dropped rather than duplicated. Named
|
|
1576
|
+
// explicitly rather than left to the default, which has changed across
|
|
1577
|
+
// git releases.
|
|
1375
1578
|
const rebaseArgs = squashPoint
|
|
1376
1579
|
? ['rebase', '--onto', baseRef, '--end-of-options', squashPoint.oid]
|
|
1377
|
-
:
|
|
1378
|
-
|
|
1580
|
+
: carry
|
|
1581
|
+
? ['rebase', '--empty=drop', '--onto', baseRef, '--end-of-options', carry.mergeBase]
|
|
1582
|
+
: ['rebase', baseRef];
|
|
1583
|
+
audit.syncBranch = squashPoint ? 'rebase-onto' : carry ? 'carry-forward' : 'rebase';
|
|
1379
1584
|
if (squashPoint) {
|
|
1380
1585
|
emit(`Pull request #${squashPoint.pr} was squash-merged. Replaying commits after ${squashPoint.oid} onto ${baseRef}.`);
|
|
1381
1586
|
}
|
|
1587
|
+
else if (carry) {
|
|
1588
|
+
emit(`Replaying the commits after the merge base ${carry.mergeBase} onto ${baseRef}.`);
|
|
1589
|
+
}
|
|
1382
1590
|
else {
|
|
1383
1591
|
emit(`Rebasing onto ${baseRef}.`);
|
|
1384
1592
|
}
|
|
@@ -1408,10 +1616,32 @@ export function runWorktreeSyncCore(options) {
|
|
|
1408
1616
|
if (audit.checkpointRef)
|
|
1409
1617
|
emit(`Checkpoint: ${audit.checkpointRef}`);
|
|
1410
1618
|
audit.headAfter = readHead(cwd, deps);
|
|
1619
|
+
if (carry) {
|
|
1620
|
+
// #1159: a refused carry-forward leaves HEAD and the working tree
|
|
1621
|
+
// as they were. The abort put HEAD back; the checkpoint, parented
|
|
1622
|
+
// on that same HEAD, puts the working tree back.
|
|
1623
|
+
emit(`HEAD backup: ${carry.backupRef}`);
|
|
1624
|
+
const putBack = restoreAfterRefusedReplay(cwd, audit, restoreCommit, indexCommit, options.restore !== false, deps);
|
|
1625
|
+
for (const l of putBack.lines)
|
|
1626
|
+
emit(l);
|
|
1627
|
+
if (!putBack.ok)
|
|
1628
|
+
return finish('restore-failed', 1);
|
|
1629
|
+
return finish(wasConflict ? 'refused-replay-conflict' : 'rebase-failed', 1);
|
|
1630
|
+
}
|
|
1411
1631
|
return finish(wasConflict ? 'conflict' : 'rebase-failed', 1);
|
|
1412
1632
|
}
|
|
1413
1633
|
}
|
|
1414
1634
|
audit.headAfter = readHead(cwd, deps);
|
|
1635
|
+
if (carry) {
|
|
1636
|
+
audit.dropped = droppedByCarryForward(cwd, carry, deps);
|
|
1637
|
+
const replayed = runGit(cwd, ['rev-list', '--count', `${baseRef}..HEAD`], deps).stdout.trim();
|
|
1638
|
+
emit(`Carried forward: ${replayed || 'an unknown number of'} commit(s) now on top of ${baseRef}.`);
|
|
1639
|
+
if (audit.dropped.length > 0) {
|
|
1640
|
+
emit(`Not replayed: ${audit.dropped.length} commit(s), already on ${baseRef} or merge commits. Each is reachable from ${carry.backupRef}:`);
|
|
1641
|
+
for (const sha of audit.dropped)
|
|
1642
|
+
emit(` ${sha}`);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1415
1645
|
// ── F2: restore ───────────────────────────────────────────────────────
|
|
1416
1646
|
// Saving without applying loses the working state of any teammate who did
|
|
1417
1647
|
// not read this session's console, and no cross-session channel relays it.
|