@mizchi/bit 0.43.2
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 +341 -0
- package/bin/bit.mjs +11 -0
- package/bit.cjs +30712 -0
- package/bit.js +8 -0
- package/lib.d.ts +604 -0
- package/lib.js +1261 -0
- package/lib.raw.js +58436 -0
- package/package.json +44 -0
package/lib.js
ADDED
|
@@ -0,0 +1,1261 @@
|
|
|
1
|
+
import {
|
|
2
|
+
add as rawAdd,
|
|
3
|
+
branchCreate as rawBranchCreate,
|
|
4
|
+
branchDelete as rawBranchDelete,
|
|
5
|
+
branchList as rawBranchList,
|
|
6
|
+
branchRename as rawBranchRename,
|
|
7
|
+
buildCommitPayload as rawBuildCommitPayload,
|
|
8
|
+
cherryPick as rawCherryPick,
|
|
9
|
+
clone as rawClone,
|
|
10
|
+
checkout as rawCheckout,
|
|
11
|
+
checkoutB as rawCheckoutB,
|
|
12
|
+
commit as rawCommit,
|
|
13
|
+
commitAmend as rawCommitAmend,
|
|
14
|
+
commitSigned as rawCommitSigned,
|
|
15
|
+
commitSignedChecked as rawCommitSignedChecked,
|
|
16
|
+
diffIndex as rawDiffIndex,
|
|
17
|
+
diffIndexStat as rawDiffIndexStat,
|
|
18
|
+
diffWorktree as rawDiffWorktree,
|
|
19
|
+
diffWorktreeStat as rawDiffWorktreeStat,
|
|
20
|
+
destroyHost as rawDestroyHost,
|
|
21
|
+
fetch as rawFetch,
|
|
22
|
+
getRemoteUrl as rawGetRemoteUrl,
|
|
23
|
+
hostReadString as rawHostReadString,
|
|
24
|
+
hostWriteString as rawHostWriteString,
|
|
25
|
+
init as rawInit,
|
|
26
|
+
listRemotes as rawListRemotes,
|
|
27
|
+
listRemotesVerbose as rawListRemotesVerbose,
|
|
28
|
+
log as rawLog,
|
|
29
|
+
logOneline as rawLogOneline,
|
|
30
|
+
reflog as rawReflog,
|
|
31
|
+
mergeBase as rawMergeBase,
|
|
32
|
+
isAncestor as rawIsAncestor,
|
|
33
|
+
gc as rawGc,
|
|
34
|
+
fsck as rawFsck,
|
|
35
|
+
worktreeList as rawWorktreeList,
|
|
36
|
+
merge as rawMerge,
|
|
37
|
+
mv as rawMv,
|
|
38
|
+
push as rawPush,
|
|
39
|
+
rebaseAbort as rawRebaseAbort,
|
|
40
|
+
rebaseContinue as rawRebaseContinue,
|
|
41
|
+
rebaseSkip as rawRebaseSkip,
|
|
42
|
+
rebaseStart as rawRebaseStart,
|
|
43
|
+
rebaseStartWithOnto as rawRebaseStartWithOnto,
|
|
44
|
+
resolveSshEd25519PublicKey as rawResolveSshEd25519PublicKey,
|
|
45
|
+
reset as rawReset,
|
|
46
|
+
restore as rawRestore,
|
|
47
|
+
revParse as rawRevParse,
|
|
48
|
+
rm as rawRm,
|
|
49
|
+
signGitPayloadSshEd25519 as rawSignGitPayloadSshEd25519,
|
|
50
|
+
showRef as rawShowRef,
|
|
51
|
+
stashApply as rawStashApply,
|
|
52
|
+
stashDrop as rawStashDrop,
|
|
53
|
+
stashList as rawStashList,
|
|
54
|
+
stashPush as rawStashPush,
|
|
55
|
+
statusText as rawStatusText,
|
|
56
|
+
status as rawStatus,
|
|
57
|
+
statusPorcelain as rawStatusPorcelain,
|
|
58
|
+
sparseCheckoutAdd as rawSparseCheckoutAdd,
|
|
59
|
+
sparseCheckoutConeEnabled as rawSparseCheckoutConeEnabled,
|
|
60
|
+
sparseCheckoutDisable as rawSparseCheckoutDisable,
|
|
61
|
+
sparseCheckoutDisplayPatterns as rawSparseCheckoutDisplayPatterns,
|
|
62
|
+
sparseCheckoutEnabled as rawSparseCheckoutEnabled,
|
|
63
|
+
sparseCheckoutInit as rawSparseCheckoutInit,
|
|
64
|
+
sparseCheckoutPatterns as rawSparseCheckoutPatterns,
|
|
65
|
+
sparseCheckoutReapply as rawSparseCheckoutReapply,
|
|
66
|
+
sparseCheckoutSet as rawSparseCheckoutSet,
|
|
67
|
+
switchBranch as rawSwitchBranch,
|
|
68
|
+
tagCreateAnnotated as rawTagCreateAnnotated,
|
|
69
|
+
tagCreateLightweight as rawTagCreateLightweight,
|
|
70
|
+
tagDelete as rawTagDelete,
|
|
71
|
+
tagList as rawTagList,
|
|
72
|
+
verifyCommitSshEd25519 as rawVerifyCommitSshEd25519,
|
|
73
|
+
verifyGitPayloadSshEd25519 as rawVerifyGitPayloadSshEd25519,
|
|
74
|
+
} from "./lib.raw.js";
|
|
75
|
+
|
|
76
|
+
const ensureState = () => (
|
|
77
|
+
globalThis.__bitGitJsState ??= { nextHostId: 1, hosts: new Map() }
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const ensureTransportState = () => (
|
|
81
|
+
globalThis.__bitGitJsTransportState ??= { nextTransportId: 1, transports: new Map() }
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const backendHostIds = new WeakMap();
|
|
85
|
+
const transportIds = new WeakMap();
|
|
86
|
+
const fetchTransportCache = new WeakMap();
|
|
87
|
+
|
|
88
|
+
const isMoonBitResult = (value) => (
|
|
89
|
+
!!value &&
|
|
90
|
+
typeof value === "object" &&
|
|
91
|
+
"$tag" in value
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const unwrap = (label, result) => {
|
|
95
|
+
let current = result;
|
|
96
|
+
while (isMoonBitResult(current)) {
|
|
97
|
+
if (current.$tag === 1) {
|
|
98
|
+
current = current._0;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`${label}: ${String(current._0 ?? "bit js error")}`);
|
|
102
|
+
}
|
|
103
|
+
return current;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const callMoonBitAsync = (fn, ...args) => new Promise((resolve, reject) => {
|
|
107
|
+
let settled = false;
|
|
108
|
+
const finishResolve = (value) => {
|
|
109
|
+
if (settled) return;
|
|
110
|
+
settled = true;
|
|
111
|
+
resolve(value);
|
|
112
|
+
};
|
|
113
|
+
const finishReject = (error) => {
|
|
114
|
+
if (settled) return;
|
|
115
|
+
settled = true;
|
|
116
|
+
reject(error);
|
|
117
|
+
};
|
|
118
|
+
const immediate = fn(...args, finishResolve, finishReject);
|
|
119
|
+
if (immediate !== undefined) {
|
|
120
|
+
finishResolve(immediate);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const unwrapAsync = async (label, fn, ...args) => (
|
|
125
|
+
unwrap(label, await callMoonBitAsync(fn, ...args))
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const isBackendObject = (value) => (
|
|
129
|
+
!!value &&
|
|
130
|
+
typeof value === "object" &&
|
|
131
|
+
typeof value.readFile === "function" &&
|
|
132
|
+
typeof value.readdir === "function" &&
|
|
133
|
+
typeof value.isDir === "function" &&
|
|
134
|
+
typeof value.isFile === "function"
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const isTransportObject = (value) => (
|
|
138
|
+
!!value &&
|
|
139
|
+
typeof value === "object" &&
|
|
140
|
+
typeof value.get === "function" &&
|
|
141
|
+
typeof value.post === "function"
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const registerBackend = (backend) => {
|
|
145
|
+
const cached = backendHostIds.get(backend);
|
|
146
|
+
if (cached !== undefined) {
|
|
147
|
+
return cached;
|
|
148
|
+
}
|
|
149
|
+
const state = ensureState();
|
|
150
|
+
const hostId = state.nextHostId++;
|
|
151
|
+
state.hosts.set(hostId, backend);
|
|
152
|
+
backendHostIds.set(backend, hostId);
|
|
153
|
+
return hostId;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const toHostId = (backend) => {
|
|
157
|
+
if (isBackendObject(backend)) {
|
|
158
|
+
return registerBackend(backend);
|
|
159
|
+
}
|
|
160
|
+
throw new TypeError("expected bit backend");
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const createFetchTransport = (fetchImpl) => {
|
|
164
|
+
if (typeof fetchImpl !== "function") {
|
|
165
|
+
throw new TypeError("expected fetch implementation");
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
async get(url, headers) {
|
|
169
|
+
const response = await fetchImpl(url, { method: "GET", headers });
|
|
170
|
+
return {
|
|
171
|
+
status: response.status,
|
|
172
|
+
body: new Uint8Array(await response.arrayBuffer()),
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
async post(url, body, headers) {
|
|
176
|
+
const response = await fetchImpl(url, { method: "POST", headers, body });
|
|
177
|
+
return {
|
|
178
|
+
status: response.status,
|
|
179
|
+
body: new Uint8Array(await response.arrayBuffer()),
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const normalizeTransport = (transportOrFetch) => {
|
|
186
|
+
if (isTransportObject(transportOrFetch)) {
|
|
187
|
+
return transportOrFetch;
|
|
188
|
+
}
|
|
189
|
+
if (typeof transportOrFetch === "function") {
|
|
190
|
+
const cached = fetchTransportCache.get(transportOrFetch);
|
|
191
|
+
if (cached) {
|
|
192
|
+
return cached;
|
|
193
|
+
}
|
|
194
|
+
const transport = createFetchTransport(transportOrFetch);
|
|
195
|
+
fetchTransportCache.set(transportOrFetch, transport);
|
|
196
|
+
return transport;
|
|
197
|
+
}
|
|
198
|
+
throw new TypeError("expected bit transport or fetch implementation");
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const toTransportId = (transportOrFetch) => {
|
|
202
|
+
const transport = normalizeTransport(transportOrFetch);
|
|
203
|
+
const cached = transportIds.get(transport);
|
|
204
|
+
if (cached !== undefined) {
|
|
205
|
+
return cached;
|
|
206
|
+
}
|
|
207
|
+
const state = ensureTransportState();
|
|
208
|
+
const transportId = state.nextTransportId++;
|
|
209
|
+
state.transports.set(transportId, transport);
|
|
210
|
+
transportIds.set(transport, transportId);
|
|
211
|
+
return transportId;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const toUint8Array = (value) => {
|
|
215
|
+
if (value == null) return new Uint8Array();
|
|
216
|
+
if (value instanceof Uint8Array) return value;
|
|
217
|
+
if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
|
|
218
|
+
return new Uint8Array(value);
|
|
219
|
+
}
|
|
220
|
+
if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value)) {
|
|
221
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
222
|
+
}
|
|
223
|
+
if (typeof value === "string") {
|
|
224
|
+
return new TextEncoder().encode(value);
|
|
225
|
+
}
|
|
226
|
+
return Uint8Array.from(value);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const relayUsesSignaling = (remoteUrl) => (
|
|
230
|
+
typeof remoteUrl === "string" &&
|
|
231
|
+
(
|
|
232
|
+
remoteUrl.startsWith("relay+http://") ||
|
|
233
|
+
remoteUrl.startsWith("relay+https://") ||
|
|
234
|
+
remoteUrl.startsWith("relay://")
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const trimTrailingSlash = (value) => (
|
|
239
|
+
value.length > 1 && value.endsWith("/") ? value.slice(0, -1) : value
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const relayToHttpUrl = (remoteUrl) => {
|
|
243
|
+
if (typeof remoteUrl !== "string") {
|
|
244
|
+
throw new TypeError("expected remote URL string");
|
|
245
|
+
}
|
|
246
|
+
if (remoteUrl.startsWith("relay+http://") || remoteUrl.startsWith("relay+https://")) {
|
|
247
|
+
return remoteUrl.slice(6);
|
|
248
|
+
}
|
|
249
|
+
if (remoteUrl.startsWith("relay://")) {
|
|
250
|
+
return `http://${remoteUrl.slice(8)}`;
|
|
251
|
+
}
|
|
252
|
+
if (remoteUrl.startsWith("http://") || remoteUrl.startsWith("https://")) {
|
|
253
|
+
return remoteUrl;
|
|
254
|
+
}
|
|
255
|
+
throw new TypeError("relay url must be relay+http(s)://, relay://, or http(s)://");
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const relayDetectSession = (remoteUrl) => {
|
|
259
|
+
if (!relayUsesSignaling(remoteUrl)) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const normalized = trimTrailingSlash(relayToHttpUrl(remoteUrl));
|
|
263
|
+
const slashIndex = normalized.lastIndexOf("/");
|
|
264
|
+
if (slashIndex < 0) return null;
|
|
265
|
+
const sessionId = normalized.slice(slashIndex + 1);
|
|
266
|
+
if (!/^[A-Za-z0-9]{6,16}$/.test(sessionId)) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
baseUrl: normalized.slice(0, slashIndex),
|
|
271
|
+
sessionId,
|
|
272
|
+
url: `${normalized.slice(0, slashIndex)}/git/${sessionId}`,
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const relayResolveControlEndpoint = (remoteUrl) => {
|
|
277
|
+
const raw = trimTrailingSlash(relayToHttpUrl(remoteUrl));
|
|
278
|
+
const url = new URL(raw);
|
|
279
|
+
const room = (url.searchParams.get("room") ?? "main").trim() || "main";
|
|
280
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(room)) {
|
|
281
|
+
throw new Error(`invalid relay room: ${room}`);
|
|
282
|
+
}
|
|
283
|
+
const roomToken = (url.searchParams.get("room_token") ?? "").trim() || null;
|
|
284
|
+
url.search = "";
|
|
285
|
+
return {
|
|
286
|
+
baseUrl: trimTrailingSlash(url.toString()),
|
|
287
|
+
room,
|
|
288
|
+
roomToken,
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const relayPollUrl = ({ baseUrl, room, roomToken }) => {
|
|
293
|
+
const url = new URL(`${baseUrl}/api/v1/poll`);
|
|
294
|
+
url.searchParams.set("room", room);
|
|
295
|
+
url.searchParams.set("after", "0");
|
|
296
|
+
url.searchParams.set("limit", "200");
|
|
297
|
+
if (roomToken) {
|
|
298
|
+
url.searchParams.set("room_token", roomToken);
|
|
299
|
+
}
|
|
300
|
+
return url.toString();
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const relayAuthHeaders = (authToken) => (
|
|
304
|
+
authToken ? { Accept: "application/json", Authorization: `Bearer ${authToken}` } : { Accept: "application/json" }
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const relayDecodeJsonBody = (body) => (
|
|
308
|
+
JSON.parse(new TextDecoder().decode(toUint8Array(body)))
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const normalizeOptionalText = (value) => {
|
|
312
|
+
if (typeof value !== "string") return null;
|
|
313
|
+
const normalized = value.trim();
|
|
314
|
+
return normalized.length > 0 ? normalized : null;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const relayListClonePeers = async (remoteUrl, transportOrFetch, options = {}) => {
|
|
318
|
+
const transport = normalizeTransport(transportOrFetch);
|
|
319
|
+
const endpoint = relayResolveControlEndpoint(remoteUrl);
|
|
320
|
+
const response = await transport.get(
|
|
321
|
+
relayPollUrl(endpoint),
|
|
322
|
+
relayAuthHeaders(options.authToken ?? null),
|
|
323
|
+
);
|
|
324
|
+
if (Math.trunc(response?.status ?? response?.code ?? 0) !== 200) {
|
|
325
|
+
throw new Error(`relay poll failed: HTTP ${Math.trunc(response?.status ?? response?.code ?? 0)}`);
|
|
326
|
+
}
|
|
327
|
+
const payload = relayDecodeJsonBody(response?.body);
|
|
328
|
+
const peersBySender = new Map();
|
|
329
|
+
for (const envelope of Array.isArray(payload?.envelopes) ? payload.envelopes : []) {
|
|
330
|
+
const sender = normalizeOptionalText(envelope?.sender);
|
|
331
|
+
const kind = normalizeOptionalText(envelope?.payload?.kind);
|
|
332
|
+
const cloneUrl = normalizeOptionalText(envelope?.payload?.clone_url);
|
|
333
|
+
if (!sender || kind !== "bit.clone.announce.v1" || !cloneUrl) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
peersBySender.set(sender, {
|
|
337
|
+
sender,
|
|
338
|
+
cloneUrl,
|
|
339
|
+
repo: normalizeOptionalText(envelope?.payload?.repo),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return Array.from(peersBySender.values()).sort((a, b) => a.sender.localeCompare(b.sender));
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const selectRelayPeer = (peers, options = {}) => {
|
|
346
|
+
if (options.preferredSender) {
|
|
347
|
+
const bySender = peers.find((peer) => peer.sender === options.preferredSender);
|
|
348
|
+
if (bySender) return bySender;
|
|
349
|
+
}
|
|
350
|
+
if (options.preferredRepo) {
|
|
351
|
+
const byRepo = peers.find((peer) => peer.repo === options.preferredRepo);
|
|
352
|
+
if (byRepo) return byRepo;
|
|
353
|
+
}
|
|
354
|
+
return peers[0] ?? null;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
export const relayResolveRemote = async (remoteUrl, transportOrFetch, options = {}) => {
|
|
358
|
+
const session = relayDetectSession(remoteUrl);
|
|
359
|
+
if (session) {
|
|
360
|
+
return {
|
|
361
|
+
via: "session",
|
|
362
|
+
url: session.url,
|
|
363
|
+
sender: null,
|
|
364
|
+
repo: null,
|
|
365
|
+
sessionId: session.sessionId,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
const peers = await relayListClonePeers(remoteUrl, transportOrFetch, {
|
|
369
|
+
authToken: options.authToken ?? null,
|
|
370
|
+
});
|
|
371
|
+
const selected = selectRelayPeer(peers, options);
|
|
372
|
+
if (!selected) {
|
|
373
|
+
throw new Error(`No relay peers announced via relay: ${remoteUrl}`);
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
via: "peer",
|
|
377
|
+
url: selected.cloneUrl,
|
|
378
|
+
sender: selected.sender,
|
|
379
|
+
repo: selected.repo,
|
|
380
|
+
sessionId: null,
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const toStatus = (value) => ({
|
|
385
|
+
stagedAdded: Array.from(value.staged_added),
|
|
386
|
+
stagedModified: Array.from(value.staged_modified),
|
|
387
|
+
stagedDeleted: Array.from(value.staged_deleted),
|
|
388
|
+
unstagedModified: Array.from(value.unstaged_modified),
|
|
389
|
+
unstagedDeleted: Array.from(value.unstaged_deleted),
|
|
390
|
+
untracked: Array.from(value.untracked),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const toBranchInfo = (value) => ({
|
|
394
|
+
name: value.name,
|
|
395
|
+
commitId: value.commit_id,
|
|
396
|
+
isCurrent: Boolean(value.is_current),
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const toLogEntry = (value) => ({
|
|
400
|
+
id: value.id,
|
|
401
|
+
author: value.author,
|
|
402
|
+
message: value.message,
|
|
403
|
+
timestamp: value.timestamp,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const toRefInfo = (value) => ({
|
|
407
|
+
name: value.name,
|
|
408
|
+
id: value.id,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const toReflogEntry = (value) => ({
|
|
412
|
+
oldId: value.old_id,
|
|
413
|
+
newId: value.new_id,
|
|
414
|
+
author: value.author,
|
|
415
|
+
email: value.email,
|
|
416
|
+
timestamp: value.timestamp,
|
|
417
|
+
timezone: value.timezone,
|
|
418
|
+
message: value.message,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const toGcResult = (value) => ({
|
|
422
|
+
packId: toMaybeString(value.pack_id),
|
|
423
|
+
objectCount: value.object_count,
|
|
424
|
+
packBytes: value.pack_bytes,
|
|
425
|
+
dangling: Array.from(value.dangling),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const toFsckResult = (value) => ({
|
|
429
|
+
errors: value.errors,
|
|
430
|
+
reachable: value.reachable,
|
|
431
|
+
missing: Array.from(value.missing),
|
|
432
|
+
rootCommits: Array.from(value.root_commits),
|
|
433
|
+
tagObjects: Array.from(value.tag_objects),
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
const toWorktreeInfo = (value) => ({
|
|
437
|
+
path: value.path,
|
|
438
|
+
headId: toMaybeString(value.head_id),
|
|
439
|
+
branch: toMaybeString(value.branch),
|
|
440
|
+
locked: value.locked,
|
|
441
|
+
isMain: value.is_main,
|
|
442
|
+
isBare: value.is_bare,
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
const toRemoteVerboseEntry = (value) => ({
|
|
446
|
+
name: value.name,
|
|
447
|
+
value: value.value,
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const toStashEntry = (value) => ({
|
|
451
|
+
id: value.id,
|
|
452
|
+
message: value.message,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const toMaybeString = (value) => (
|
|
456
|
+
typeof value === "string" && value.length > 0 ? value : null
|
|
457
|
+
);
|
|
458
|
+
|
|
459
|
+
const mergeStatusMap = {
|
|
460
|
+
already_up_to_date: "alreadyUpToDate",
|
|
461
|
+
fast_forward: "fastForward",
|
|
462
|
+
merged: "merged",
|
|
463
|
+
conflicted: "conflicted",
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const rebaseStatusMap = {
|
|
467
|
+
complete: "complete",
|
|
468
|
+
conflict: "conflict",
|
|
469
|
+
nothing_to_rebase: "nothingToRebase",
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const cherryPickStatusMap = {
|
|
473
|
+
success: "success",
|
|
474
|
+
conflict: "conflict",
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
const toMergeResult = (value) => ({
|
|
478
|
+
status: mergeStatusMap[value.status] ?? value.status,
|
|
479
|
+
commitId: toMaybeString(value.commit_id),
|
|
480
|
+
conflicts: Array.from(value.conflicts),
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
const toRebaseResult = (value) => ({
|
|
484
|
+
status: rebaseStatusMap[value.status] ?? value.status,
|
|
485
|
+
commitId: toMaybeString(value.commit_id),
|
|
486
|
+
conflicts: Array.from(value.conflicts),
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
const toCherryPickResult = (value) => ({
|
|
490
|
+
status: cherryPickStatusMap[value.status] ?? value.status,
|
|
491
|
+
commitId: toMaybeString(value.commit_id),
|
|
492
|
+
conflicts: Array.from(value.conflicts),
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const toFetchResult = (value) => ({
|
|
496
|
+
status: value.status,
|
|
497
|
+
commitId: toMaybeString(value.commit_id),
|
|
498
|
+
refname: toMaybeString(value.refname),
|
|
499
|
+
remoteRef: toMaybeString(value.remote_ref),
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
const toCloneResult = (value) => ({
|
|
503
|
+
status: value.status,
|
|
504
|
+
commitId: toMaybeString(value.commit_id),
|
|
505
|
+
refname: toMaybeString(value.refname),
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const createMemoryBackendImpl = () => {
|
|
509
|
+
const encoder = new TextEncoder();
|
|
510
|
+
const decoder = new TextDecoder();
|
|
511
|
+
const files = new Map();
|
|
512
|
+
const dirs = new Set(["/"]);
|
|
513
|
+
|
|
514
|
+
const normalizePath = (path) => {
|
|
515
|
+
if (path == null || path === "") return "/";
|
|
516
|
+
let normalized = String(path).replace(/\/+/g, "/");
|
|
517
|
+
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
|
518
|
+
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
519
|
+
normalized = normalized.slice(0, -1);
|
|
520
|
+
}
|
|
521
|
+
return normalized;
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
const parentDir = (path) => {
|
|
525
|
+
const normalized = normalizePath(path);
|
|
526
|
+
if (normalized === "/") return "/";
|
|
527
|
+
const index = normalized.lastIndexOf("/");
|
|
528
|
+
return index <= 0 ? "/" : normalized.slice(0, index);
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
const baseName = (path) => {
|
|
532
|
+
const normalized = normalizePath(path);
|
|
533
|
+
if (normalized === "/") return "/";
|
|
534
|
+
const index = normalized.lastIndexOf("/");
|
|
535
|
+
return index < 0 ? normalized : normalized.slice(index + 1);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
const ensureDirs = (path) => {
|
|
539
|
+
const normalized = normalizePath(path);
|
|
540
|
+
if (normalized === "/") {
|
|
541
|
+
dirs.add("/");
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
545
|
+
let current = "";
|
|
546
|
+
for (const part of parts) {
|
|
547
|
+
current += `/${part}`;
|
|
548
|
+
dirs.add(current);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
return {
|
|
553
|
+
mkdirP(path) {
|
|
554
|
+
ensureDirs(path);
|
|
555
|
+
},
|
|
556
|
+
writeFile(path, content) {
|
|
557
|
+
const normalized = normalizePath(path);
|
|
558
|
+
ensureDirs(parentDir(normalized));
|
|
559
|
+
files.set(normalized, Uint8Array.from(content));
|
|
560
|
+
},
|
|
561
|
+
writeString(path, content) {
|
|
562
|
+
this.writeFile(path, encoder.encode(String(content)));
|
|
563
|
+
},
|
|
564
|
+
removeFile(path) {
|
|
565
|
+
const normalized = normalizePath(path);
|
|
566
|
+
if (!files.delete(normalized)) {
|
|
567
|
+
throw new Error(`File not found: ${normalized}`);
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
removeDir(path) {
|
|
571
|
+
const normalized = normalizePath(path);
|
|
572
|
+
if (!dirs.has(normalized)) {
|
|
573
|
+
throw new Error(`Directory not found: ${normalized}`);
|
|
574
|
+
}
|
|
575
|
+
for (const filePath of files.keys()) {
|
|
576
|
+
if (parentDir(filePath) === normalized) {
|
|
577
|
+
throw new Error(`Directory not empty: ${normalized}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
for (const dirPath of dirs.values()) {
|
|
581
|
+
if (dirPath !== normalized && parentDir(dirPath) === normalized) {
|
|
582
|
+
throw new Error(`Directory not empty: ${normalized}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
dirs.delete(normalized);
|
|
586
|
+
},
|
|
587
|
+
readFile(path) {
|
|
588
|
+
const normalized = normalizePath(path);
|
|
589
|
+
const value = files.get(normalized);
|
|
590
|
+
if (!value) {
|
|
591
|
+
throw new Error(`File not found: ${normalized}`);
|
|
592
|
+
}
|
|
593
|
+
return Uint8Array.from(value);
|
|
594
|
+
},
|
|
595
|
+
readdir(path) {
|
|
596
|
+
const normalized = normalizePath(path);
|
|
597
|
+
if (!dirs.has(normalized)) {
|
|
598
|
+
throw new Error(`Directory not found: ${normalized}`);
|
|
599
|
+
}
|
|
600
|
+
const entries = new Set();
|
|
601
|
+
for (const filePath of files.keys()) {
|
|
602
|
+
if (parentDir(filePath) === normalized) {
|
|
603
|
+
entries.add(baseName(filePath));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
for (const dirPath of dirs.values()) {
|
|
607
|
+
if (dirPath !== normalized && parentDir(dirPath) === normalized) {
|
|
608
|
+
entries.add(baseName(dirPath));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return Array.from(entries).sort();
|
|
612
|
+
},
|
|
613
|
+
isDir(path) {
|
|
614
|
+
return dirs.has(normalizePath(path));
|
|
615
|
+
},
|
|
616
|
+
isFile(path) {
|
|
617
|
+
return files.has(normalizePath(path));
|
|
618
|
+
},
|
|
619
|
+
readString(path) {
|
|
620
|
+
return decoder.decode(this.readFile(path));
|
|
621
|
+
},
|
|
622
|
+
};
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
export const createMemoryBackend = () => createMemoryBackendImpl();
|
|
626
|
+
|
|
627
|
+
export const destroyBackend = (backend) => {
|
|
628
|
+
if (!isBackendObject(backend)) {
|
|
629
|
+
throw new TypeError("expected bit backend");
|
|
630
|
+
}
|
|
631
|
+
const hostId = backendHostIds.get(backend);
|
|
632
|
+
if (hostId === undefined) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
backendHostIds.delete(backend);
|
|
636
|
+
rawDestroyHost(hostId);
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
export const writeString = (backend, path, content) => {
|
|
640
|
+
unwrap("writeString", rawHostWriteString(toHostId(backend), path, content));
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
export const readString = (backend, path) => (
|
|
644
|
+
unwrap("readString", rawHostReadString(toHostId(backend), path))
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
export const init = (backend, root, defaultBranch = "main") => {
|
|
648
|
+
unwrap("init", rawInit(toHostId(backend), root, defaultBranch));
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
export const add = (backend, root, paths) => {
|
|
652
|
+
unwrap("add", rawAdd(toHostId(backend), root, Array.from(paths)));
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
export const status = (backend, root) => (
|
|
656
|
+
toStatus(unwrap("status", rawStatus(toHostId(backend), root)))
|
|
657
|
+
);
|
|
658
|
+
|
|
659
|
+
export const statusPorcelain = (backend, root) => (
|
|
660
|
+
Array.from(unwrap("statusPorcelain", rawStatusPorcelain(toHostId(backend), root)))
|
|
661
|
+
);
|
|
662
|
+
|
|
663
|
+
export const statusText = async (backend, root) => (
|
|
664
|
+
await unwrapAsync("statusText", rawStatusText, toHostId(backend), root)
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
export const commit = (
|
|
668
|
+
backend,
|
|
669
|
+
root,
|
|
670
|
+
message,
|
|
671
|
+
author,
|
|
672
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
673
|
+
) => (
|
|
674
|
+
unwrap("commit", rawCommit(toHostId(backend), root, message, author, Math.trunc(timestampSec)))
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
export const commitAmend = (
|
|
678
|
+
backend,
|
|
679
|
+
root,
|
|
680
|
+
message,
|
|
681
|
+
author,
|
|
682
|
+
authorTimestampSec = Math.floor(Date.now() / 1000),
|
|
683
|
+
options = {},
|
|
684
|
+
) => (
|
|
685
|
+
unwrap(
|
|
686
|
+
"commitAmend",
|
|
687
|
+
rawCommitAmend(
|
|
688
|
+
toHostId(backend),
|
|
689
|
+
root,
|
|
690
|
+
message,
|
|
691
|
+
author,
|
|
692
|
+
Math.trunc(authorTimestampSec),
|
|
693
|
+
options.committer ?? "",
|
|
694
|
+
Math.trunc(options.committerTimestampSec ?? authorTimestampSec),
|
|
695
|
+
options.timezone ?? "",
|
|
696
|
+
options.encoding ?? "",
|
|
697
|
+
options.authorTimezone ?? "",
|
|
698
|
+
options.committerTimezone ?? "",
|
|
699
|
+
),
|
|
700
|
+
)
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
export const buildCommitPayload = (
|
|
704
|
+
backend,
|
|
705
|
+
root,
|
|
706
|
+
message,
|
|
707
|
+
author,
|
|
708
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
709
|
+
) => (
|
|
710
|
+
unwrap(
|
|
711
|
+
"buildCommitPayload",
|
|
712
|
+
rawBuildCommitPayload(toHostId(backend), root, message, author, Math.trunc(timestampSec)),
|
|
713
|
+
)
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
export const commitSigned = (
|
|
717
|
+
backend,
|
|
718
|
+
root,
|
|
719
|
+
message,
|
|
720
|
+
author,
|
|
721
|
+
signature,
|
|
722
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
723
|
+
) => (
|
|
724
|
+
unwrap(
|
|
725
|
+
"commitSigned",
|
|
726
|
+
rawCommitSigned(
|
|
727
|
+
toHostId(backend),
|
|
728
|
+
root,
|
|
729
|
+
message,
|
|
730
|
+
author,
|
|
731
|
+
Math.trunc(timestampSec),
|
|
732
|
+
signature,
|
|
733
|
+
),
|
|
734
|
+
)
|
|
735
|
+
);
|
|
736
|
+
|
|
737
|
+
export const commitSignedChecked = (
|
|
738
|
+
backend,
|
|
739
|
+
root,
|
|
740
|
+
message,
|
|
741
|
+
author,
|
|
742
|
+
expectedPayload,
|
|
743
|
+
signature,
|
|
744
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
745
|
+
) => (
|
|
746
|
+
unwrap(
|
|
747
|
+
"commitSignedChecked",
|
|
748
|
+
rawCommitSignedChecked(
|
|
749
|
+
toHostId(backend),
|
|
750
|
+
root,
|
|
751
|
+
message,
|
|
752
|
+
author,
|
|
753
|
+
Math.trunc(timestampSec),
|
|
754
|
+
expectedPayload,
|
|
755
|
+
signature,
|
|
756
|
+
),
|
|
757
|
+
)
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
export const commitWithSigner = async (
|
|
761
|
+
backend,
|
|
762
|
+
root,
|
|
763
|
+
message,
|
|
764
|
+
author,
|
|
765
|
+
signer,
|
|
766
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
767
|
+
) => {
|
|
768
|
+
const payload = buildCommitPayload(backend, root, message, author, timestampSec);
|
|
769
|
+
const signature = await signer(payload);
|
|
770
|
+
if (typeof signature !== "string" || signature.length === 0) {
|
|
771
|
+
throw new TypeError("signer must return a non-empty signature string");
|
|
772
|
+
}
|
|
773
|
+
return commitSignedChecked(
|
|
774
|
+
backend,
|
|
775
|
+
root,
|
|
776
|
+
message,
|
|
777
|
+
author,
|
|
778
|
+
payload,
|
|
779
|
+
signature,
|
|
780
|
+
timestampSec,
|
|
781
|
+
);
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
export const resolveSshEd25519PublicKey = async (
|
|
785
|
+
privateKeyPem,
|
|
786
|
+
comment = "",
|
|
787
|
+
) => (
|
|
788
|
+
await unwrapAsync(
|
|
789
|
+
"resolveSshEd25519PublicKey",
|
|
790
|
+
rawResolveSshEd25519PublicKey,
|
|
791
|
+
privateKeyPem,
|
|
792
|
+
comment,
|
|
793
|
+
)
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
export const signGitPayloadSshEd25519 = async (
|
|
797
|
+
privateKeyPem,
|
|
798
|
+
payload,
|
|
799
|
+
) => (
|
|
800
|
+
await unwrapAsync(
|
|
801
|
+
"signGitPayloadSshEd25519",
|
|
802
|
+
rawSignGitPayloadSshEd25519,
|
|
803
|
+
privateKeyPem,
|
|
804
|
+
payload,
|
|
805
|
+
)
|
|
806
|
+
);
|
|
807
|
+
|
|
808
|
+
export const verifyGitPayloadSshEd25519 = async (
|
|
809
|
+
publicKey,
|
|
810
|
+
payload,
|
|
811
|
+
signature,
|
|
812
|
+
) => (
|
|
813
|
+
await unwrapAsync(
|
|
814
|
+
"verifyGitPayloadSshEd25519",
|
|
815
|
+
rawVerifyGitPayloadSshEd25519,
|
|
816
|
+
publicKey,
|
|
817
|
+
payload,
|
|
818
|
+
signature,
|
|
819
|
+
)
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
export const verifyCommitSshEd25519 = async (
|
|
823
|
+
backend,
|
|
824
|
+
root,
|
|
825
|
+
spec,
|
|
826
|
+
publicKey,
|
|
827
|
+
) => (
|
|
828
|
+
await unwrapAsync(
|
|
829
|
+
"verifyCommitSshEd25519",
|
|
830
|
+
rawVerifyCommitSshEd25519,
|
|
831
|
+
toHostId(backend),
|
|
832
|
+
root,
|
|
833
|
+
spec,
|
|
834
|
+
publicKey,
|
|
835
|
+
)
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
export const log = (backend, root, maxCount = 32) => (
|
|
839
|
+
Array.from(unwrap("log", rawLog(toHostId(backend), root, Math.trunc(maxCount)))).map(toLogEntry)
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
export const logOneline = (backend, root, maxCount = 32) => (
|
|
843
|
+
Array.from(unwrap("logOneline", rawLogOneline(toHostId(backend), root, Math.trunc(maxCount))))
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
export const revParse = (backend, root, spec) => (
|
|
847
|
+
toMaybeString(unwrap("revParse", rawRevParse(toHostId(backend), root, spec)))
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
export const showRef = (backend, root) => (
|
|
851
|
+
Array.from(unwrap("showRef", rawShowRef(toHostId(backend), root))).map(toRefInfo)
|
|
852
|
+
);
|
|
853
|
+
|
|
854
|
+
export const reflog = (backend, root, refname = "HEAD") => (
|
|
855
|
+
Array.from(unwrap("reflog", rawReflog(toHostId(backend), root, refname))).map(toReflogEntry)
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
export const mergeBase = (backend, root, a, b) => (
|
|
859
|
+
Array.from(unwrap("mergeBase", rawMergeBase(toHostId(backend), root, a, b)))
|
|
860
|
+
);
|
|
861
|
+
|
|
862
|
+
export const isAncestor = (backend, root, ancestor, descendant) => (
|
|
863
|
+
unwrap("isAncestor", rawIsAncestor(toHostId(backend), root, ancestor, descendant))
|
|
864
|
+
);
|
|
865
|
+
|
|
866
|
+
export const gc = (backend, root) => (
|
|
867
|
+
toGcResult(unwrap("gc", rawGc(toHostId(backend), root)))
|
|
868
|
+
);
|
|
869
|
+
|
|
870
|
+
export const fsck = (backend, root) => (
|
|
871
|
+
toFsckResult(unwrap("fsck", rawFsck(toHostId(backend), root)))
|
|
872
|
+
);
|
|
873
|
+
|
|
874
|
+
export const worktreeList = (backend, root) => (
|
|
875
|
+
Array.from(unwrap("worktreeList", rawWorktreeList(toHostId(backend), root))).map(toWorktreeInfo)
|
|
876
|
+
);
|
|
877
|
+
|
|
878
|
+
export const merge = (
|
|
879
|
+
backend,
|
|
880
|
+
root,
|
|
881
|
+
target,
|
|
882
|
+
message,
|
|
883
|
+
author,
|
|
884
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
885
|
+
) => (
|
|
886
|
+
toMergeResult(
|
|
887
|
+
unwrap(
|
|
888
|
+
"merge",
|
|
889
|
+
rawMerge(toHostId(backend), root, target, message, author, Math.trunc(timestampSec)),
|
|
890
|
+
),
|
|
891
|
+
)
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
export const checkout = (backend, root, target) => {
|
|
895
|
+
unwrap("checkout", rawCheckout(toHostId(backend), root, target));
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
export const checkoutB = (backend, root, branchName) => {
|
|
899
|
+
unwrap("checkoutB", rawCheckoutB(toHostId(backend), root, branchName));
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
export const switchBranch = (backend, root, name, options = {}) => {
|
|
903
|
+
unwrap(
|
|
904
|
+
"switchBranch",
|
|
905
|
+
rawSwitchBranch(
|
|
906
|
+
toHostId(backend),
|
|
907
|
+
root,
|
|
908
|
+
name,
|
|
909
|
+
Boolean(options.create),
|
|
910
|
+
options.checkoutFiles !== false,
|
|
911
|
+
),
|
|
912
|
+
);
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
export const restore = (backend, root, paths) => {
|
|
916
|
+
unwrap("restore", rawRestore(toHostId(backend), root, Array.from(paths)));
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
export const branchList = (backend, root) => (
|
|
920
|
+
Array.from(unwrap("branchList", rawBranchList(toHostId(backend), root))).map(toBranchInfo)
|
|
921
|
+
);
|
|
922
|
+
|
|
923
|
+
export const branchCreate = (backend, root, name) => {
|
|
924
|
+
unwrap("branchCreate", rawBranchCreate(toHostId(backend), root, name));
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
export const branchDelete = (backend, root, name) => {
|
|
928
|
+
unwrap("branchDelete", rawBranchDelete(toHostId(backend), root, name));
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
export const branchRename = (
|
|
932
|
+
backend,
|
|
933
|
+
root,
|
|
934
|
+
oldName,
|
|
935
|
+
newName,
|
|
936
|
+
options = {},
|
|
937
|
+
) => {
|
|
938
|
+
unwrap(
|
|
939
|
+
"branchRename",
|
|
940
|
+
rawBranchRename(
|
|
941
|
+
toHostId(backend),
|
|
942
|
+
root,
|
|
943
|
+
oldName,
|
|
944
|
+
newName,
|
|
945
|
+
Boolean(options.force),
|
|
946
|
+
options.author ?? "Unknown",
|
|
947
|
+
options.email ?? "unknown@localhost",
|
|
948
|
+
Math.trunc(options.timestampSec ?? 0),
|
|
949
|
+
options.timezone ?? "+0000",
|
|
950
|
+
),
|
|
951
|
+
);
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
export const tagList = (backend, root) => (
|
|
955
|
+
Array.from(unwrap("tagList", rawTagList(toHostId(backend), root)))
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
export const tagDelete = (backend, root, name) => {
|
|
959
|
+
unwrap("tagDelete", rawTagDelete(toHostId(backend), root, name));
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
export const tagCreateLightweight = (
|
|
963
|
+
backend,
|
|
964
|
+
root,
|
|
965
|
+
name,
|
|
966
|
+
target = "HEAD",
|
|
967
|
+
) => {
|
|
968
|
+
unwrap(
|
|
969
|
+
"tagCreateLightweight",
|
|
970
|
+
rawTagCreateLightweight(toHostId(backend), root, name, target),
|
|
971
|
+
);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
export const tagCreateAnnotated = (
|
|
975
|
+
backend,
|
|
976
|
+
root,
|
|
977
|
+
name,
|
|
978
|
+
target,
|
|
979
|
+
message,
|
|
980
|
+
tagger,
|
|
981
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
982
|
+
) => {
|
|
983
|
+
unwrap(
|
|
984
|
+
"tagCreateAnnotated",
|
|
985
|
+
rawTagCreateAnnotated(
|
|
986
|
+
toHostId(backend),
|
|
987
|
+
root,
|
|
988
|
+
name,
|
|
989
|
+
target,
|
|
990
|
+
message,
|
|
991
|
+
tagger,
|
|
992
|
+
Math.trunc(timestampSec),
|
|
993
|
+
),
|
|
994
|
+
);
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
export const rebaseStart = (backend, root, upstream) => (
|
|
998
|
+
toRebaseResult(unwrap("rebaseStart", rawRebaseStart(toHostId(backend), root, upstream)))
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
export const rebase = rebaseStart;
|
|
1002
|
+
|
|
1003
|
+
export const rebaseStartWithOnto = (backend, root, onto, upstream) => (
|
|
1004
|
+
toRebaseResult(
|
|
1005
|
+
unwrap(
|
|
1006
|
+
"rebaseStartWithOnto",
|
|
1007
|
+
rawRebaseStartWithOnto(toHostId(backend), root, onto, upstream),
|
|
1008
|
+
),
|
|
1009
|
+
)
|
|
1010
|
+
);
|
|
1011
|
+
|
|
1012
|
+
export const rebaseContinue = (backend, root) => (
|
|
1013
|
+
toRebaseResult(unwrap("rebaseContinue", rawRebaseContinue(toHostId(backend), root)))
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
export const rebaseAbort = (backend, root) => {
|
|
1017
|
+
unwrap("rebaseAbort", rawRebaseAbort(toHostId(backend), root));
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
export const rebaseSkip = (backend, root) => (
|
|
1021
|
+
toRebaseResult(unwrap("rebaseSkip", rawRebaseSkip(toHostId(backend), root)))
|
|
1022
|
+
);
|
|
1023
|
+
|
|
1024
|
+
export const reset = (backend, root, target, mode = "mixed") => (
|
|
1025
|
+
unwrap("reset", rawReset(toHostId(backend), root, target, mode))
|
|
1026
|
+
);
|
|
1027
|
+
|
|
1028
|
+
export const stashList = (backend, root) => (
|
|
1029
|
+
Array.from(unwrap("stashList", rawStashList(toHostId(backend), root))).map(toStashEntry)
|
|
1030
|
+
);
|
|
1031
|
+
|
|
1032
|
+
export const stashPush = async (
|
|
1033
|
+
backend,
|
|
1034
|
+
root,
|
|
1035
|
+
message,
|
|
1036
|
+
author,
|
|
1037
|
+
timestampSec = Math.floor(Date.now() / 1000),
|
|
1038
|
+
) => (
|
|
1039
|
+
toMaybeString(
|
|
1040
|
+
await unwrapAsync(
|
|
1041
|
+
"stashPush",
|
|
1042
|
+
rawStashPush,
|
|
1043
|
+
toHostId(backend),
|
|
1044
|
+
root,
|
|
1045
|
+
message,
|
|
1046
|
+
author,
|
|
1047
|
+
Math.trunc(timestampSec),
|
|
1048
|
+
),
|
|
1049
|
+
)
|
|
1050
|
+
);
|
|
1051
|
+
|
|
1052
|
+
export const stashApply = (backend, root, index = 0) => {
|
|
1053
|
+
unwrap("stashApply", rawStashApply(toHostId(backend), root, Math.trunc(index), false));
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
export const stashPop = (backend, root, index = 0) => {
|
|
1057
|
+
unwrap("stashPop", rawStashApply(toHostId(backend), root, Math.trunc(index), true));
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
export const stashDrop = (backend, root, index = 0) => {
|
|
1061
|
+
unwrap("stashDrop", rawStashDrop(toHostId(backend), root, Math.trunc(index)));
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
export const cherryPick = (
|
|
1065
|
+
backend,
|
|
1066
|
+
root,
|
|
1067
|
+
target,
|
|
1068
|
+
author,
|
|
1069
|
+
options = {},
|
|
1070
|
+
) => (
|
|
1071
|
+
toCherryPickResult(
|
|
1072
|
+
unwrap(
|
|
1073
|
+
"cherryPick",
|
|
1074
|
+
rawCherryPick(
|
|
1075
|
+
toHostId(backend),
|
|
1076
|
+
root,
|
|
1077
|
+
target,
|
|
1078
|
+
author,
|
|
1079
|
+
Math.trunc(options.timestampSec ?? Math.floor(Date.now() / 1000)),
|
|
1080
|
+
Boolean(options.noCommit),
|
|
1081
|
+
options.messageSuffix ?? "",
|
|
1082
|
+
options.signoffCommitter ?? "",
|
|
1083
|
+
),
|
|
1084
|
+
),
|
|
1085
|
+
)
|
|
1086
|
+
);
|
|
1087
|
+
|
|
1088
|
+
export const diffWorktree = async (backend, root) => (
|
|
1089
|
+
Array.from(
|
|
1090
|
+
await unwrapAsync("diffWorktree", rawDiffWorktree, toHostId(backend), root),
|
|
1091
|
+
)
|
|
1092
|
+
);
|
|
1093
|
+
|
|
1094
|
+
export const diffWorktreeStat = async (backend, root) => (
|
|
1095
|
+
Array.from(
|
|
1096
|
+
await unwrapAsync(
|
|
1097
|
+
"diffWorktreeStat",
|
|
1098
|
+
rawDiffWorktreeStat,
|
|
1099
|
+
toHostId(backend),
|
|
1100
|
+
root,
|
|
1101
|
+
),
|
|
1102
|
+
)
|
|
1103
|
+
);
|
|
1104
|
+
|
|
1105
|
+
export const diffIndex = (backend, root) => (
|
|
1106
|
+
Array.from(unwrap("diffIndex", rawDiffIndex(toHostId(backend), root)))
|
|
1107
|
+
);
|
|
1108
|
+
|
|
1109
|
+
export const diffIndexStat = (backend, root) => (
|
|
1110
|
+
Array.from(unwrap("diffIndexStat", rawDiffIndexStat(toHostId(backend), root)))
|
|
1111
|
+
);
|
|
1112
|
+
|
|
1113
|
+
export const listRemotes = (backend, root) => (
|
|
1114
|
+
Array.from(unwrap("listRemotes", rawListRemotes(toHostId(backend), root)))
|
|
1115
|
+
);
|
|
1116
|
+
|
|
1117
|
+
export const listRemotesVerbose = (backend, root) => (
|
|
1118
|
+
Array.from(unwrap("listRemotesVerbose", rawListRemotesVerbose(toHostId(backend), root)))
|
|
1119
|
+
.map(toRemoteVerboseEntry)
|
|
1120
|
+
);
|
|
1121
|
+
|
|
1122
|
+
export const getRemoteUrl = (backend, root, name) => (
|
|
1123
|
+
toMaybeString(unwrap("getRemoteUrl", rawGetRemoteUrl(toHostId(backend), root, name)))
|
|
1124
|
+
);
|
|
1125
|
+
|
|
1126
|
+
export const sparseCheckoutInit = (backend, root, cone = false) => {
|
|
1127
|
+
unwrap("sparseCheckoutInit", rawSparseCheckoutInit(toHostId(backend), root, Boolean(cone)));
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
export const sparseCheckoutSet = (backend, root, patterns) => {
|
|
1131
|
+
unwrap("sparseCheckoutSet", rawSparseCheckoutSet(toHostId(backend), root, Array.from(patterns)));
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
export const sparseCheckoutAdd = (backend, root, patterns) => {
|
|
1135
|
+
unwrap("sparseCheckoutAdd", rawSparseCheckoutAdd(toHostId(backend), root, Array.from(patterns)));
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
export const sparseCheckoutDisable = (backend, root) => {
|
|
1139
|
+
unwrap("sparseCheckoutDisable", rawSparseCheckoutDisable(toHostId(backend), root));
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
export const sparseCheckoutReapply = (backend, root) => {
|
|
1143
|
+
unwrap("sparseCheckoutReapply", rawSparseCheckoutReapply(toHostId(backend), root));
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
export const sparseCheckoutEnabled = (backend, root) => (
|
|
1147
|
+
Boolean(unwrap("sparseCheckoutEnabled", rawSparseCheckoutEnabled(toHostId(backend), root)))
|
|
1148
|
+
);
|
|
1149
|
+
|
|
1150
|
+
export const sparseCheckoutConeEnabled = (backend, root) => (
|
|
1151
|
+
Boolean(
|
|
1152
|
+
unwrap(
|
|
1153
|
+
"sparseCheckoutConeEnabled",
|
|
1154
|
+
rawSparseCheckoutConeEnabled(toHostId(backend), root),
|
|
1155
|
+
),
|
|
1156
|
+
)
|
|
1157
|
+
);
|
|
1158
|
+
|
|
1159
|
+
export const sparseCheckoutPatterns = (backend, root) => (
|
|
1160
|
+
Array.from(unwrap("sparseCheckoutPatterns", rawSparseCheckoutPatterns(toHostId(backend), root)))
|
|
1161
|
+
);
|
|
1162
|
+
|
|
1163
|
+
export const sparseCheckoutDisplayPatterns = (backend, root) => (
|
|
1164
|
+
Array.from(
|
|
1165
|
+
unwrap(
|
|
1166
|
+
"sparseCheckoutDisplayPatterns",
|
|
1167
|
+
rawSparseCheckoutDisplayPatterns(toHostId(backend), root),
|
|
1168
|
+
),
|
|
1169
|
+
)
|
|
1170
|
+
);
|
|
1171
|
+
|
|
1172
|
+
export const fetch = async (
|
|
1173
|
+
backend,
|
|
1174
|
+
root,
|
|
1175
|
+
remoteUrl,
|
|
1176
|
+
transport,
|
|
1177
|
+
options = {},
|
|
1178
|
+
) => {
|
|
1179
|
+
const resolvedRemoteUrl = relayUsesSignaling(remoteUrl)
|
|
1180
|
+
? (await relayResolveRemote(remoteUrl, transport, {
|
|
1181
|
+
preferredSender: options.preferredSender ?? null,
|
|
1182
|
+
preferredRepo: options.preferredRepo ?? null,
|
|
1183
|
+
authToken: options.authToken ?? null,
|
|
1184
|
+
})).url
|
|
1185
|
+
: remoteUrl;
|
|
1186
|
+
return toFetchResult(
|
|
1187
|
+
await unwrapAsync(
|
|
1188
|
+
"fetch",
|
|
1189
|
+
rawFetch,
|
|
1190
|
+
toHostId(backend),
|
|
1191
|
+
root,
|
|
1192
|
+
resolvedRemoteUrl,
|
|
1193
|
+
toTransportId(transport),
|
|
1194
|
+
options.refspec ?? "",
|
|
1195
|
+
options.preferV2 !== false,
|
|
1196
|
+
options.depth ?? 0,
|
|
1197
|
+
),
|
|
1198
|
+
);
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
export const clone = async (
|
|
1202
|
+
backend,
|
|
1203
|
+
root,
|
|
1204
|
+
remoteUrl,
|
|
1205
|
+
transport,
|
|
1206
|
+
options = {},
|
|
1207
|
+
) => {
|
|
1208
|
+
const resolvedRemoteUrl = relayUsesSignaling(remoteUrl)
|
|
1209
|
+
? (await relayResolveRemote(remoteUrl, transport, {
|
|
1210
|
+
preferredSender: options.preferredSender ?? null,
|
|
1211
|
+
preferredRepo: options.preferredRepo ?? null,
|
|
1212
|
+
authToken: options.authToken ?? null,
|
|
1213
|
+
})).url
|
|
1214
|
+
: remoteUrl;
|
|
1215
|
+
return toCloneResult(
|
|
1216
|
+
await unwrapAsync(
|
|
1217
|
+
"clone",
|
|
1218
|
+
rawClone,
|
|
1219
|
+
toHostId(backend),
|
|
1220
|
+
root,
|
|
1221
|
+
resolvedRemoteUrl,
|
|
1222
|
+
toTransportId(transport),
|
|
1223
|
+
options.preferV2 !== false,
|
|
1224
|
+
options.depth ?? 0,
|
|
1225
|
+
),
|
|
1226
|
+
);
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
export const push = async (
|
|
1230
|
+
backend,
|
|
1231
|
+
root,
|
|
1232
|
+
remoteUrl,
|
|
1233
|
+
transport,
|
|
1234
|
+
options = {},
|
|
1235
|
+
) => {
|
|
1236
|
+
const resolvedRemoteUrl = relayUsesSignaling(remoteUrl)
|
|
1237
|
+
? (await relayResolveRemote(remoteUrl, transport, {
|
|
1238
|
+
preferredSender: options.preferredSender ?? null,
|
|
1239
|
+
preferredRepo: options.preferredRepo ?? null,
|
|
1240
|
+
authToken: options.authToken ?? null,
|
|
1241
|
+
})).url
|
|
1242
|
+
: remoteUrl;
|
|
1243
|
+
return unwrapAsync(
|
|
1244
|
+
"push",
|
|
1245
|
+
rawPush,
|
|
1246
|
+
toHostId(backend),
|
|
1247
|
+
root,
|
|
1248
|
+
resolvedRemoteUrl,
|
|
1249
|
+
toTransportId(transport),
|
|
1250
|
+
options.refname ?? "",
|
|
1251
|
+
Boolean(options.force),
|
|
1252
|
+
);
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
export const rm = (backend, root, paths, options = {}) => {
|
|
1256
|
+
unwrap("rm", rawRm(toHostId(backend), root, Array.from(paths), Boolean(options.cached)));
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
export const mv = (backend, root, source, dest) => {
|
|
1260
|
+
unwrap("mv", rawMv(toHostId(backend), root, source, dest));
|
|
1261
|
+
};
|