@narumitw/pi-worktree 0.51.6 → 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 +54 -78
- package/dist/index.ts +54 -227
- package/dist/index.ts.map +2 -2
- package/package.json +49 -53
- package/src/command.ts +605 -693
- package/src/git.ts +635 -731
- package/src/session.ts +77 -81
- package/src/settings.ts +211 -223
- package/src/status.ts +287 -309
- package/src/worktree.ts +26 -33
package/src/status.ts
CHANGED
|
@@ -8,377 +8,355 @@ const OID_PATTERN = /^[0-9a-fA-F]{40,64}$/u;
|
|
|
8
8
|
const STATUS_XY_PATTERN = /^[.MADRCUT]{2}$/u;
|
|
9
9
|
|
|
10
10
|
export interface WorktreeStatusSnapshot {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
headOid?: string;
|
|
12
|
+
branch?: string;
|
|
13
|
+
detached: boolean;
|
|
14
|
+
upstream?: string;
|
|
15
|
+
ahead?: number;
|
|
16
|
+
behind?: number;
|
|
17
|
+
staged: number;
|
|
18
|
+
unstaged: number;
|
|
19
|
+
untracked: number;
|
|
20
|
+
conflicts: number;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface LastCommitSummary {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
committedAt: string;
|
|
25
|
+
subject: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export type WorktreeStatusResult =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
| {
|
|
30
|
+
kind: "available";
|
|
31
|
+
snapshot: WorktreeStatusSnapshot;
|
|
32
|
+
lastCommit?: LastCommitSummary;
|
|
33
|
+
}
|
|
34
|
+
| { kind: "unavailable"; reason: string };
|
|
35
35
|
|
|
36
36
|
export interface WorktreeStatusCard {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
description: string;
|
|
40
|
+
statusText: string;
|
|
41
|
+
searchText: string;
|
|
42
|
+
details: string[];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
interface LoadStatusOptions {
|
|
46
|
-
|
|
46
|
+
concurrency?: number;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export function parseWorktreeStatusPorcelain(output: string): WorktreeStatusSnapshot {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
if (output && !output.endsWith("\0")) {
|
|
51
|
+
throw new Error("Git status porcelain output is not NUL-terminated.");
|
|
52
|
+
}
|
|
53
|
+
const entries = output ? output.slice(0, -1).split("\0") : [];
|
|
54
|
+
const snapshot: WorktreeStatusSnapshot = {
|
|
55
|
+
detached: false,
|
|
56
|
+
staged: 0,
|
|
57
|
+
unstaged: 0,
|
|
58
|
+
untracked: 0,
|
|
59
|
+
conflicts: 0,
|
|
60
|
+
};
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
62
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
63
|
+
const entry = entries[index] ?? "";
|
|
64
|
+
if (entry.startsWith("# ")) {
|
|
65
|
+
parseBranchHeader(snapshot, entry);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (entry.startsWith("1 ")) {
|
|
69
|
+
assertFieldCount(entry, 9, "ordinary");
|
|
70
|
+
countTrackedState(snapshot, statusCode(entry));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (entry.startsWith("2 ")) {
|
|
74
|
+
assertFieldCount(entry, 10, "renamed");
|
|
75
|
+
countTrackedState(snapshot, statusCode(entry));
|
|
76
|
+
const originalPath = entries[index + 1];
|
|
77
|
+
if (!originalPath) throw new Error("Git status returned a malformed renamed record.");
|
|
78
|
+
index += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (entry.startsWith("u ")) {
|
|
82
|
+
assertFieldCount(entry, 11, "unmerged");
|
|
83
|
+
statusCode(entry);
|
|
84
|
+
snapshot.conflicts += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (entry.startsWith("? ")) {
|
|
88
|
+
if (entry.length === 2) throw new Error("Git status returned a malformed untracked record.");
|
|
89
|
+
snapshot.untracked += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (entry.startsWith("! ")) continue;
|
|
93
|
+
throw new Error("Git status returned an unknown porcelain-v2 record.");
|
|
94
|
+
}
|
|
95
|
+
return snapshot;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function formatWorktreeStatusCard(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
record: WorktreeRecord,
|
|
100
|
+
currentPath: string,
|
|
101
|
+
result: WorktreeStatusResult,
|
|
102
102
|
): WorktreeStatusCard {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
? `Prunable: ${safeDisplay(record.prunableReason)}`
|
|
135
|
-
: "Prunable: no reason provided",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
103
|
+
const path = safeDisplay(record.path);
|
|
104
|
+
const identity = [
|
|
105
|
+
pathsEqual(record.path, currentPath) ? "current" : undefined,
|
|
106
|
+
record.isMain ? "main" : undefined,
|
|
107
|
+
record.bare ? "bare" : undefined,
|
|
108
|
+
record.detached ? "detached" : undefined,
|
|
109
|
+
].filter((value): value is string => value !== undefined);
|
|
110
|
+
const label = safeDisplay(
|
|
111
|
+
record.branch ??
|
|
112
|
+
(record.detached
|
|
113
|
+
? `Detached ${record.head?.slice(0, 8) ?? "HEAD"}`
|
|
114
|
+
: record.bare
|
|
115
|
+
? "Bare worktree"
|
|
116
|
+
: "Unknown worktree"),
|
|
117
|
+
);
|
|
118
|
+
const statePrefix = identity.length > 0 ? `${identity.join(" · ")} · ` : "";
|
|
119
|
+
const baseDetails = [
|
|
120
|
+
`Path: ${path}`,
|
|
121
|
+
`Identity: ${identity.join(" · ") || "linked"}`,
|
|
122
|
+
`Registered HEAD: ${safeDisplay(record.head ?? "unavailable")}`,
|
|
123
|
+
];
|
|
124
|
+
if (record.lockedReason !== undefined) {
|
|
125
|
+
baseDetails.push(
|
|
126
|
+
record.lockedReason ? `Locked: ${safeDisplay(record.lockedReason)}` : "Locked: no reason provided",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (record.prunableReason !== undefined) {
|
|
130
|
+
baseDetails.push(
|
|
131
|
+
record.prunableReason ? `Prunable: ${safeDisplay(record.prunableReason)}` : "Prunable: no reason provided",
|
|
132
|
+
);
|
|
133
|
+
}
|
|
138
134
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
"Snapshot: local Git state; no fetch performed.",
|
|
151
|
-
],
|
|
152
|
-
};
|
|
153
|
-
}
|
|
135
|
+
if (result.kind === "unavailable") {
|
|
136
|
+
const reason = safeDisplay(result.reason);
|
|
137
|
+
return {
|
|
138
|
+
id: record.path,
|
|
139
|
+
label,
|
|
140
|
+
description: path,
|
|
141
|
+
statusText: `${statePrefix}unavailable`,
|
|
142
|
+
searchText: `${label} ${path} ${identity.join(" ")} unavailable ${reason}`,
|
|
143
|
+
details: [...baseDetails, `Status: ${reason}`, "Snapshot: local Git state; no fetch performed."],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
147
|
+
const { snapshot, lastCommit } = result;
|
|
148
|
+
const workingState = formatWorkingState(snapshot);
|
|
149
|
+
const upstream = snapshot.upstream
|
|
150
|
+
? snapshot.ahead !== undefined && snapshot.behind !== undefined
|
|
151
|
+
? `${safeDisplay(snapshot.upstream)} · ahead ${snapshot.ahead} · behind ${snapshot.behind}`
|
|
152
|
+
: `${safeDisplay(snapshot.upstream)} · ahead/behind unavailable`
|
|
153
|
+
: "not configured; ahead/behind unavailable";
|
|
154
|
+
const details = [
|
|
155
|
+
...baseDetails,
|
|
156
|
+
`Snapshot HEAD: ${safeDisplay(snapshot.headOid ?? "unborn")}`,
|
|
157
|
+
`Working tree: ${workingState}`,
|
|
158
|
+
`Upstream: ${upstream}`,
|
|
159
|
+
lastCommit
|
|
160
|
+
? `Last commit: ${safeDisplay(lastCommit.committedAt)} · ${safeDisplay(lastCommit.subject || "(no subject)")}`
|
|
161
|
+
: "Last commit: unavailable",
|
|
162
|
+
"Snapshot: local Git state; no fetch performed; removal uses stricter checks.",
|
|
163
|
+
];
|
|
164
|
+
return {
|
|
165
|
+
id: record.path,
|
|
166
|
+
label,
|
|
167
|
+
description: path,
|
|
168
|
+
statusText: `${statePrefix}${workingState}`,
|
|
169
|
+
searchText: `${label} ${path} ${identity.join(" ")} ${workingState} ${safeDisplay(snapshot.upstream ?? "")}`,
|
|
170
|
+
details,
|
|
171
|
+
};
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
export async function loadWorktreeStatusCards(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
pi: Pick<ExtensionAPI, "exec">,
|
|
176
|
+
records: readonly WorktreeRecord[],
|
|
177
|
+
currentPath: string,
|
|
178
|
+
signal?: AbortSignal,
|
|
179
|
+
options: LoadStatusOptions = {},
|
|
188
180
|
): Promise<WorktreeStatusCard[]> {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
);
|
|
193
|
-
const cards = new Array<WorktreeStatusCard>(records.length);
|
|
194
|
-
let nextIndex = 0;
|
|
181
|
+
const concurrency = Math.max(1, Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1));
|
|
182
|
+
const cards = new Array<WorktreeStatusCard>(records.length);
|
|
183
|
+
let nextIndex = 0;
|
|
195
184
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
cards[index] = formatWorktreeStatusCard(record, currentPath, {
|
|
247
|
-
kind: "unavailable",
|
|
248
|
-
reason: `Status failed: ${formatError(error)}`,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
};
|
|
185
|
+
const worker = async () => {
|
|
186
|
+
while (true) {
|
|
187
|
+
throwIfAborted(signal);
|
|
188
|
+
const index = nextIndex;
|
|
189
|
+
if (index >= records.length) return;
|
|
190
|
+
nextIndex += 1;
|
|
191
|
+
const record = records[index];
|
|
192
|
+
if (!record) return;
|
|
193
|
+
const unavailable = unavailableReason(record);
|
|
194
|
+
if (unavailable) {
|
|
195
|
+
cards[index] = formatWorktreeStatusCard(record, currentPath, {
|
|
196
|
+
kind: "unavailable",
|
|
197
|
+
reason: unavailable,
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const status = await runGit(
|
|
203
|
+
pi,
|
|
204
|
+
["status", "--porcelain=v2", "--branch", "-z", "--untracked-files=all", "--ignore-submodules=none"],
|
|
205
|
+
record.path,
|
|
206
|
+
signal,
|
|
207
|
+
);
|
|
208
|
+
const snapshot = parseWorktreeStatusPorcelain(status.stdout);
|
|
209
|
+
const lastCommit = snapshot.headOid
|
|
210
|
+
? parseLastCommit(
|
|
211
|
+
(
|
|
212
|
+
await runGit(
|
|
213
|
+
pi,
|
|
214
|
+
["show", "-s", "--format=%aI%x00%s", "--end-of-options", snapshot.headOid],
|
|
215
|
+
record.path,
|
|
216
|
+
signal,
|
|
217
|
+
)
|
|
218
|
+
).stdout,
|
|
219
|
+
)
|
|
220
|
+
: undefined;
|
|
221
|
+
cards[index] = formatWorktreeStatusCard(record, currentPath, {
|
|
222
|
+
kind: "available",
|
|
223
|
+
snapshot,
|
|
224
|
+
lastCommit,
|
|
225
|
+
});
|
|
226
|
+
} catch (error) {
|
|
227
|
+
throwIfAborted(signal);
|
|
228
|
+
cards[index] = formatWorktreeStatusCard(record, currentPath, {
|
|
229
|
+
kind: "unavailable",
|
|
230
|
+
reason: `Status failed: ${formatError(error)}`,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
253
235
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
236
|
+
await Promise.all(Array.from({ length: concurrency }, worker));
|
|
237
|
+
throwIfAborted(signal);
|
|
238
|
+
return cards;
|
|
257
239
|
}
|
|
258
240
|
|
|
259
241
|
function parseBranchHeader(snapshot: WorktreeStatusSnapshot, entry: string): void {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
242
|
+
if (entry.startsWith("# branch.oid ")) {
|
|
243
|
+
const oid = entry.slice("# branch.oid ".length);
|
|
244
|
+
if (oid === "(initial)") {
|
|
245
|
+
snapshot.headOid = undefined;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (!OID_PATTERN.test(oid)) throw new Error("Git status returned a malformed branch OID.");
|
|
249
|
+
snapshot.headOid = oid;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (entry.startsWith("# branch.head ")) {
|
|
253
|
+
const branch = entry.slice("# branch.head ".length);
|
|
254
|
+
if (!branch) throw new Error("Git status returned a malformed branch head.");
|
|
255
|
+
snapshot.detached = branch === "(detached)";
|
|
256
|
+
snapshot.branch = snapshot.detached || branch === "(unknown)" ? undefined : branch;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (entry.startsWith("# branch.upstream ")) {
|
|
260
|
+
const upstream = entry.slice("# branch.upstream ".length);
|
|
261
|
+
if (!upstream) throw new Error("Git status returned a malformed upstream.");
|
|
262
|
+
snapshot.upstream = upstream;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (entry.startsWith("# branch.ab ")) {
|
|
266
|
+
const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(entry);
|
|
267
|
+
if (!match?.[1] || !match[2]) {
|
|
268
|
+
throw new Error("Git status returned malformed ahead/behind counts.");
|
|
269
|
+
}
|
|
270
|
+
snapshot.ahead = Number.parseInt(match[1], 10);
|
|
271
|
+
snapshot.behind = Number.parseInt(match[2], 10);
|
|
272
|
+
}
|
|
291
273
|
}
|
|
292
274
|
|
|
293
275
|
function statusCode(entry: string): string {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
276
|
+
const code = entry.slice(2, 4);
|
|
277
|
+
if (!STATUS_XY_PATTERN.test(code)) {
|
|
278
|
+
throw new Error("Git status returned a malformed tracked status code.");
|
|
279
|
+
}
|
|
280
|
+
return code;
|
|
299
281
|
}
|
|
300
282
|
|
|
301
283
|
function countTrackedState(snapshot: WorktreeStatusSnapshot, code: string): void {
|
|
302
|
-
|
|
303
|
-
|
|
284
|
+
if (code[0] !== ".") snapshot.staged += 1;
|
|
285
|
+
if (code[1] !== ".") snapshot.unstaged += 1;
|
|
304
286
|
}
|
|
305
287
|
|
|
306
288
|
function assertFieldCount(entry: string, minimum: number, kind: string): void {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
289
|
+
if (entry.split(" ").length < minimum) {
|
|
290
|
+
throw new Error(`Git status returned a malformed ${kind} record.`);
|
|
291
|
+
}
|
|
310
292
|
}
|
|
311
293
|
|
|
312
294
|
function formatWorkingState(snapshot: WorktreeStatusSnapshot): string {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
].filter((value): value is string => value !== undefined);
|
|
321
|
-
return values.join(" · ") || "clean";
|
|
295
|
+
const values = [
|
|
296
|
+
snapshot.conflicts > 0 ? `${snapshot.conflicts} conflict${snapshot.conflicts === 1 ? "" : "s"}` : undefined,
|
|
297
|
+
snapshot.staged > 0 ? `${snapshot.staged} staged` : undefined,
|
|
298
|
+
snapshot.unstaged > 0 ? `${snapshot.unstaged} unstaged` : undefined,
|
|
299
|
+
snapshot.untracked > 0 ? `${snapshot.untracked} untracked` : undefined,
|
|
300
|
+
].filter((value): value is string => value !== undefined);
|
|
301
|
+
return values.join(" · ") || "clean";
|
|
322
302
|
}
|
|
323
303
|
|
|
324
304
|
function unavailableReason(record: WorktreeRecord): string | undefined {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (!existsSync(record.path)) return "Worktree path is missing";
|
|
332
|
-
return undefined;
|
|
305
|
+
if (record.bare) return "Bare worktree cannot be inspected";
|
|
306
|
+
if (record.prunableReason !== undefined) {
|
|
307
|
+
return record.prunableReason ? `Prunable: ${record.prunableReason}` : "Prunable worktree metadata";
|
|
308
|
+
}
|
|
309
|
+
if (!existsSync(record.path)) return "Worktree path is missing";
|
|
310
|
+
return undefined;
|
|
333
311
|
}
|
|
334
312
|
|
|
335
313
|
async function runGit(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
314
|
+
pi: Pick<ExtensionAPI, "exec">,
|
|
315
|
+
args: string[],
|
|
316
|
+
cwd: string,
|
|
317
|
+
signal?: AbortSignal,
|
|
340
318
|
): Promise<ExecResult> {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
319
|
+
throwIfAborted(signal);
|
|
320
|
+
const result = await pi.exec("git", args, { cwd, signal, timeout: GIT_STATUS_TIMEOUT_MS });
|
|
321
|
+
if (result.killed) {
|
|
322
|
+
throwIfAborted(signal);
|
|
323
|
+
throw new Error(`git ${args.slice(0, 2).join(" ")} timed out.`);
|
|
324
|
+
}
|
|
325
|
+
if (result.code !== 0) {
|
|
326
|
+
const detail = [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join(" ");
|
|
327
|
+
throw new Error(detail || `git ${args.slice(0, 2).join(" ")} exited with code ${result.code}.`);
|
|
328
|
+
}
|
|
329
|
+
return result;
|
|
352
330
|
}
|
|
353
331
|
|
|
354
332
|
function parseLastCommit(output: string): LastCommitSummary {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
333
|
+
const separator = output.indexOf("\0");
|
|
334
|
+
if (separator <= 0 || output.indexOf("\0", separator + 1) >= 0) {
|
|
335
|
+
throw new Error("Git returned malformed last-commit details.");
|
|
336
|
+
}
|
|
337
|
+
const committedAt = output.slice(0, separator);
|
|
338
|
+
const subject = removeLineEnding(output.slice(separator + 1));
|
|
339
|
+
if (!committedAt) throw new Error("Git returned an empty last-commit timestamp.");
|
|
340
|
+
return { committedAt, subject };
|
|
363
341
|
}
|
|
364
342
|
|
|
365
343
|
function safeDisplay(value: string): string {
|
|
366
|
-
|
|
344
|
+
return stripTerminalControls(value);
|
|
367
345
|
}
|
|
368
346
|
|
|
369
347
|
function throwIfAborted(signal?: AbortSignal): void {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
348
|
+
if (signal?.aborted) {
|
|
349
|
+
throw new DOMException("Worktree status loading was aborted.", "AbortError");
|
|
350
|
+
}
|
|
373
351
|
}
|
|
374
352
|
|
|
375
353
|
function removeLineEnding(value: string): string {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
354
|
+
if (value.endsWith("\r\n")) return value.slice(0, -2);
|
|
355
|
+
if (value.endsWith("\n")) return value.slice(0, -1);
|
|
356
|
+
return value;
|
|
379
357
|
}
|
|
380
358
|
|
|
381
359
|
function formatError(error: unknown): string {
|
|
382
|
-
|
|
383
|
-
|
|
360
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
361
|
+
return safeDisplay(message).slice(0, 500);
|
|
384
362
|
}
|