@statewalker/vcs-commands 0.1.1 → 0.3.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.
Files changed (86) hide show
  1. package/README.md +180 -466
  2. package/dist/commands/commit-command.d.ts.map +1 -1
  3. package/dist/commands/init-command.d.ts.map +1 -1
  4. package/dist/commands/push-command.d.ts.map +1 -1
  5. package/dist/core-commands/checkout.command.impl.d.ts +1 -1
  6. package/dist/core-commands/checkout.command.impl.d.ts.map +1 -1
  7. package/dist/git-command.d.ts.map +1 -1
  8. package/package.json +25 -16
  9. package/src/commands/add-command.ts +494 -0
  10. package/src/commands/blame-command.ts +1241 -0
  11. package/src/commands/branch-command.ts +487 -0
  12. package/src/commands/checkout-command.ts +681 -0
  13. package/src/commands/cherry-pick-command.ts +544 -0
  14. package/src/commands/clean-command.ts +218 -0
  15. package/src/commands/clone-command.ts +532 -0
  16. package/src/commands/commit-command.ts +529 -0
  17. package/src/commands/describe-command.ts +454 -0
  18. package/src/commands/diff-command.ts +257 -0
  19. package/src/commands/fetch-command.ts +615 -0
  20. package/src/commands/gc-command.ts +155 -0
  21. package/src/commands/index.ts +31 -0
  22. package/src/commands/init-command.ts +365 -0
  23. package/src/commands/log-command.ts +549 -0
  24. package/src/commands/ls-remote-command.ts +237 -0
  25. package/src/commands/merge-command.ts +750 -0
  26. package/src/commands/pack-refs-command.ts +101 -0
  27. package/src/commands/pull-command.ts +258 -0
  28. package/src/commands/push-command.ts +682 -0
  29. package/src/commands/rebase-command.ts +665 -0
  30. package/src/commands/reflog-command.ts +68 -0
  31. package/src/commands/remote-command.ts +385 -0
  32. package/src/commands/reset-command.ts +292 -0
  33. package/src/commands/revert-command.ts +552 -0
  34. package/src/commands/rm-command.ts +178 -0
  35. package/src/commands/stash-apply-command.ts +402 -0
  36. package/src/commands/stash-create-command.ts +339 -0
  37. package/src/commands/stash-drop-command.ts +115 -0
  38. package/src/commands/stash-list-command.ts +116 -0
  39. package/src/commands/status-command.ts +173 -0
  40. package/src/commands/tag-command.ts +378 -0
  41. package/src/commands/tree-restore.ts +126 -0
  42. package/src/core-commands/add.command.impl.ts +274 -0
  43. package/src/core-commands/add.command.ts +81 -0
  44. package/src/core-commands/checkout.command.impl.ts +586 -0
  45. package/src/core-commands/checkout.command.ts +125 -0
  46. package/src/core-commands/index.ts +13 -0
  47. package/src/errors/add-errors.ts +20 -0
  48. package/src/errors/checkout-errors.ts +42 -0
  49. package/src/errors/command-errors.ts +68 -0
  50. package/src/errors/commit-errors.ts +40 -0
  51. package/src/errors/git-api-error.ts +11 -0
  52. package/src/errors/index.ts +12 -0
  53. package/src/errors/merge-errors.ts +94 -0
  54. package/src/errors/rebase-errors.ts +34 -0
  55. package/src/errors/ref-errors.ts +100 -0
  56. package/src/errors/remote-errors.ts +27 -0
  57. package/src/errors/stash-errors.ts +42 -0
  58. package/src/errors/tag-errors.ts +16 -0
  59. package/src/errors/transport-errors.ts +68 -0
  60. package/src/git-command.ts +421 -0
  61. package/src/git.ts +910 -0
  62. package/src/index.ts +18 -0
  63. package/src/pack-import/index.ts +8 -0
  64. package/src/pack-import/pack-import.ts +24 -0
  65. package/src/remote-config/index.ts +12 -0
  66. package/src/remote-config/remote-config-store.ts +285 -0
  67. package/src/rename/index.ts +5 -0
  68. package/src/rename/similarity-index.ts +185 -0
  69. package/src/results/cherry-pick-result.ts +35 -0
  70. package/src/results/clone-result.ts +25 -0
  71. package/src/results/diff-entry.ts +162 -0
  72. package/src/results/diff-formatter.ts +416 -0
  73. package/src/results/fetch-result.ts +91 -0
  74. package/src/results/index.ts +13 -0
  75. package/src/results/init-result.ts +29 -0
  76. package/src/results/merge-result.ts +135 -0
  77. package/src/results/pull-result.ts +27 -0
  78. package/src/results/push-result.ts +86 -0
  79. package/src/results/rebase-result.ts +140 -0
  80. package/src/results/revert-result.ts +35 -0
  81. package/src/results/stash-result.ts +60 -0
  82. package/src/results/status-result.ts +65 -0
  83. package/src/transport-command.ts +125 -0
  84. package/src/tree-merge/index.ts +8 -0
  85. package/src/tree-merge/tree-merge.ts +249 -0
  86. package/src/types.ts +70 -0
