@catamorphic/git 0.1.0-alpha.42 → 0.1.0-alpha.44

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.
Files changed (66) hide show
  1. package/dist/checkout-remote-backend.d.ts.map +1 -1
  2. package/dist/fs-backend.d.ts +8 -0
  3. package/dist/fs-backend.d.ts.map +1 -1
  4. package/dist/fs-remote-backend.d.ts +43 -9
  5. package/dist/fs-remote-backend.d.ts.map +1 -1
  6. package/dist/git-objects.d.ts +77 -0
  7. package/dist/git-objects.d.ts.map +1 -0
  8. package/dist/git-sync.d.ts +16 -17
  9. package/dist/git-sync.d.ts.map +1 -1
  10. package/dist/index.d.ts +6 -5
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3912 -3059
  13. package/dist/index.js.map +23 -21
  14. package/dist/native-git.d.ts +114 -2
  15. package/dist/native-git.d.ts.map +1 -1
  16. package/dist/native-project-repo.d.ts +40 -5
  17. package/dist/native-project-repo.d.ts.map +1 -1
  18. package/dist/network-sync.d.ts.map +1 -1
  19. package/dist/network.d.ts +14 -9
  20. package/dist/network.d.ts.map +1 -1
  21. package/dist/object-origin-cache.d.ts +86 -0
  22. package/dist/object-origin-cache.d.ts.map +1 -0
  23. package/dist/object-remote-backend.d.ts +64 -10
  24. package/dist/object-remote-backend.d.ts.map +1 -1
  25. package/dist/origin-draft.d.ts.map +1 -1
  26. package/dist/origin-objects.d.ts +7 -2
  27. package/dist/origin-objects.d.ts.map +1 -1
  28. package/dist/project-manager.d.ts +22 -0
  29. package/dist/project-manager.d.ts.map +1 -1
  30. package/dist/project-paths.d.ts +20 -0
  31. package/dist/project-paths.d.ts.map +1 -0
  32. package/dist/ref-names.d.ts +35 -0
  33. package/dist/ref-names.d.ts.map +1 -1
  34. package/dist/types.d.ts +37 -4
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/workspace-checkout.d.ts +31 -0
  37. package/dist/workspace-checkout.d.ts.map +1 -0
  38. package/dist/workspace-mirror.d.ts +38 -5
  39. package/dist/workspace-mirror.d.ts.map +1 -1
  40. package/dist/workspace-save.d.ts +27 -2
  41. package/dist/workspace-save.d.ts.map +1 -1
  42. package/package.json +4 -4
  43. package/src/checkout-remote-backend.ts +77 -29
  44. package/src/fs-backend.ts +69 -7
  45. package/src/fs-remote-backend.ts +255 -133
  46. package/src/git-objects.ts +363 -0
  47. package/src/git-sync.ts +124 -453
  48. package/src/index.ts +17 -7
  49. package/src/native-git.ts +566 -25
  50. package/src/native-project-repo.ts +318 -99
  51. package/src/network-sync.ts +43 -35
  52. package/src/network.ts +177 -153
  53. package/src/object-origin-cache.ts +689 -0
  54. package/src/object-remote-backend.ts +277 -20
  55. package/src/origin-draft.ts +22 -15
  56. package/src/origin-objects.ts +21 -5
  57. package/src/project-manager.ts +261 -73
  58. package/src/project-paths.ts +142 -0
  59. package/src/ref-names.ts +56 -0
  60. package/src/types.ts +38 -4
  61. package/src/workspace-checkout.ts +192 -0
  62. package/src/workspace-mirror.ts +276 -68
  63. package/src/workspace-save.ts +99 -30
  64. package/dist/project-repo.d.ts +0 -81
  65. package/dist/project-repo.d.ts.map +0 -1
  66. package/src/project-repo.ts +0 -821
package/src/git-sync.ts CHANGED
@@ -1,33 +1,18 @@
1
- import nodeFs from "node:fs";
1
+ import { getTracer, withSpan } from "@catamorphic/otel";
2
2
  import { publishedRef } from "@catamorphic/workflow/project-layout";
3
- import git from "isomorphic-git";
4
3
  import { nativeGit } from "./native-git.js";
5
- import { NativeProjectRepo } from "./native-project-repo.js";
6
- import { mapLimit } from "./origin-objects.js";
7
- import type {
8
- ConflictEntry,
9
- MergeResult,
10
- OriginRepo,
11
- ProjectRepo,
12
- RemoteBackend,
13
- } from "./types.js";
4
+ import type { ProjectRepo, RemoteBackend } from "./types.js";
5
+
6
+ const tracer = getTracer("@catamorphic/git");
14
7
 
