@narumitw/pi-worktree 0.51.7 → 0.51.8
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 +19 -57
- package/dist/index.ts +52 -226
- package/dist/index.ts.map +2 -2
- package/package.json +49 -50
- package/src/command.ts +605 -693
- package/src/git.ts +635 -731
- package/src/session.ts +76 -84
- package/src/settings.ts +211 -223
- package/src/status.ts +287 -309
- package/src/worktree.ts +26 -33
package/dist/index.ts
CHANGED
|
@@ -43,9 +43,7 @@ function parseWorktreePorcelain(output) {
|
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
if (!current) {
|
|
46
|
-
throw new GitWorktreeError(
|
|
47
|
-
`Worktree porcelain field ${JSON.stringify(key)} appears before worktree.`
|
|
48
|
-
);
|
|
46
|
+
throw new GitWorktreeError(`Worktree porcelain field ${JSON.stringify(key)} appears before worktree.`);
|
|
49
47
|
}
|
|
50
48
|
switch (key) {
|
|
51
49
|
case "HEAD":
|
|
@@ -113,16 +111,12 @@ function unresolvableSymlinkAncestor(path) {
|
|
|
113
111
|
if (isNodeError(error) && (error.code === "ENOENT" || error.code === "ELOOP")) {
|
|
114
112
|
return current;
|
|
115
113
|
}
|
|
116
|
-
throw new GitWorktreeError(
|
|
117
|
-
`Cannot resolve filesystem ancestor ${current}: ${formatError(error)}`
|
|
118
|
-
);
|
|
114
|
+
throw new GitWorktreeError(`Cannot resolve filesystem ancestor ${current}: ${formatError(error)}`);
|
|
119
115
|
}
|
|
120
116
|
} catch (error) {
|
|
121
117
|
if (!isNodeError(error) || error.code !== "ENOENT") {
|
|
122
118
|
if (error instanceof GitWorktreeError) throw error;
|
|
123
|
-
throw new GitWorktreeError(
|
|
124
|
-
`Cannot inspect filesystem ancestor ${current}: ${formatError(error)}`
|
|
125
|
-
);
|
|
119
|
+
throw new GitWorktreeError(`Cannot inspect filesystem ancestor ${current}: ${formatError(error)}`);
|
|
126
120
|
}
|
|
127
121
|
const parent = dirname(current);
|
|
128
122
|
if (parent === current) return void 0;
|
|
@@ -147,12 +141,7 @@ async function currentWorktreePath(pi, cwd, signal) {
|
|
|
147
141
|
return pathIdentity(path);
|
|
148
142
|
}
|
|
149
143
|
async function symbolicBranch(pi, cwd, signal) {
|
|
150
|
-
const result = await runGitAllowFailure(
|
|
151
|
-
pi,
|
|
152
|
-
["symbolic-ref", "--quiet", "--short", "HEAD"],
|
|
153
|
-
cwd,
|
|
154
|
-
signal
|
|
155
|
-
);
|
|
144
|
+
const result = await runGitAllowFailure(pi, ["symbolic-ref", "--quiet", "--short", "HEAD"], cwd, signal);
|
|
156
145
|
if (result.killed) throw killedError(["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
157
146
|
if (result.code !== 0) return void 0;
|
|
158
147
|
return result.stdout.trim() || void 0;
|
|
@@ -176,12 +165,7 @@ async function localBranchExists(pi, cwd, branch, signal) {
|
|
|
176
165
|
throw gitFailure(["show-ref", "--verify", "--quiet"], result);
|
|
177
166
|
}
|
|
178
167
|
async function resolveCommit(pi, cwd, startPoint, signal) {
|
|
179
|
-
const result = await runGit(
|
|
180
|
-
pi,
|
|
181
|
-
["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`],
|
|
182
|
-
cwd,
|
|
183
|
-
signal
|
|
184
|
-
);
|
|
168
|
+
const result = await runGit(pi, ["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`], cwd, signal);
|
|
185
169
|
const oid = result.stdout.trim();
|
|
186
170
|
if (!/^[0-9a-fA-F]{40,64}$/u.test(oid)) {
|
|
187
171
|
throw new GitWorktreeError(`Git returned an invalid commit object for ${startPoint}.`);
|
|
@@ -227,12 +211,7 @@ async function worktreeInventory(pi, path, signal) {
|
|
|
227
211
|
];
|
|
228
212
|
}
|
|
229
213
|
async function worktreeAdministrativeDirectory(pi, cwd, signal) {
|
|
230
|
-
const result = await runGit(
|
|
231
|
-
pi,
|
|
232
|
-
["rev-parse", "--path-format=absolute", "--git-dir"],
|
|
233
|
-
cwd,
|
|
234
|
-
signal
|
|
235
|
-
);
|
|
214
|
+
const result = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-dir"], cwd, signal);
|
|
236
215
|
const value = removeLineEnding(result.stdout);
|
|
237
216
|
if (!value) throw new GitWorktreeError("Git did not return its worktree administrative path.");
|
|
238
217
|
return resolve(cwd, value);
|
|
@@ -247,14 +226,7 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
|
|
|
247
226
|
signal
|
|
248
227
|
);
|
|
249
228
|
values.push(...splitAdministrativeOids(refs.stdout, "per-worktree refs"));
|
|
250
|
-
for (const name of [
|
|
251
|
-
"ORIG_HEAD",
|
|
252
|
-
"MERGE_HEAD",
|
|
253
|
-
"REBASE_HEAD",
|
|
254
|
-
"CHERRY_PICK_HEAD",
|
|
255
|
-
"REVERT_HEAD",
|
|
256
|
-
"BISECT_HEAD"
|
|
257
|
-
]) {
|
|
229
|
+
for (const name of ["ORIG_HEAD", "MERGE_HEAD", "REBASE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "BISECT_HEAD"]) {
|
|
258
230
|
const contents = readAdministrativeFile(administrativePath, name);
|
|
259
231
|
if (contents === void 0) continue;
|
|
260
232
|
values.push(...splitAdministrativeOids(contents, name));
|
|
@@ -266,12 +238,7 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
|
|
|
266
238
|
return [...new Set(values)];
|
|
267
239
|
}
|
|
268
240
|
async function administrativePruneCandidates(pi, cwd, signal) {
|
|
269
|
-
const commonResult = await runGit(
|
|
270
|
-
pi,
|
|
271
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
272
|
-
cwd,
|
|
273
|
-
signal
|
|
274
|
-
);
|
|
241
|
+
const commonResult = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd, signal);
|
|
275
242
|
const commonValue = removeLineEnding(commonResult.stdout);
|
|
276
243
|
if (!commonValue) throw new GitWorktreeError("Git did not return its common directory.");
|
|
277
244
|
const commonDirectory = resolve(cwd, commonValue);
|
|
@@ -281,9 +248,7 @@ async function administrativePruneCandidates(pi, cwd, signal) {
|
|
|
281
248
|
for (const entry of readdirSync(administrativeRoot, { withFileTypes: true })) {
|
|
282
249
|
const administrativePath = resolve(administrativeRoot, entry.name);
|
|
283
250
|
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
284
|
-
throw new GitWorktreeError(
|
|
285
|
-
`Unexpected Git worktree administrative entry: ${administrativePath}.`
|
|
286
|
-
);
|
|
251
|
+
throw new GitWorktreeError(`Unexpected Git worktree administrative entry: ${administrativePath}.`);
|
|
287
252
|
}
|
|
288
253
|
if (existsSync(resolve(administrativePath, "locked"))) continue;
|
|
289
254
|
const gitdirPath = resolve(administrativePath, "gitdir");
|
|
@@ -306,17 +271,13 @@ async function administrativePruneCandidates(pi, cwd, signal) {
|
|
|
306
271
|
headValue = removeLineEnding(readFileSync(headPath, "utf8"));
|
|
307
272
|
} catch (error) {
|
|
308
273
|
if (error instanceof GitWorktreeError) throw error;
|
|
309
|
-
throw new GitWorktreeError(
|
|
310
|
-
`Cannot inspect Git worktree administrative HEAD ${headPath}: ${formatError(error)}`
|
|
311
|
-
);
|
|
274
|
+
throw new GitWorktreeError(`Cannot inspect Git worktree administrative HEAD ${headPath}: ${formatError(error)}`);
|
|
312
275
|
}
|
|
313
276
|
const indexDirty = await administrativeIndexIsDirty(pi, cwd, administrativePath, signal);
|
|
314
277
|
if (headValue.startsWith("ref: ")) {
|
|
315
278
|
const branchRef = headValue.slice("ref: ".length);
|
|
316
279
|
if (!branchRef) {
|
|
317
|
-
throw new GitWorktreeError(
|
|
318
|
-
`Git worktree administrative HEAD has an empty ref: ${headPath}.`
|
|
319
|
-
);
|
|
280
|
+
throw new GitWorktreeError(`Git worktree administrative HEAD has an empty ref: ${headPath}.`);
|
|
320
281
|
}
|
|
321
282
|
candidates.push({
|
|
322
283
|
id: entry.name,
|
|
@@ -359,12 +320,7 @@ async function durableRefExists(pi, cwd, ref, signal) {
|
|
|
359
320
|
if (!ref.startsWith("refs/") || ref.includes("\0")) {
|
|
360
321
|
throw new GitWorktreeError("Git worktree administrative HEAD contains an invalid ref.");
|
|
361
322
|
}
|
|
362
|
-
const result = await runGitAllowFailure(
|
|
363
|
-
pi,
|
|
364
|
-
["show-ref", "--verify", "--quiet", ref],
|
|
365
|
-
cwd,
|
|
366
|
-
signal
|
|
367
|
-
);
|
|
323
|
+
const result = await runGitAllowFailure(pi, ["show-ref", "--verify", "--quiet", ref], cwd, signal);
|
|
368
324
|
if (result.killed) throw killedError(["show-ref", "--verify", "--quiet"]);
|
|
369
325
|
if (result.code === 0) return true;
|
|
370
326
|
if (result.code === 1) return false;
|
|
@@ -376,14 +332,7 @@ async function durableRefsContaining(pi, cwd, head, signal) {
|
|
|
376
332
|
}
|
|
377
333
|
const result = await runGit(
|
|
378
334
|
pi,
|
|
379
|
-
[
|
|
380
|
-
"for-each-ref",
|
|
381
|
-
"--format=%(refname)",
|
|
382
|
-
`--contains=${head}`,
|
|
383
|
-
"refs/heads",
|
|
384
|
-
"refs/tags",
|
|
385
|
-
"refs/remotes"
|
|
386
|
-
],
|
|
335
|
+
["for-each-ref", "--format=%(refname)", `--contains=${head}`, "refs/heads", "refs/tags", "refs/remotes"],
|
|
387
336
|
cwd,
|
|
388
337
|
signal
|
|
389
338
|
);
|
|
@@ -394,13 +343,7 @@ async function prunePreview(pi, cwd, signal) {
|
|
|
394
343
|
return combineOutput(result);
|
|
395
344
|
}
|
|
396
345
|
async function pruneWorktrees(pi, cwd, signal) {
|
|
397
|
-
const result = await runGit(
|
|
398
|
-
pi,
|
|
399
|
-
["worktree", "prune", "--verbose"],
|
|
400
|
-
cwd,
|
|
401
|
-
signal,
|
|
402
|
-
GIT_MUTATION_TIMEOUT_MS
|
|
403
|
-
);
|
|
346
|
+
const result = await runGit(pi, ["worktree", "prune", "--verbose"], cwd, signal, GIT_MUTATION_TIMEOUT_MS);
|
|
404
347
|
return combineOutput(result);
|
|
405
348
|
}
|
|
406
349
|
function formatWorktree(record, currentPath) {
|
|
@@ -435,24 +378,16 @@ async function runGitAllowFailure(pi, args, cwd, signal, timeout = GIT_TIMEOUT_M
|
|
|
435
378
|
if (/\bENOENT\b|not found/i.test(message)) {
|
|
436
379
|
throw new GitWorktreeError("Git executable was not found. Install Git and retry.", args);
|
|
437
380
|
}
|
|
438
|
-
throw new GitWorktreeError(
|
|
439
|
-
`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`,
|
|
440
|
-
args
|
|
441
|
-
);
|
|
381
|
+
throw new GitWorktreeError(`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`, args);
|
|
442
382
|
}
|
|
443
383
|
}
|
|
444
384
|
function gitFailure(args, result) {
|
|
445
|
-
const detail = stripTerminalControls(
|
|
446
|
-
[result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n")
|
|
447
|
-
);
|
|
385
|
+
const detail = stripTerminalControls([result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n"));
|
|
448
386
|
const hint = /not a git repository/i.test(detail) ? "The current Pi workspace is not inside a Git repository." : detail || `Git exited with code ${result.code}.`;
|
|
449
387
|
return new GitWorktreeError(`git ${args.slice(0, 2).join(" ")} failed: ${hint}`, args);
|
|
450
388
|
}
|
|
451
389
|
function killedError(args) {
|
|
452
|
-
return new GitWorktreeError(
|
|
453
|
-
`git ${args.slice(0, 2).join(" ")} timed out or was cancelled.`,
|
|
454
|
-
args
|
|
455
|
-
);
|
|
390
|
+
return new GitWorktreeError(`git ${args.slice(0, 2).join(" ")} timed out or was cancelled.`, args);
|
|
456
391
|
}
|
|
457
392
|
function nonEmptyLines(value) {
|
|
458
393
|
return value.split(/\r?\n/u).filter((line) => line.length > 0);
|
|
@@ -499,12 +434,7 @@ async function sparseManagedSkipWorktreePaths(pi, cwd, paths, signal) {
|
|
|
499
434
|
if (config.code !== 0 || config.stdout.trim() !== "true") return /* @__PURE__ */ new Set();
|
|
500
435
|
const candidates = new Set(paths);
|
|
501
436
|
const checkArgs = ["sparse-checkout", "check-rules", "-z"];
|
|
502
|
-
const checked = await runGitWithInputAllowFailure(
|
|
503
|
-
checkArgs,
|
|
504
|
-
cwd,
|
|
505
|
-
`${[...candidates].join("\0")}\0`,
|
|
506
|
-
signal
|
|
507
|
-
);
|
|
437
|
+
const checked = await runGitWithInputAllowFailure(checkArgs, cwd, `${[...candidates].join("\0")}\0`, signal);
|
|
508
438
|
if (checked.killed) throw killedError(checkArgs);
|
|
509
439
|
if (checked.code !== 0) return /* @__PURE__ */ new Set();
|
|
510
440
|
const included = new Set(nulSeparatedPaths(checked.stdout, "sparse-checkout rules"));
|
|
@@ -538,10 +468,7 @@ function runGitWithInputAllowFailure(args, cwd, input, signal, timeout = GIT_TIM
|
|
|
538
468
|
child.kill();
|
|
539
469
|
const message = formatError(error);
|
|
540
470
|
reject(
|
|
541
|
-
/\bENOENT\b|not found/i.test(message) ? new GitWorktreeError("Git executable was not found. Install Git and retry.", args) : new GitWorktreeError(
|
|
542
|
-
`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`,
|
|
543
|
-
args
|
|
544
|
-
)
|
|
471
|
+
/\bENOENT\b|not found/i.test(message) ? new GitWorktreeError("Git executable was not found. Install Git and retry.", args) : new GitWorktreeError(`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`, args)
|
|
545
472
|
);
|
|
546
473
|
};
|
|
547
474
|
const stop = () => {
|
|
@@ -610,21 +537,15 @@ function readAdministrativeFile(administrativePath, name) {
|
|
|
610
537
|
stat = lstatSync(path);
|
|
611
538
|
} catch (error) {
|
|
612
539
|
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
613
|
-
throw new GitWorktreeError(
|
|
614
|
-
`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`
|
|
615
|
-
);
|
|
540
|
+
throw new GitWorktreeError(`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`);
|
|
616
541
|
}
|
|
617
542
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
618
|
-
throw new GitWorktreeError(
|
|
619
|
-
`Git worktree administrative ${name} must be a regular file: ${path}.`
|
|
620
|
-
);
|
|
543
|
+
throw new GitWorktreeError(`Git worktree administrative ${name} must be a regular file: ${path}.`);
|
|
621
544
|
}
|
|
622
545
|
try {
|
|
623
546
|
return readFileSync(path, "utf8");
|
|
624
547
|
} catch (error) {
|
|
625
|
-
throw new GitWorktreeError(
|
|
626
|
-
`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`
|
|
627
|
-
);
|
|
548
|
+
throw new GitWorktreeError(`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`);
|
|
628
549
|
}
|
|
629
550
|
}
|
|
630
551
|
function readAdministrativeReflogOids(logPath) {
|
|
@@ -685,10 +606,7 @@ async function switchToWorktree(ctx, targetPath) {
|
|
|
685
606
|
sessionPath = createTargetSession(ctx, targetPath);
|
|
686
607
|
const result = await ctx.switchSession(sessionPath, {
|
|
687
608
|
withSession: async (replacementCtx) => {
|
|
688
|
-
replacementCtx.ui.notify(
|
|
689
|
-
stripTerminalControls(`Switched Pi workspace to ${targetPath}.`),
|
|
690
|
-
"info"
|
|
691
|
-
);
|
|
609
|
+
replacementCtx.ui.notify(stripTerminalControls(`Switched Pi workspace to ${targetPath}.`), "info");
|
|
692
610
|
}
|
|
693
611
|
});
|
|
694
612
|
if (result.cancelled) {
|
|
@@ -733,12 +651,7 @@ function createTargetSession(ctx, targetPath) {
|
|
|
733
651
|
return writeTargetSession(targetPath, ctx.sessionManager.getBranch(), sourceFile, activeLeaf);
|
|
734
652
|
}
|
|
735
653
|
if (ctx.sessionManager.getEntries().length > 0) {
|
|
736
|
-
return writeTargetSession(
|
|
737
|
-
targetPath,
|
|
738
|
-
ctx.sessionManager.getBranch(),
|
|
739
|
-
void 0,
|
|
740
|
-
ctx.sessionManager.getLeafId()
|
|
741
|
-
);
|
|
654
|
+
return writeTargetSession(targetPath, ctx.sessionManager.getBranch(), void 0, ctx.sessionManager.getLeafId());
|
|
742
655
|
}
|
|
743
656
|
return writeTargetSession(targetPath, [], void 0, null);
|
|
744
657
|
}
|
|
@@ -852,11 +765,7 @@ function formatWorktreeStatusCard(record, currentPath, result) {
|
|
|
852
765
|
description: path,
|
|
853
766
|
statusText: `${statePrefix}unavailable`,
|
|
854
767
|
searchText: `${label} ${path} ${identity.join(" ")} unavailable ${reason}`,
|
|
855
|
-
details: [
|
|
856
|
-
...baseDetails,
|
|
857
|
-
`Status: ${reason}`,
|
|
858
|
-
"Snapshot: local Git state; no fetch performed."
|
|
859
|
-
]
|
|
768
|
+
details: [...baseDetails, `Status: ${reason}`, "Snapshot: local Git state; no fetch performed."]
|
|
860
769
|
};
|
|
861
770
|
}
|
|
862
771
|
const { snapshot, lastCommit } = result;
|
|
@@ -880,10 +789,7 @@ function formatWorktreeStatusCard(record, currentPath, result) {
|
|
|
880
789
|
};
|
|
881
790
|
}
|
|
882
791
|
async function loadWorktreeStatusCards(pi, records, currentPath, signal, options = {}) {
|
|
883
|
-
const concurrency = Math.max(
|
|
884
|
-
1,
|
|
885
|
-
Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1)
|
|
886
|
-
);
|
|
792
|
+
const concurrency = Math.max(1, Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1));
|
|
887
793
|
const cards = new Array(records.length);
|
|
888
794
|
let nextIndex = 0;
|
|
889
795
|
const worker = async () => {
|
|
@@ -905,14 +811,7 @@ async function loadWorktreeStatusCards(pi, records, currentPath, signal, options
|
|
|
905
811
|
try {
|
|
906
812
|
const status = await runGit2(
|
|
907
813
|
pi,
|
|
908
|
-
[
|
|
909
|
-
"status",
|
|
910
|
-
"--porcelain=v2",
|
|
911
|
-
"--branch",
|
|
912
|
-
"-z",
|
|
913
|
-
"--untracked-files=all",
|
|
914
|
-
"--ignore-submodules=none"
|
|
915
|
-
],
|
|
814
|
+
["status", "--porcelain=v2", "--branch", "-z", "--untracked-files=all", "--ignore-submodules=none"],
|
|
916
815
|
record.path,
|
|
917
816
|
signal
|
|
918
817
|
);
|
|
@@ -1070,11 +969,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
|
|
|
1070
969
|
description: "Interactively manage Git worktrees and their default root",
|
|
1071
970
|
handler: async (args, ctx) => {
|
|
1072
971
|
if (args.trim()) {
|
|
1073
|
-
safeNotify(
|
|
1074
|
-
ctx,
|
|
1075
|
-
"/worktree does not accept arguments; run it without arguments to open the menu.",
|
|
1076
|
-
"warning"
|
|
1077
|
-
);
|
|
972
|
+
safeNotify(ctx, "/worktree does not accept arguments; run it without arguments to open the menu.", "warning");
|
|
1078
973
|
return;
|
|
1079
974
|
}
|
|
1080
975
|
if (!ctx.hasUI) {
|
|
@@ -1131,12 +1026,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
|
|
|
1131
1026
|
status: async ({ signal }) => {
|
|
1132
1027
|
try {
|
|
1133
1028
|
const statusRecords = await listWorktrees(pi, ctx.cwd, signal);
|
|
1134
|
-
state.statusCards = await loadWorktreeStatusCards(
|
|
1135
|
-
pi,
|
|
1136
|
-
statusRecords,
|
|
1137
|
-
currentPath,
|
|
1138
|
-
signal
|
|
1139
|
-
);
|
|
1029
|
+
state.statusCards = await loadWorktreeStatusCards(pi, statusRecords, currentPath, signal);
|
|
1140
1030
|
if (signal.aborted || !owner.isCurrent()) return { kind: "close" };
|
|
1141
1031
|
return { kind: "to", screen: "status" };
|
|
1142
1032
|
} catch (error) {
|
|
@@ -1166,9 +1056,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
|
|
|
1166
1056
|
async function configureRootFlow(ctx, settings) {
|
|
1167
1057
|
const current = await settings.reload();
|
|
1168
1058
|
if (!current.canSave) {
|
|
1169
|
-
throw new Error(
|
|
1170
|
-
current.warning ?? `Fix ${settings.getPath()} before changing pi-worktree settings.`
|
|
1171
|
-
);
|
|
1059
|
+
throw new Error(current.warning ?? `Fix ${settings.getPath()} before changing pi-worktree settings.`);
|
|
1172
1060
|
}
|
|
1173
1061
|
const requested = await ctx.ui.input(
|
|
1174
1062
|
"Worktree root (blank restores ~/.worktrees)",
|
|
@@ -1190,9 +1078,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
|
|
|
1190
1078
|
throw new Error("The main worktree is bare; pi-worktree cannot derive a safe default path.");
|
|
1191
1079
|
}
|
|
1192
1080
|
if (!existsSync4(main.path)) {
|
|
1193
|
-
throw new Error(
|
|
1194
|
-
`The registered main worktree path is stale: ${main.path}. Repair it with Git first.`
|
|
1195
|
-
);
|
|
1081
|
+
throw new Error(`The registered main worktree path is stale: ${main.path}. Repair it with Git first.`);
|
|
1196
1082
|
}
|
|
1197
1083
|
const requestedBranch = await ctx.ui.input("Branch for the new worktree", "feat/my-change");
|
|
1198
1084
|
if (requestedBranch === void 0) return;
|
|
@@ -1237,9 +1123,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
|
|
|
1237
1123
|
stripTerminalControls(suggestedPath)
|
|
1238
1124
|
);
|
|
1239
1125
|
if (requestedPath === void 0) return;
|
|
1240
|
-
const targetPath = pathIdentity(
|
|
1241
|
-
requestedPath.trim() ? resolve2(ctx.cwd, requestedPath.trim()) : suggestedPath
|
|
1242
|
-
);
|
|
1126
|
+
const targetPath = pathIdentity(requestedPath.trim() ? resolve2(ctx.cwd, requestedPath.trim()) : suggestedPath);
|
|
1243
1127
|
assertTargetFilesystemAvailable(targetPath);
|
|
1244
1128
|
const pathCollision = records.find((record) => pathsEqual(record.path, targetPath));
|
|
1245
1129
|
if (pathCollision) {
|
|
@@ -1251,15 +1135,11 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
|
|
|
1251
1135
|
const latestRecords = await listWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1252
1136
|
const latestOccupied = worktreeForBranch(latestRecords, branch);
|
|
1253
1137
|
if (latestOccupied) {
|
|
1254
|
-
throw new Error(
|
|
1255
|
-
`Branch ${branch} is now checked out at ${latestOccupied.path}; select it again.`
|
|
1256
|
-
);
|
|
1138
|
+
throw new Error(`Branch ${branch} is now checked out at ${latestOccupied.path}; select it again.`);
|
|
1257
1139
|
}
|
|
1258
1140
|
const latestPathCollision = latestRecords.find((record) => pathsEqual(record.path, targetPath));
|
|
1259
1141
|
if (latestPathCollision) {
|
|
1260
|
-
throw new Error(
|
|
1261
|
-
`The target path is now registered as a worktree: ${latestPathCollision.path}. Select it again.`
|
|
1262
|
-
);
|
|
1142
|
+
throw new Error(`The target path is now registered as a worktree: ${latestPathCollision.path}. Select it again.`);
|
|
1263
1143
|
}
|
|
1264
1144
|
const branchStillExists = await localBranchExists(pi, ctx.cwd, branch, ctx.signal);
|
|
1265
1145
|
if (branchStillExists !== branchExists) {
|
|
@@ -1278,9 +1158,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
|
|
|
1278
1158
|
const updated = await listWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1279
1159
|
const verified = updated.find((record) => pathsEqual(record.path, targetPath));
|
|
1280
1160
|
if (!verified || verified.branch !== branch || verified.head !== provenance.oid) {
|
|
1281
|
-
throw new Error(
|
|
1282
|
-
"the expected path, branch, and approved HEAD were not present in Git porcelain output"
|
|
1283
|
-
);
|
|
1161
|
+
throw new Error("the expected path, branch, and approved HEAD were not present in Git porcelain output");
|
|
1284
1162
|
}
|
|
1285
1163
|
created = verified;
|
|
1286
1164
|
} catch (error) {
|
|
@@ -1289,10 +1167,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
|
|
|
1289
1167
|
);
|
|
1290
1168
|
}
|
|
1291
1169
|
safeNotify(ctx, `Created worktree ${targetPath} on branch ${branch}.`, "info");
|
|
1292
|
-
if (await ctx.ui.confirm(
|
|
1293
|
-
"Switch Pi workspace?",
|
|
1294
|
-
stripTerminalControls(`Continue this conversation in ${targetPath}?`)
|
|
1295
|
-
)) {
|
|
1170
|
+
if (await ctx.ui.confirm("Switch Pi workspace?", stripTerminalControls(`Continue this conversation in ${targetPath}?`))) {
|
|
1296
1171
|
const latest = await revalidateWorktreeIdentity(pi, ctx, created);
|
|
1297
1172
|
if (latest.prunableReason !== void 0 || !existsSync4(latest.path)) {
|
|
1298
1173
|
throw new Error("The newly created worktree became unavailable; select it again.");
|
|
@@ -1329,9 +1204,7 @@ function assertTargetFilesystemAvailable(targetPath) {
|
|
|
1329
1204
|
}
|
|
1330
1205
|
const unsafeAncestor = unresolvableSymlinkAncestor(targetPath);
|
|
1331
1206
|
if (unsafeAncestor) {
|
|
1332
|
-
throw new Error(
|
|
1333
|
-
`The target path has an unresolvable symbolic-link ancestor: ${unsafeAncestor}.`
|
|
1334
|
-
);
|
|
1207
|
+
throw new Error(`The target path has an unresolvable symbolic-link ancestor: ${unsafeAncestor}.`);
|
|
1335
1208
|
}
|
|
1336
1209
|
}
|
|
1337
1210
|
async function switchFlow(pi, ctx, records, currentPath, signal) {
|
|
@@ -1350,13 +1223,7 @@ async function removeFlow(pi, ctx, records, currentPath, signal) {
|
|
|
1350
1223
|
const candidates = records.filter(
|
|
1351
1224
|
(record) => !record.isMain && !record.bare && !pathsEqual(record.path, currentPath)
|
|
1352
1225
|
);
|
|
1353
|
-
const selected = await selectWorktree(
|
|
1354
|
-
ctx,
|
|
1355
|
-
"Remove linked worktree",
|
|
1356
|
-
candidates,
|
|
1357
|
-
currentPath,
|
|
1358
|
-
signal
|
|
1359
|
-
);
|
|
1226
|
+
const selected = await selectWorktree(ctx, "Remove linked worktree", candidates, currentPath, signal);
|
|
1360
1227
|
if (!selected) return;
|
|
1361
1228
|
if (selected.lockedReason !== void 0) {
|
|
1362
1229
|
throw new Error(
|
|
@@ -1366,9 +1233,7 @@ async function removeFlow(pi, ctx, records, currentPath, signal) {
|
|
|
1366
1233
|
if (selected.prunableReason !== void 0 || !existsSync4(selected.path)) {
|
|
1367
1234
|
throw new Error("The selected worktree path is stale. Use prune instead of remove.");
|
|
1368
1235
|
}
|
|
1369
|
-
const inventory = classifyRemovalInventory(
|
|
1370
|
-
await worktreeInventory(pi, selected.path, ctx.signal)
|
|
1371
|
-
);
|
|
1236
|
+
const inventory = classifyRemovalInventory(await worktreeInventory(pi, selected.path, ctx.signal));
|
|
1372
1237
|
if (inventory.protected.length > 0) {
|
|
1373
1238
|
throw new Error(
|
|
1374
1239
|
`Removal refused because ${selected.path} contains tracked, untracked, index-flagged, or submodule data:
|
|
@@ -1392,13 +1257,7 @@ ${recoveryWarning.trimStart()}` : `${ignoredWarning}${recoveryWarning}`;
|
|
|
1392
1257
|
)) {
|
|
1393
1258
|
return;
|
|
1394
1259
|
}
|
|
1395
|
-
await assertAdministrativeHistoryUnchanged(
|
|
1396
|
-
pi,
|
|
1397
|
-
ctx,
|
|
1398
|
-
selected.path,
|
|
1399
|
-
administrativePath,
|
|
1400
|
-
approvedHistoryRisks
|
|
1401
|
-
);
|
|
1260
|
+
await assertAdministrativeHistoryUnchanged(pi, ctx, selected.path, administrativePath, approvedHistoryRisks);
|
|
1402
1261
|
const beforeRemoval = await listWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1403
1262
|
const latest = beforeRemoval.find((record) => pathsEqual(record.path, selected.path));
|
|
1404
1263
|
if (!latest) throw new Error(`Worktree ${selected.path} is no longer registered.`);
|
|
@@ -1406,13 +1265,9 @@ ${recoveryWarning.trimStart()}` : `${ignoredWarning}${recoveryWarning}`;
|
|
|
1406
1265
|
throw new Error(`Worktree ${selected.path} changed identity; select it again.`);
|
|
1407
1266
|
}
|
|
1408
1267
|
if (latest.isMain || latest.lockedReason !== void 0 || latest.prunableReason !== void 0) {
|
|
1409
|
-
throw new Error(
|
|
1410
|
-
`Worktree ${selected.path} changed state after confirmation; removal was refused.`
|
|
1411
|
-
);
|
|
1268
|
+
throw new Error(`Worktree ${selected.path} changed state after confirmation; removal was refused.`);
|
|
1412
1269
|
}
|
|
1413
|
-
const latestInventory = classifyRemovalInventory(
|
|
1414
|
-
await worktreeInventory(pi, latest.path, ctx.signal)
|
|
1415
|
-
);
|
|
1270
|
+
const latestInventory = classifyRemovalInventory(await worktreeInventory(pi, latest.path, ctx.signal));
|
|
1416
1271
|
if (latestInventory.protected.length > 0) {
|
|
1417
1272
|
throw new Error(
|
|
1418
1273
|
`Removal refused because new protected local data appeared after confirmation:
|
|
@@ -1426,13 +1281,7 @@ ${latestInventory.ignored.join("\n") || "(none)"}`
|
|
|
1426
1281
|
);
|
|
1427
1282
|
}
|
|
1428
1283
|
await assertDetachedHeadIsDurable(pi, ctx, latest);
|
|
1429
|
-
await assertAdministrativeHistoryUnchanged(
|
|
1430
|
-
pi,
|
|
1431
|
-
ctx,
|
|
1432
|
-
latest.path,
|
|
1433
|
-
administrativePath,
|
|
1434
|
-
approvedHistoryRisks
|
|
1435
|
-
);
|
|
1284
|
+
await assertAdministrativeHistoryUnchanged(pi, ctx, latest.path, administrativePath, approvedHistoryRisks);
|
|
1436
1285
|
await removeWorktree(pi, ctx.cwd, latest.path, ctx.signal);
|
|
1437
1286
|
const updated = await listWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1438
1287
|
if (updated.some((record) => pathsEqual(record.path, selected.path))) {
|
|
@@ -1441,9 +1290,7 @@ ${latestInventory.ignored.join("\n") || "(none)"}`
|
|
|
1441
1290
|
safeNotify(ctx, `Removed worktree ${selected.path}. Its branch was preserved.`, "info");
|
|
1442
1291
|
}
|
|
1443
1292
|
async function pruneFlow(pi, ctx, records) {
|
|
1444
|
-
for (const record of records.filter(
|
|
1445
|
-
(candidate) => candidate.prunableReason !== void 0 && candidate.detached
|
|
1446
|
-
)) {
|
|
1293
|
+
for (const record of records.filter((candidate) => candidate.prunableReason !== void 0 && candidate.detached)) {
|
|
1447
1294
|
await assertDetachedHeadIsDurable(pi, ctx, record);
|
|
1448
1295
|
}
|
|
1449
1296
|
const preview = await prunePreview(pi, ctx.cwd, ctx.signal);
|
|
@@ -1463,9 +1310,7 @@ ${safePreview}`, "warning");
|
|
|
1463
1310
|
return;
|
|
1464
1311
|
}
|
|
1465
1312
|
const latest = await listWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1466
|
-
for (const record of latest.filter(
|
|
1467
|
-
(candidate) => candidate.prunableReason !== void 0 && candidate.detached
|
|
1468
|
-
)) {
|
|
1313
|
+
for (const record of latest.filter((candidate) => candidate.prunableReason !== void 0 && candidate.detached)) {
|
|
1469
1314
|
await assertDetachedHeadIsDurable(pi, ctx, record);
|
|
1470
1315
|
}
|
|
1471
1316
|
const beforePreviewHistoryRisks = await inspectAdministrativePruneCandidates(pi, ctx);
|
|
@@ -1478,19 +1323,11 @@ ${safePreview}`, "warning");
|
|
|
1478
1323
|
throw new Error("Stale worktree metadata changed after confirmation; run prune again.");
|
|
1479
1324
|
}
|
|
1480
1325
|
const output = await pruneWorktrees(pi, ctx.cwd, ctx.signal);
|
|
1481
|
-
safeNotify(
|
|
1482
|
-
|
|
1483
|
-
output ? `Pruned stale worktree metadata:
|
|
1484
|
-
${output}` : "Pruned stale worktree metadata.",
|
|
1485
|
-
"info"
|
|
1486
|
-
);
|
|
1326
|
+
safeNotify(ctx, output ? `Pruned stale worktree metadata:
|
|
1327
|
+
${output}` : "Pruned stale worktree metadata.", "info");
|
|
1487
1328
|
}
|
|
1488
1329
|
async function assertAdministrativeHistoryUnchanged(pi, ctx, selectedPath, approvedAdministrativePath, approvedHistoryRisks) {
|
|
1489
|
-
const latestAdministrativePath = await worktreeAdministrativeDirectory(
|
|
1490
|
-
pi,
|
|
1491
|
-
selectedPath,
|
|
1492
|
-
ctx.signal
|
|
1493
|
-
);
|
|
1330
|
+
const latestAdministrativePath = await worktreeAdministrativeDirectory(pi, selectedPath, ctx.signal);
|
|
1494
1331
|
const latestHistoryRisks = historyRisks(
|
|
1495
1332
|
selectedPath,
|
|
1496
1333
|
await unreachableAdministrativeHistoryOids(pi, ctx, latestAdministrativePath)
|
|
@@ -1522,10 +1359,7 @@ async function inspectAdministrativePruneCandidates(pi, ctx) {
|
|
|
1522
1359
|
);
|
|
1523
1360
|
}
|
|
1524
1361
|
risks.push(
|
|
1525
|
-
...historyRisks(
|
|
1526
|
-
candidate.id,
|
|
1527
|
-
await unreachableAdministrativeHistoryOids(pi, ctx, candidate.administrativePath)
|
|
1528
|
-
)
|
|
1362
|
+
...historyRisks(candidate.id, await unreachableAdministrativeHistoryOids(pi, ctx, candidate.administrativePath))
|
|
1529
1363
|
);
|
|
1530
1364
|
}
|
|
1531
1365
|
return normalizeAdministrativeHistoryRisks(risks);
|
|
@@ -1549,9 +1383,7 @@ function sameAdministrativeHistoryRisks(left, right) {
|
|
|
1549
1383
|
}
|
|
1550
1384
|
function formatAdministrativeRecoveryWarning(risks) {
|
|
1551
1385
|
if (risks.length === 0) return "";
|
|
1552
|
-
const entries = risks.map(
|
|
1553
|
-
(risk) => `${stripTerminalControls(risk.label)}: ${risk.oids.map(stripTerminalControls).join(", ")}`
|
|
1554
|
-
).join("; ");
|
|
1386
|
+
const entries = risks.map((risk) => `${stripTerminalControls(risk.label)}: ${risk.oids.map(stripTerminalControls).join(", ")}`).join("; ");
|
|
1555
1387
|
return ` Administrative recovery warning: these commits are not reachable from a branch, tag, or remote ref: ${entries}. Discarding their recovery pointers means they may later be garbage-collected.`;
|
|
1556
1388
|
}
|
|
1557
1389
|
function classifyRemovalInventory(lines) {
|
|
@@ -1578,8 +1410,7 @@ ${ignored.map(stripTerminalControls).join("\n")}`;
|
|
|
1578
1410
|
}
|
|
1579
1411
|
async function assertDetachedHeadIsDurable(pi, ctx, record) {
|
|
1580
1412
|
if (!record.detached) return;
|
|
1581
|
-
if (!record.head)
|
|
1582
|
-
throw new Error(`Detached worktree ${record.path} has no HEAD object; refusing.`);
|
|
1413
|
+
if (!record.head) throw new Error(`Detached worktree ${record.path} has no HEAD object; refusing.`);
|
|
1583
1414
|
const refs = await durableRefsContaining(pi, ctx.cwd, record.head, ctx.signal);
|
|
1584
1415
|
if (refs.length === 0) {
|
|
1585
1416
|
throw new Error(
|
|
@@ -1808,12 +1639,7 @@ function createWorktreeSettingsRuntime(options = {}) {
|
|
|
1808
1639
|
state = { ...state, warning: latest.warning, canSave: false };
|
|
1809
1640
|
throw new Error(`Fix the pi-worktree settings file at ${getPath()} before changing it.`);
|
|
1810
1641
|
}
|
|
1811
|
-
await saveWorktreeSettings(
|
|
1812
|
-
latest.document ?? {},
|
|
1813
|
-
configuredRoot,
|
|
1814
|
-
getPath(),
|
|
1815
|
-
options.operations
|
|
1816
|
-
);
|
|
1642
|
+
await saveWorktreeSettings(latest.document ?? {}, configuredRoot, getPath(), options.operations);
|
|
1817
1643
|
state = {
|
|
1818
1644
|
effectiveRoot,
|
|
1819
1645
|
source: configuredRoot === void 0 ? "default" : "user",
|