@@ -0,0 +1,615 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+ // Import from the package root only: vcs-core ships a single runtime file
3
+ // (dist/index.js); its subpaths resolve for types but not at runtime.
4
+ import { isSymbolicRef } from "@statewalker/vcs-core";
5
+ import {
6
+ expandFromSource,
7
+ matchSource,
8
+ parseRefSpec,
9
+ type RefSpec,
10
+ fetch as transportFetch,
11
+ } from "@statewalker/vcs-transport";
12
+
13
+ import { InvalidArgumentError, InvalidRemoteError } from "../errors/index.js";
14
+ import { importPackIntoHistory } from "../pack-import/index.js";
15
+ import { RemoteConfigStore } from "../remote-config/index.js";
16
+ import {
17
+ type FetchResult,
18
+ RefUpdateStatus,
19
+ type TrackingRefUpdate,
20
+ } from "../results/fetch-result.js";
21
+ import { TransportCommand } from "../transport-command.js";
22
+
23
+ /**
24
+ * Tag fetching option.
25
+ *
26
+ * Based on JGit's TagOpt.
27
+ */
28
+ export enum TagOption {
29
+ /** Automatically follow tags that point to fetched commits */
30
+ AUTO_FOLLOW = "auto-follow",
31
+ /** Fetch all tags */
32
+ FETCH_TAGS = "fetch-tags",
33
+ /** Don't fetch any tags */
34
+ NO_TAGS = "no-tags",
35
+ }
36
+
37
+ /**
38
+ * Fetch objects and refs from a remote repository.
39
+ *
40
+ * Equivalent to `git fetch`.
41
+ *
42
+ * Based on JGit's FetchCommand.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // Fetch from default remote
47
+ * const result = await git.fetch().call();
48
+ *
49
+ * // Fetch from specific remote
50
+ * const result = await git.fetch()
51
+ * .setRemote("upstream")
52
+ * .call();
53
+ *
54
+ * // Fetch specific refs
55
+ * const result = await git.fetch()
56
+ * .setRefSpecs("refs/heads/main:refs/remotes/origin/main")
57
+ * .call();
58
+ *
59
+ * // Shallow fetch
60
+ * const result = await git.fetch()
61
+ * .setDepth(10)
62
+ * .call();
63
+ *
64
+ * // Fetch with authentication
65
+ * const result = await git.fetch()
66
+ * .setCredentialsProvider("user", "token")
67
+ * .call();
68
+ * ```
69
+ */
70
+ export class FetchCommand extends TransportCommand<FetchResult> {
71
+ private remote = "origin";
72
+ private refSpecs: string[] = [];
73
+ private removeDeletedRefs = false;
74
+ // biome-ignore lint/correctness/noUnusedPrivateClassMembers: Set by setTagOpt(), to be used in call()
75
+ private tagOption: TagOption = TagOption.AUTO_FOLLOW;
76
+ private thin = true;
77
+ private depth?: number;
78
+ private dryRun = false;
79
+ private forceUpdate = false;
80
+ private checkFetchedObjects = false;
81
+ private initialBranch?: string;
82
+ private shallowSince?: Date;
83
+ private shallowExcludes: string[] = [];
84
+ private unshallow = false;
85
+
86
+ /**
87
+ * Set the remote to fetch from.
88
+ *
89
+ * Can be either a remote name (e.g., "origin") or a URL.
90
+ * Default is "origin".
91
+ *
92
+ * @param remote Remote name or URL
93
+ */
94
+ setRemote(remote: string): this {
95
+ this.checkCallable();
96
+ this.remote = remote;
97
+ return this;
98
+ }
99
+
100
+ /**
101
+ * Get the remote being fetched from.
102
+ */
103
+ getRemote(): string {
104
+ return this.remote;
105
+ }
106
+
107
+ /**
108
+ * Set refspecs to fetch.
109
+ *
110
+ * If not set, uses the default refspec for the remote.
111
+ *
112
+ * @param refSpecs Refspec strings
113
+ */
114
+ setRefSpecs(...refSpecs: string[]): this {
115
+ this.checkCallable();
116
+ this.refSpecs = refSpecs;
117
+ return this;
118
+ }
119
+
120
+ /**
121
+ * Add a refspec to fetch.
122
+ *
123
+ * @param refSpec Refspec string
124
+ */
125
+ addRefSpec(refSpec: string): this {
126
+ this.checkCallable();
127
+ this.refSpecs.push(refSpec);
128
+ return this;
129
+ }
130
+
131
+ /**
132
+ * Set whether to remove refs that no longer exist on the remote.
133
+ *
134
+ * Equivalent to `git fetch --prune`.
135
+ *
136
+ * @param remove Whether to prune deleted refs
137
+ */
138
+ setRemoveDeletedRefs(remove: boolean): this {
139
+ this.checkCallable();
140
+ this.removeDeletedRefs = remove;
141
+ return this;
142
+ }
143
+
144
+ /**
145
+ * Whether to remove deleted refs.
146
+ */
147
+ isRemoveDeletedRefs(): boolean {
148
+ return this.removeDeletedRefs;
149
+ }
150
+
151
+ setTagOpt(option: TagOption): this {
152
+ this.checkCallable();
153
+ this.tagOption = option;
154
+ return this;
155
+ }
156
+
157
+ /**
158
+ * Set thin-pack preference.
159
+ *
160
+ * @param thin Whether to use thin packs
161
+ */
162
+ setThin(thin: boolean): this {
163
+ this.checkCallable();
164
+ this.thin = thin;
165
+ return this;
166
+ }
167
+
168
+ /**
169
+ * Whether thin packs are enabled.
170
+ */
171
+ isThin(): boolean {
172
+ return this.thin;
173
+ }
174
+
175
+ /**
176
+ * Set shallow clone depth.
177
+ *
178
+ * @param depth Number of commits to fetch
179
+ */
180
+ setDepth(depth: number): this {
181
+ this.checkCallable();
182
+ if (depth < 1) {
183
+ throw new InvalidArgumentError("depth", depth, "Depth must be at least 1");
184
+ }
185
+ this.depth = depth;
186
+ return this;
187
+ }
188
+
189
+ /**
190
+ * Set dry run mode.
191
+ *
192
+ * In dry run mode, refs are not actually updated.
193
+ *
194
+ * @param dryRun Whether to do a dry run
195
+ */
196
+ setDryRun(dryRun: boolean): this {
197
+ this.checkCallable();
198
+ this.dryRun = dryRun;
199
+ return this;
200
+ }
201
+
202
+ /**
203
+ * Whether dry run mode is enabled.
204
+ */
205
+ isDryRun(): boolean {
206
+ return this.dryRun;
207
+ }
208
+
209
+ /**
210
+ * Set force update mode.
211
+ *
212
+ * When enabled, allows non-fast-forward updates.
213
+ *
214
+ * @param force Whether to force updates
215
+ */
216
+ setForceUpdate(force: boolean): this {
217
+ this.checkCallable();
218
+ this.forceUpdate = force;
219
+ return this;
220
+ }
221
+
222
+ /**
223
+ * Whether force update mode is enabled.
224
+ */
225
+ isForceUpdate(): boolean {
226
+ return this.forceUpdate;
227
+ }
228
+
229
+ /**
230
+ * Set whether to check received objects for validity.
231
+ *
232
+ * If true, objects received will be verified.
233
+ *
234
+ * @param check Whether to check objects
235
+ */
236
+ setCheckFetchedObjects(check: boolean): this {
237
+ this.checkCallable();
238
+ this.checkFetchedObjects = check;
239
+ return this;
240
+ }
241
+
242
+ /**
243
+ * Whether to check received objects for validity.
244
+ */
245
+ isCheckFetchedObjects(): boolean {
246
+ return this.checkFetchedObjects;
247
+ }
248
+
249
+ /**
250
+ * Set the initial branch to check out.
251
+ *
252
+ * Can be specified as ref name (refs/heads/main), branch name (main),
253
+ * or tag name (v1.0.0).
254
+ *
255
+ * @param branch Initial branch name
256
+ */
257
+ setInitialBranch(branch: string): this {
258
+ this.checkCallable();
259
+ this.initialBranch = branch;
260
+ return this;
261
+ }
262
+
263
+ /**
264
+ * Get the initial branch.
265
+ */
266
+ getInitialBranch(): string | undefined {
267
+ return this.initialBranch;
268
+ }
269
+
270
+ /**
271
+ * Deepens or shortens the history of a shallow repository to include
272
+ * all reachable commits after a specified time.
273
+ *
274
+ * Equivalent to `git fetch --shallow-since=<date>`.
275
+ *
276
+ * @param shallowSince The timestamp
277
+ */
278
+ setShallowSince(shallowSince: Date): this {
279
+ this.checkCallable();
280
+ this.shallowSince = shallowSince;
281
+ return this;
282
+ }
283
+
284
+ /**
285
+ * Get the shallow-since date.
286
+ */
287
+ getShallowSince(): Date | undefined {
288
+ return this.shallowSince;
289
+ }
290
+
291
+ /**
292
+ * Deepens or shortens the history of a shallow repository to exclude
293
+ * commits reachable from a specified remote branch or tag.
294
+ *
295
+ * Equivalent to `git fetch --shallow-exclude=<ref>`.
296
+ *
297
+ * @param shallowExclude The ref or commit to exclude
298
+ */
299
+ addShallowExclude(shallowExclude: string): this {
300
+ this.checkCallable();
301
+ this.shallowExcludes.push(shallowExclude);
302
+ return this;
303
+ }
304
+
305
+ /**
306
+ * Get the shallow excludes.
307
+ */
308
+ getShallowExcludes(): string[] {
309
+ return [...this.shallowExcludes];
310
+ }
311
+
312
+ /**
313
+ * If the source repository is complete, converts a shallow repository
314
+ * to a complete one, removing all the limitations imposed by shallow
315
+ * repositories.
316
+ *
317
+ * Equivalent to `git fetch --unshallow`.
318
+ *
319
+ * @param unshallow Whether to unshallow
320
+ */
321
+ setUnshallow(unshallow: boolean): this {
322
+ this.checkCallable();
323
+ this.unshallow = unshallow;
324
+ return this;
325
+ }
326
+
327
+ /**
328
+ * Whether unshallow mode is enabled.
329
+ */
330
+ isUnshallow(): boolean {
331
+ return this.unshallow;
332
+ }
333
+
334
+ /**
335
+ * Execute the fetch operation.
336
+ *
337
+ * @returns Fetch result with updated refs
338
+ * @throws InvalidRemoteError if remote cannot be resolved
339
+ */
340
+ async call(): Promise<FetchResult> {
341
+ this.checkCallable();
342
+ this.setCallable(false);
343
+
344
+ // Resolve remote URL
345
+ const remoteUrl = await this.resolveRemoteUrl(this.remote);
346
+ if (!remoteUrl) {
347
+ throw new InvalidRemoteError(this.remote);
348
+ }
349
+
350
+ // Parse refspecs for source→destination mapping
351
+ const parsedSpecs = this.effectiveRefSpecs().map((s) => parseRefSpec(s));
352
+
353
+ // Save old ref values before fetch for status computation
354
+ const oldRefValues = new Map<string, string | undefined>();
355
+ for await (const ref of this.refsStore.list()) {
356
+ if (!isSymbolicRef(ref) && ref.objectId) {
357
+ oldRefValues.set(ref.name, ref.objectId);
358
+ }
359
+ }
360
+
361
+ // Execute fetch using high-level fetch API
362
+ const transportResult = await transportFetch({
363
+ url: remoteUrl,
364
+ auth: this.credentials,
365
+ headers: this.headers,
366
+ timeout: this.timeout,
367
+ depth: this.depth,
368
+ onProgressMessage: this.progressMessageCallback,
369
+ });
370
+
371
+ // Convert refs from Uint8Array to hex strings
372
+ const bytesToHex = (bytes: Uint8Array): string =>
373
+ Array.from(bytes)
374
+ .map((b) => b.toString(16).padStart(2, "0"))
375
+ .join("");
376
+
377
+ const advertisedRefs = new Map<string, ObjectId>();
378
+ for (const [refName, objectId] of transportResult.refs) {
379
+ advertisedRefs.set(refName, bytesToHex(objectId));
380
+ }
381
+
382
+ // Build tracking ref updates by mapping server refs through refspecs
383
+ const trackingUpdates: TrackingRefUpdate[] = [];
384
+ for (const [serverRefName, objectIdBytes] of transportResult.refs) {
385
+ const objectId = bytesToHex(objectIdBytes);
386
+
387
+ // Map server ref name to local ref name via refspecs
388
+ const localRefName = this.mapServerRef(serverRefName, parsedSpecs);
389
+ if (!localRefName) continue;
390
+
391
+ const isForce = this.forceUpdate || this.isRefSpecForced(serverRefName, parsedSpecs);
392
+ const update = await this.computeRefUpdate(
393
+ localRefName,
394
+ serverRefName,
395
+ objectId,
396
+ oldRefValues,
397
+ isForce,
398
+ );
399
+
400
+ // Write the mapped ref to local store (unless dry-run)
401
+ if (!this.dryRun) {
402
+ await this.refsStore.set(localRefName, objectId);
403
+ }
404
+
405
+ trackingUpdates.push(update);
406
+ }
407
+
408
+ // Handle prune
409
+ if (!this.dryRun && this.removeDeletedRefs) {
410
+ const pruned = await this.pruneDeletedRefs(transportResult.refs);
411
+ trackingUpdates.push(...pruned);
412
+ }
413
+
414
+ // Store pack data
415
+ if (transportResult.packData.length > 0 && !this.dryRun) {
416
+ await this.storePack(transportResult.packData);
417
+ }
418
+
419
+ return {
420
+ uri: remoteUrl,
421
+ advertisedRefs,
422
+ trackingRefUpdates: trackingUpdates,
423
+ defaultBranch: transportResult.defaultBranch,
424
+ bytesReceived: transportResult.bytesReceived,
425
+ isEmpty: transportResult.isEmpty,
426
+ messages: [],
427
+ };
428
+ }
429
+
430
+ /**
431
+ * Map a server ref name to a local ref name using parsed refspecs.
432
+ * Returns undefined if no refspec matches.
433
+ */
434
+ private mapServerRef(serverRef: string, specs: RefSpec[]): string | undefined {
435
+ for (const spec of specs) {
436
+ if (spec.negative) continue;
437
+ if (!spec.source || !spec.destination) continue;
438
+ if (!matchSource(spec, serverRef)) continue;
439
+
440
+ const expanded = expandFromSource(spec, serverRef);
441
+ return expanded.destination ?? undefined;
442
+ }
443
+ return undefined;
444
+ }
445
+
446
+ /**
447
+ * Check if any matching refspec has the force flag for a given server ref.
448
+ */
449
+ private isRefSpecForced(serverRef: string, specs: RefSpec[]): boolean {
450
+ for (const spec of specs) {
451
+ if (spec.negative) continue;
452
+ if (!spec.source) continue;
453
+ if (matchSource(spec, serverRef) && spec.force) return true;
454
+ }
455
+ return false;
456
+ }
457
+
458
+ /**
459
+ * The refspecs this fetch runs with.
460
+ *
461
+ * Explicit refspecs win; otherwise a configured remote contributes its
462
+ * `remote.<name>.fetch` lines, which is what makes `fetch().setRemote("origin")`
463
+ * update tracking refs without being told how. A remote given as a bare URL
464
+ * has no config and so still needs its refspecs spelled out.
465
+ */
466
+ private effectiveRefSpecs(): string[] {
467
+ if (this.refSpecs.length > 0) return this.refSpecs;
468
+ const store = RemoteConfigStore.from(this.workingCopy);
469
+ return store.isConfigured(this.remote) ? store.read(this.remote).fetchRefspecs : [];
470
+ }
471
+
472
+ /**
473
+ * Resolve remote name to URL.
474
+ *
475
+ * A named remote resolves through `remote.<name>.url` in the working copy
476
+ * configuration. An unconfigured name is passed through unchanged, so a URL
477
+ * given straight to {@link setRemote} still works.
478
+ */
479
+ private async resolveRemoteUrl(remote: string): Promise<string | undefined> {
480
+ // If it looks like a URL, use it directly
481
+ if (remote.includes("://") || remote.includes("@")) {
482
+ return remote;
483
+ }
484
+
485
+ return RemoteConfigStore.from(this.workingCopy).urlFor(remote) ?? remote;
486
+ }
487
+
488
+ /**
489
+ * Compute ref update status using pre-fetch ref values.
490
+ *
491
+ * Uses saved pre-fetch values to correctly determine
492
+ * NEW vs NO_CHANGE vs FAST_FORWARD status.
493
+ */
494
+ private async computeRefUpdate(
495
+ localRef: string,
496
+ remoteRef: string,
497
+ newObjectId: ObjectId,
498
+ oldRefValues: Map<string, string | undefined>,
499
+ force: boolean,
500
+ ): Promise<TrackingRefUpdate> {
501
+ const oldObjectId = oldRefValues.get(localRef);
502
+
503
+ let status: RefUpdateStatus;
504
+ if (!oldObjectId) {
505
+ status = RefUpdateStatus.NEW;
506
+ } else if (oldObjectId === newObjectId) {
507
+ status = RefUpdateStatus.NO_CHANGE;
508
+ } else if (force) {
509
+ status = RefUpdateStatus.FORCED;
510
+ } else {
511
+ // Check if fast-forward
512
+ const isAncestor = await this.isAncestor(oldObjectId, newObjectId);
513
+ status = isAncestor ? RefUpdateStatus.FAST_FORWARD : RefUpdateStatus.REJECTED;
514
+ }
515
+
516
+ return {
517
+ localRef,
518
+ remoteRef,
519
+ oldObjectId,
520
+ newObjectId,
521
+ status,
522
+ };
523
+ }
524
+
525
+ /**
526
+ * Check if one commit is an ancestor of another.
527
+ */
528
+ private async isAncestor(ancestor: ObjectId, descendant: ObjectId): Promise<boolean> {
529
+ // Walk from descendant back to see if we hit ancestor
530
+ const visited = new Set<ObjectId>();
531
+ const queue: ObjectId[] = [descendant];
532
+
533
+ while (queue.length > 0) {
534
+ const current = queue.shift();
535
+ if (current === undefined) break;
536
+ if (current === ancestor) {
537
+ return true;
538
+ }
539
+ if (visited.has(current)) {
540
+ continue;
541
+ }
542
+ visited.add(current);
543
+
544
+ try {
545
+ const commit = await this.commits.load(current);
546
+ if (commit) {
547
+ queue.push(...commit.parents);
548
+ }
549
+ } catch {
550
+ // Commit not found, skip
551
+ }
552
+
553
+ // Limit walk depth for performance
554
+ if (visited.size > 10000) {
555
+ break;
556
+ }
557
+ }
558
+
559
+ return false;
560
+ }
561
+
562
+ /**
563
+ * Prune refs that no longer exist on remote.
564
+ */
565
+ private async pruneDeletedRefs(
566
+ remoteRefs: Map<string, Uint8Array>,
567
+ ): Promise<TrackingRefUpdate[]> {
568
+ const updates: TrackingRefUpdate[] = [];
569
+ const prefix = `refs/remotes/${this.remote}/`;
570
+
571
+ // Get remote ref names for comparison
572
+ const remoteRefNames = new Set<string>();
573
+ for (const refName of remoteRefs.keys()) {
574
+ remoteRefNames.add(refName);
575
+ }
576
+
577
+ // Find local tracking refs that don't exist on remote
578
+ for await (const ref of this.refsStore.list(prefix)) {
579
+ // Skip symbolic refs
580
+ if (isSymbolicRef(ref)) {
581
+ continue;
582
+ }
583
+
584
+ // Derive remote ref name
585
+ const localName = ref.name.slice(prefix.length);
586
+ const remoteRefName = `refs/heads/${localName}`;
587
+
588
+ if (!remoteRefNames.has(ref.name) && !remoteRefNames.has(remoteRefName)) {
589
+ // Delete the local tracking ref
590
+ await this.refsStore.delete(ref.name);
591
+ updates.push({
592
+ localRef: ref.name,
593
+ remoteRef: remoteRefName,
594
+ oldObjectId: ref.objectId,
595
+ newObjectId: "", // Empty indicates deletion
596
+ status: RefUpdateStatus.DELETED,
597
+ });
598
+ }
599
+ }
600
+
601
+ return updates;
602
+ }
603
+
604
+ /**
605
+ * Store received pack data.
606
+ *
607
+ * Unpacks the pack into the working copy's history, so the objects the
608
+ * freshly written tracking refs point at are actually available locally.
609
+ * Import is idempotent: the stores are content-addressed, so re-importing
610
+ * a pack rewrites the same object IDs.
611
+ */
612
+ private async storePack(packData: Uint8Array): Promise<void> {
613
+ await importPackIntoHistory(this._workingCopy.history, packData);
614
+ }
615
+ }