15
8
  /**
16
- * Server-orchestrated git transport between a dev `ProjectRepo` (working tree)
17
- * and an `OriginRepo` (bare repo). This module implements **object-level
18
- * transfer** — walking reachable commits/trees/blobs and copying them between
19
- * the two stores — so we never need a network git protocol between sandboxes.
20
- *
21
- * All operations assume the dev repo is an FS-backed `ProjectRepoImpl`. When
22
- * we later wire in Cloudflare dev sandboxes, this module will grow a thin
23
- * adapter, but the transfer algorithm stays the same.
9
+ * Server-orchestrated Git transport between a repository on this machine's
10
+ * disk (a checkout, a session's copy) and a project's origin (ADR 0356).
11
+ * Histories move as packs, built and read by the Git program: only what
12
+ * the receiving side lacks travels, and nothing here walks a history or
13
+ * holds its objects in memory.
24
14
  */
25
15
 
26
- const SYSTEM_AUTHOR = {
27
- name: "Work",
28
- email: "system@work.software",
29
- };
30
-
31
16
  export interface PushOpts {
32
17
  dev: ProjectRepo;
33
18
  remote: Pick<RemoteBackend, "withOrigin">;
@@ -52,76 +37,85 @@ export interface FetchOpts {
52
37
  tenantId: string;
53
38
  projectId: string;
54
39
  remoteBranch?: string;
55
- }
56
-
57
- export interface PullOpts extends FetchOpts {
58
- /** Author for the merge commit (if one is needed). */
59
- author?: { name: string; email: string };
40
+ /**
41
+ * `dev` is a copy Work manages on this machine: an origin that keeps its
42
+ * objects here lends them to it instead of copying them.
43
+ */
44
+ borrow?: boolean;
60
45
  }
61
46
 
62
47
  /**
63
- * Copy reachable commits from dev → origin and fast-forward the remote branch.
48
+ * Publish a commit of the dev repository as a branch of the origin: the
49
+ * origin takes what it lacks, then the branch moves by compare-and-swap.
64
50
  * Throws if the push would not be a fast-forward (caller should pull first).
65
51
  */
66
52
  export async function push(opts: PushOpts): Promise<{ sha: string }> {
67
53
  const branch = opts.remoteBranch ?? "main";
68
54
  const localSha = opts.localSha ?? (await opts.dev.resolveRef("HEAD"));
69
55
 
70
- return opts.remote.withOrigin(
71
- opts.tenantId,
72
- opts.projectId,
73
- async (origin) => {
74
- const ref = `refs/heads/${branch}`;
75
- const currentRemote = await origin.resolveRef(ref);
56
+ return withSpan(
57
+ {
58
+ tracer,
59
+ name: "git.publish",
60
+ attributes: {
61
+ "catamorphic.tenant.id": opts.tenantId,
62
+ "catamorphic.project.id": opts.projectId,
63
+ "catamorphic.git.branch": branch,
64
+ },
65
+ },
66
+ () =>
67
+ opts.remote.withOrigin(opts.tenantId, opts.projectId, async (origin) => {
68
+ const ref = `refs/heads/${branch}`;
69
+ const currentRemote = await origin.resolveRef(ref);
76
70
 
77
- if (currentRemote === localSha) {
78
- return { sha: localSha };
79
- }
71
+ if (currentRemote === localSha) {
72
+ return { sha: localSha };
73
+ }
80
74
 
81
- if (opts.expected !== undefined && currentRemote !== opts.expected)
82
- throw new Error(
83
- "The workspace checkpoint changed before it could be published.",
84
- );
75
+ if (opts.expected !== undefined && currentRemote !== opts.expected)
76
+ throw new Error(
77
+ "The workspace checkpoint changed before it could be published.",
78
+ );
85
79
 
86
- if (currentRemote && !opts.force) {
87
- const fastForward = await isAncestor({
88
- dev: opts.dev,
89
- ancestor: currentRemote,
90
- descendant: localSha,
91
- });
92
- if (!fastForward) {
93
- throw new PushNotFastForwardError({
94
- localSha,
95
- remoteSha: currentRemote,
80
+ if (currentRemote && !opts.force) {
81
+ const fastForward = await isAncestor({
82
+ repoPath: opts.dev.repoPath,
83
+ ancestor: currentRemote,
84
+ descendant: localSha,
96
85
  });
86
+ if (!fastForward) {
87
+ throw new PushNotFastForwardError({
88
+ localSha,
89
+ remoteSha: currentRemote,
90
+ });
91
+ }
97
92
  }
98
- }
99
93
 
100
- await transferCommits({
101
- source: devSource(opts.dev),
102
- sink: originSink(origin),
103
- sha: localSha,
104
- });
94
+ await origin.receive({
95
+ repoPath: opts.dev.repoPath,
96
+ commit: localSha,
97
+ ref,
98
+ });
105
99
 
106
- await origin.updateRef({
107
- ref,
108
- sha: localSha,
109
- expected: currentRemote,
110
- });
100
+ await origin.updateRef({
101
+ ref,
102
+ sha: localSha,
103
+ expected: currentRemote,
104
+ });
111
105
 
112
- await syncRemoteTrackingRef({
113
- dev: opts.dev,
114
- branch,
115
- sha: localSha,
116
- });
106
+ await syncRemoteTrackingRef({
107
+ repoPath: opts.dev.repoPath,
108
+ branch,
109
+ sha: localSha,
110
+ });
117
111
 
118
- return { sha: localSha };
119
- },
112
+ return { sha: localSha };
113
+ }),
120
114
  );
121
115
  }
122
116
 
123
117
  /**
124
- * Copy the tip of the remote branch into the dev repo and update the
118
+ * Make the tip of the remote branch readable in the dev repo and update the
125
119
  * `refs/work/published/<branch>` tracking ref. Does not touch the working tree.
126
120
  */
127
121
  export async function fetchRemote(opts: FetchOpts): Promise<{
@@ -130,125 +124,45 @@ export async function fetchRemote(opts: FetchOpts): Promise<{
130
124
  }> {
131
125
  const branch = opts.remoteBranch ?? "main";
132
126
 
133
- return opts.remote.withOrigin(
134
- opts.tenantId,
135
- opts.projectId,
136
- async (origin) => {
137
- const ref = `refs/heads/${branch}`;
138
- const remoteSha = await origin.resolveRef(ref);
139
- if (!remoteSha) return { sha: null, alreadyUpToDate: true };
127
+ return withSpan(
128
+ {
129
+ tracer,
130
+ name: "git.fetch",
131
+ attributes: {
132
+ "catamorphic.tenant.id": opts.tenantId,
133
+ "catamorphic.project.id": opts.projectId,
134
+ "catamorphic.git.branch": branch,
135
+ },
136
+ },
137
+ () =>
138
+ opts.remote.withOrigin(opts.tenantId, opts.projectId, async (origin) => {
139
+ const ref = `refs/heads/${branch}`;
140
+ const remoteSha = await origin.resolveRef(ref);
141
+ if (!remoteSha) return { sha: null, alreadyUpToDate: true };
142
+
143
+ const alreadyUpToDate = await hasCommit({
144
+ repoPath: opts.dev.repoPath,
145
+ sha: remoteSha,
146
+ });
140
147
 
141
- const alreadyUpToDate = await devHasCommit({
142
- dev: opts.dev,
143
- sha: remoteSha,
144
- });
148
+ if (!alreadyUpToDate)
149
+ await origin.send({
150
+ repoPath: opts.dev.repoPath,
151
+ commit: remoteSha,
152
+ ...(opts.borrow ? { borrow: true } : {}),
153
+ });
145
154
 
146
- if (!alreadyUpToDate) {
147
- await transferCommits({
148
- source: originSource(origin),
149
- sink: devSink(opts.dev),
155
+ await syncRemoteTrackingRef({
156
+ repoPath: opts.dev.repoPath,
157
+ branch,
150
158
  sha: remoteSha,
151
159
  });
152
- }
153
-
154
- await syncRemoteTrackingRef({
155
- dev: opts.dev,
156
- branch,
157
- sha: remoteSha,
158
- });
159
160
 
160
- return { sha: remoteSha, alreadyUpToDate };
161
- },
161
+ return { sha: remoteSha, alreadyUpToDate };
162
+ }),
162
163
  );
163
164
  }
164
165
 
165
- /**
166
- * Fetch the remote branch, then merge it into the current branch. Uses a
167
- * 3-way merge via isomorphic-git. Returns conflicts when the merge cannot be
168
- * resolved automatically; working tree is left with conflict markers in that
169
- * case so the caller can surface them or invoke the AI resolver.
170
- */
171
- export async function pull(opts: PullOpts): Promise<MergeResult> {
172
- const branch = opts.remoteBranch ?? "main";
173
- const author = opts.author ?? SYSTEM_AUTHOR;
174
-
175
- const fetched = await fetchRemote(opts);
176
- if (!fetched.sha) {
177
- return {
178
- status: "up-to-date",
179
- mergeCommit: null,
180
- conflicts: [],
181
- };
182
- }
183
-
184
- const localSha = await opts.dev.resolveRef("HEAD");
185
- if (localSha === fetched.sha) {
186
- return {
187
- status: "up-to-date",
188
- mergeCommit: null,
189
- conflicts: [],
190
- };
191
- }
192
-
193
- const localIsAhead = await isAncestor({
194
- dev: opts.dev,
195
- ancestor: fetched.sha,
196
- descendant: localSha,
197
- });
198
- if (localIsAhead) {
199
- return {
200
- status: "up-to-date",
201
- mergeCommit: null,
202
- conflicts: [],
203
- };
204
- }
205
-
206
- const currentBranch = await opts.dev.currentBranch();
207
-
208
- try {
209
- const result = await git.merge({
210
- fs: nodeFs,
211
- dir: opts.dev.repoPath,
212
- ours: currentBranch,
213
- theirs: fetched.sha,
214
- author,
215
- committer: author,
216
- fastForward: true,
217
- abortOnConflict: false,
218
- message: `Merge origin/${branch} into ${currentBranch}`,
219
- });
220
-
221
- await git.checkout({
222
- fs: nodeFs,
223
- dir: opts.dev.repoPath,
224
- ref: currentBranch,
225
- force: true,
226
- });
227
-
228
- return {
229
- status: "clean",
230
- mergeCommit: result.oid ?? null,
231
- conflicts: [],
232
- };
233
- } catch (err: unknown) {
234
- const maybeConflict = err as { code?: string; data?: unknown };
235
- if (maybeConflict?.code === "MergeConflictError") {
236
- const conflicts = await collectConflicts({
237
- dev: opts.dev,
238
- oursSha: localSha,
239
- theirsSha: fetched.sha,
240
- raw: maybeConflict.data,
241
- });
242
- return {
243
- status: "conflict",
244
- mergeCommit: null,
245
- conflicts,
246
- };
247
- }
248
- throw err;
249
- }
250
- }
251
-
252
166
  export class PushNotFastForwardError extends Error {
253
167
  readonly localSha: string;
254
168
  readonly remoteSha: string;
@@ -262,285 +176,42 @@ export class PushNotFastForwardError extends Error {
262
176
  }
263
177
  }
264
178
 
265
- // --- Object transfer primitives ---
266
-
267
- interface ObjectSource {
268
- hasObject(sha: string): Promise<boolean>;
269
- readObject(sha: string): Promise<{
270
- type: "blob" | "tree" | "commit" | "tag";
271
- data: Uint8Array;
272
- }>;
273
- }
274
-
275
- interface ObjectSink {
276
- hasObject(sha: string): Promise<boolean>;
277
- writeObject(opts: {
278
- type: "blob" | "tree" | "commit" | "tag";
279
- data: Uint8Array;
280
- }): Promise<string>;
281
- }
282
-
283
- function devSource(dev: ProjectRepo): ObjectSource {
284
- const cache = {};
285
- return {
286
- hasObject: (sha) =>
287
- git
288
- .readObject({ fs: nodeFs, dir: dev.repoPath, oid: sha, cache })
289
- .then(() => true)
290
- .catch(() => false),
291
- readObject: async (sha) => {
292
- const obj = await git.readObject({
293
- fs: nodeFs,
294
- dir: dev.repoPath,
295
- oid: sha,
296
- cache,
297
- format: "content",
298
- });
299
- return {
300
- type: obj.type as "blob" | "tree" | "commit" | "tag",
301
- data: obj.object as Uint8Array,
302
- };
303
- },
304
- };
305
- }
306
-
307
- function devSink(dev: ProjectRepo): ObjectSink {
308
- const cache = {};
309
- return {
310
- hasObject: (sha) =>
311
- git
312
- .readObject({ fs: nodeFs, dir: dev.repoPath, oid: sha, cache })
313
- .then(() => true)
314
- .catch(() => false),
315
- writeObject: (opts) =>
316
- git.writeObject({
317
- fs: nodeFs,
318
- dir: dev.repoPath,
319
- type: opts.type,
320
- object: opts.data,
321
- format: "content",
322
- }),
323
- };
324
- }
325
-
326
- function originSource(origin: OriginRepo): ObjectSource {
327
- return {
328
- hasObject: (sha) => origin.hasObject(sha),
329
- readObject: (sha) => origin.readObject(sha),
330
- };
331
- }
332
-
333
- function originSink(origin: OriginRepo): ObjectSink {
334
- return {
335
- hasObject: (sha) => origin.hasObject(sha),
336
- writeObject: (opts) => origin.writeObject(opts),
337
- };
338
- }
339
-
340
- async function transferCommits(opts: {
341
- source: ObjectSource;
342
- sink: ObjectSink;
343
- sha: string;
344
- }): Promise<void> {
345
- // Breadth first, a batch of objects at a time: seeding a checkout from a
346
- // network origin is bound by round trips, not by the objects' size.
347
- let frontier: string[] = [opts.sha];
348
- const seen = new Set<string>();
349
- while (frontier.length > 0) {
350
- const batch = [...new Set(frontier)].filter((sha) => !seen.has(sha));
351
- for (const sha of batch) seen.add(sha);
352
- const next = await mapLimit(batch, TRANSFER_CONCURRENCY, async (sha) => {
353
- if (await opts.sink.hasObject(sha)) return [];
354
- const obj = await opts.source.readObject(sha);
355
- await opts.sink.writeObject(obj);
356
- if (obj.type === "commit") {
357
- const commit = parseCommit(obj.data);
358
- return [commit.tree, ...commit.parents];
359
- }
360
- if (obj.type === "tree")
361
- return parseTree(obj.data)
362
- .filter((entry) => entry.mode !== "160000")
363
- .map((entry) => entry.oid);
364
- return [];
365
- });
366
- frontier = next.flat();
367
- }
368
- }
369
-
370
- const TRANSFER_CONCURRENCY = 16;
371
-
372
- interface ParsedCommit {
373
- tree: string;
374
- parents: string[];
375
- }
376
-
377
- function parseCommit(data: Uint8Array): ParsedCommit {
378
- const text = new TextDecoder("utf-8").decode(data);
379
- const headerEnd = text.indexOf("\n\n");
380
- const header = headerEnd === -1 ? text : text.slice(0, headerEnd);
381
- const parents: string[] = [];
382
- let tree = "";
383
- for (const line of header.split("\n")) {
384
- if (line.startsWith("tree ")) tree = line.slice(5).trim();
385
- else if (line.startsWith("parent ")) parents.push(line.slice(7).trim());
386
- }
387
- return { tree, parents };
388
- }
389
-
390
- interface TreeEntry {
391
- mode: string;
392
- name: string;
393
- oid: string;
394
- }
395
-
396
- function parseTree(data: Uint8Array): TreeEntry[] {
397
- const entries: TreeEntry[] = [];
398
- let i = 0;
399
- while (i < data.length) {
400
- let spaceIdx = i;
401
- while (spaceIdx < data.length && data[spaceIdx] !== 0x20) spaceIdx++;
402
- const mode = new TextDecoder("utf-8").decode(data.slice(i, spaceIdx));
403
-
404
- let nullIdx = spaceIdx + 1;
405
- while (nullIdx < data.length && data[nullIdx] !== 0x00) nullIdx++;
406
- const name = new TextDecoder("utf-8").decode(
407
- data.slice(spaceIdx + 1, nullIdx),
408
- );
409
-
410
- const oidBytes = data.slice(nullIdx + 1, nullIdx + 21);
411
- const oid = Array.from(oidBytes)
412
- .map((b) => b.toString(16).padStart(2, "0"))
413
- .join("");
414
-
415
- entries.push({ mode, name, oid });
416
- i = nullIdx + 21;
417
- }
418
- return entries;
419
- }
420
-
421
- // --- Ancestor check ---
422
-
423
- async function isAncestor(opts: {
424
- dev: ProjectRepo;
179
+ function isAncestor(opts: {
180
+ repoPath: string;
425
181
  ancestor: string;
426
182
  descendant: string;
427
183
  }): Promise<boolean> {
428
- if (opts.ancestor === opts.descendant) return true;
429
- if (opts.dev instanceof NativeProjectRepo)
430
- return nativeGit(opts.dev.repoPath, [
431
- "merge-base",
432
- "--is-ancestor",
433
- opts.ancestor,
434
- opts.descendant,
435
- ]).then(
436
- () => true,
437
- () => false,
438
- );
439
- try {
440
- const commits = await git.log({
441
- fs: nodeFs,
442
- dir: opts.dev.repoPath,
443
- ref: opts.descendant,
444
- depth: -1,
445
- });
446
- return commits.some((c) => c.oid === opts.ancestor);
447
- } catch {
448
- return false;
449
- }
184
+ if (opts.ancestor === opts.descendant) return Promise.resolve(true);
185
+ return nativeGit(opts.repoPath, [
186
+ "merge-base",
187
+ "--is-ancestor",
188
+ opts.ancestor,
189
+ opts.descendant,
190
+ ]).then(
191
+ () => true,
192
+ () => false,
193
+ );
450
194
  }
451
195
 
452
- async function devHasCommit(opts: {
453
- dev: ProjectRepo;
454
- sha: string;
455
- }): Promise<boolean> {
456
- if (opts.dev instanceof NativeProjectRepo)
457
- return nativeGit(opts.dev.repoPath, ["cat-file", "-e", opts.sha]).then(
458
- () => true,
459
- () => false,
460
- );
461
- try {
462
- await git.readObject({
463
- fs: nodeFs,
464
- dir: opts.dev.repoPath,
465
- oid: opts.sha,
466
- });
467
- return true;
468
- } catch {
469
- return false;
470
- }
196
+ function hasCommit(opts: { repoPath: string; sha: string }): Promise<boolean> {
197
+ return nativeGit(opts.repoPath, [
198
+ "cat-file",
199
+ "-e",
200
+ `${opts.sha}^{commit}`,
201
+ ]).then(
202
+ () => true,
203
+ () => false,
204
+ );
471
205
  }
472
206
 
473
207
  async function syncRemoteTrackingRef(opts: {
474
- dev: ProjectRepo;
208
+ repoPath: string;
475
209
  branch: string;
476
210
  sha: string;
477
211
  }): Promise<void> {
478
- if (opts.dev instanceof NativeProjectRepo) {
479
- await nativeGit(opts.dev.repoPath, [
480
- "update-ref",
481
- publishedRef(opts.branch),
482
- opts.sha,
483
- ]);
484
- return;
485
- }
486
- await git.writeRef({
487
- fs: nodeFs,
488
- dir: opts.dev.repoPath,
489
- ref: publishedRef(opts.branch),
490
- value: opts.sha,
491
- force: true,
492
- });
493
- }
494
-
495
- async function collectConflicts(opts: {
496
- dev: ProjectRepo;
497
- oursSha: string;
498
- theirsSha: string;
499
- raw: unknown;
500
- }): Promise<ConflictEntry[]> {
501
- const raw = opts.raw as { filepaths?: string[] } | undefined;
502
- const paths = raw?.filepaths ?? [];
503
- const result: ConflictEntry[] = [];
504
-
505
- for (const filepath of paths) {
506
- const ours = await readAtRef(opts.dev.repoPath, opts.oursSha, filepath);
507
- const theirs = await readAtRef(opts.dev.repoPath, opts.theirsSha, filepath);
508
- const baseSha = await git
509
- .findMergeBase({
510
- fs: nodeFs,
511
- dir: opts.dev.repoPath,
512
- oids: [opts.oursSha, opts.theirsSha],
513
- })
514
- .then((bases) => bases[0] ?? null)
515
- .catch(() => null);
516
- const base = baseSha
517
- ? await readAtRef(opts.dev.repoPath, baseSha, filepath)
518
- : null;
519
-
520
- result.push({
521
- path: filepath,
522
- base,
523
- ours,
524
- theirs,
525
- });
526
- }
527
- return result;
528
- }
529
-
530
- async function readAtRef(
531
- dir: string,
532
- oid: string,
533
- filepath: string,
534
- ): Promise<string | null> {
535
- try {
536
- const { blob } = await git.readBlob({
537
- fs: nodeFs,
538
- dir,
539
- oid,
540
- filepath,
541
- });
542
- return new TextDecoder("utf-8").decode(blob);
543
- } catch {
544
- return null;
545
- }
212
+ await nativeGit(opts.repoPath, [
213
+ "update-ref",
214
+ publishedRef(opts.branch),
215
+ opts.sha,
216
+ ]);
546
217
  }