@statewalker/vcs-commands 0.3.1 → 0.4.0

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 (77) hide show
  1. package/README.md +193 -460
  2. package/dist/commands/add-command.d.ts +0 -6
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/blame-command.d.ts +14 -0
  5. package/dist/commands/blame-command.d.ts.map +1 -1
  6. package/dist/commands/branch-command.d.ts.map +1 -1
  7. package/dist/commands/checkout-command.d.ts.map +1 -1
  8. package/dist/commands/clean-command.d.ts.map +1 -1
  9. package/dist/commands/clone-command.d.ts +0 -15
  10. package/dist/commands/clone-command.d.ts.map +1 -1
  11. package/dist/commands/fetch-command.d.ts +16 -31
  12. package/dist/commands/fetch-command.d.ts.map +1 -1
  13. package/dist/commands/index.js +2 -2
  14. package/dist/commands/init-command.d.ts.map +1 -1
  15. package/dist/commands/merge-command.d.ts +15 -2
  16. package/dist/commands/merge-command.d.ts.map +1 -1
  17. package/dist/commands/push-command.d.ts +58 -25
  18. package/dist/commands/push-command.d.ts.map +1 -1
  19. package/dist/commands/stash-create-command.d.ts +1 -1
  20. package/dist/commands/stash-drop-command.d.ts +1 -1
  21. package/dist/commands/stash-list-command.d.ts +1 -1
  22. package/dist/commands/tag-command.d.ts.map +1 -1
  23. package/dist/commands/tree-restore.d.ts.map +1 -1
  24. package/dist/{commands-COO4tJhv.js → commands-BpeXZTC3.js} +473 -469
  25. package/dist/core-commands/add.command.impl.d.ts +0 -4
  26. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  27. package/dist/core-commands/checkout.command.impl.d.ts +2 -6
  28. package/dist/core-commands/checkout.command.impl.d.ts.map +1 -1
  29. package/dist/core-commands/index.d.ts +1 -0
  30. package/dist/core-commands/index.d.ts.map +1 -1
  31. package/dist/core-commands/store-worktree-file.d.ts +6 -0
  32. package/dist/core-commands/store-worktree-file.d.ts.map +1 -0
  33. package/dist/index.js +3 -3
  34. package/dist/remote-config/remote-config-store.d.ts +4 -0
  35. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  36. package/dist/results/diff-formatter.d.ts +14 -7
  37. package/dist/results/diff-formatter.d.ts.map +1 -1
  38. package/dist/results/fetch-result.d.ts +7 -0
  39. package/dist/results/fetch-result.d.ts.map +1 -1
  40. package/dist/results/index.js +27 -22
  41. package/dist/results/push-result.d.ts +9 -2
  42. package/dist/results/push-result.d.ts.map +1 -1
  43. package/dist/{status-result-BwAyxq6R.js → status-result-BapZoQaR.js} +2 -0
  44. package/package.json +19 -14
  45. package/src/commands/add-command.ts +16 -25
  46. package/src/commands/blame-command.ts +41 -0
  47. package/src/commands/branch-command.ts +2 -53
  48. package/src/commands/checkout-command.ts +7 -11
  49. package/src/commands/clean-command.ts +7 -0
  50. package/src/commands/clone-command.ts +102 -109
  51. package/src/commands/fetch-command.ts +103 -197
  52. package/src/commands/gc-command.ts +1 -1
  53. package/src/commands/init-command.ts +83 -11
  54. package/src/commands/merge-command.ts +60 -27
  55. package/src/commands/pack-refs-command.ts +2 -2
  56. package/src/commands/push-command.ts +242 -308
  57. package/src/commands/reflog-command.ts +2 -2
  58. package/src/commands/stash-apply-command.ts +1 -1
  59. package/src/commands/stash-create-command.ts +1 -1
  60. package/src/commands/stash-drop-command.ts +1 -1
  61. package/src/commands/stash-list-command.ts +1 -1
  62. package/src/commands/tag-command.ts +2 -53
  63. package/src/commands/tree-restore.ts +2 -6
  64. package/src/core-commands/add.command.impl.ts +16 -19
  65. package/src/core-commands/checkout.command.impl.ts +18 -40
  66. package/src/core-commands/index.ts +1 -0
  67. package/src/core-commands/store-worktree-file.ts +5 -0
  68. package/src/remote-config/remote-config-store.ts +11 -0
  69. package/src/results/diff-formatter.ts +31 -38
  70. package/src/results/fetch-result.ts +7 -0
  71. package/src/results/push-result.ts +9 -2
  72. package/dist/pack-import/index.d.ts +0 -8
  73. package/dist/pack-import/index.d.ts.map +0 -1
  74. package/dist/pack-import/pack-import.d.ts +0 -11
  75. package/dist/pack-import/pack-import.d.ts.map +0 -1
  76. package/src/pack-import/index.ts +0 -8
  77. package/src/pack-import/pack-import.ts +0 -24
@@ -381,7 +381,7 @@ export class StashApplyCommand extends GitCommand<StashApplyResult> {
381
381
  }
382
382
 
383
383
  // For other indices, need reflog support
384
- // Note: The core RefStore interface doesn't include reflog methods.
384
+ // Note: The core Refs interface doesn't include reflog methods.
385
385
  // Without reflog, we can only access the most recent stash (index 0).
386
386
  throw new RefNotFoundError(refName, `Stash entry ${index} not found (reflog not supported)`);
387
387
  }
@@ -329,7 +329,7 @@ export class StashCreateCommand extends GitCommand<ObjectId | undefined> {
329
329
  /**
330
330
  * Update the stash ref.
331
331
  *
332
- * Note: Reflog support is not part of the core RefStore interface.
332
+ * Note: Reflog support is not part of the core Refs interface.
333
333
  * Stash history is tracked via parent commit chain instead.
334
334
  */
335
335
  private async updateStashRef(ref: string, commitId: ObjectId, _message: string): Promise<void> {
@@ -11,7 +11,7 @@ import { STASH_REF } from "./stash-list-command.js";
11
11
  *
12
12
  * Based on JGit's StashDropCommand.
13
13
  *
14
- * Note: Without reflog support in RefStore, only the most recent stash (index 0)
14
+ * Note: Without reflog support in Refs, only the most recent stash (index 0)
15
15
  * can be dropped. Dropping by index > 0 requires reflog support.
16
16
  *
17
17
  * @example
@@ -59,7 +59,7 @@ export class StashListCommand extends GitCommand<StashEntry[]> {
59
59
  /**
60
60
  * Get stash entries.
61
61
  *
62
- * Note: Without reflog support in the core RefStore interface,
62
+ * Note: Without reflog support in the core Refs interface,
63
63
  * this returns only the most recent stash (if any).
64
64
  */
65
65
  private async getStashReflog(): Promise<Array<{ commitId: ObjectId; message: string }>> {
@@ -1,5 +1,5 @@
1
1
  import type { AnnotatedTag, ObjectId, PersonIdent, Ref } from "@statewalker/vcs-core";
2
- import { ObjectType } from "@statewalker/vcs-core";
2
+ import { compareRefNames, isValidTagName, ObjectType } from "@statewalker/vcs-core";
3
3
 
4
4
  import {
5
5
  InvalidTagNameError,
@@ -23,57 +23,6 @@ function getTimezoneOffset(): string {
23
23
  return `${sign}${hours}${minutes}`;
24
24
  }
25
25
 
26
- /**
27
- * Validate a tag name according to Git rules.
28
- *
29
- * @param name Tag name to validate
30
- * @returns true if valid
31
- */
32
- function isValidTagName(name: string): boolean {
33
- // Cannot be empty
34
- if (!name || name.length === 0) {
35
- return false;
36
- }
37
-
38
- // Cannot start or end with /
39
- if (name.startsWith("/") || name.endsWith("/")) {
40
- return false;
41
- }
42
-
43
- // Cannot contain ..
44
- if (name.includes("..")) {
45
- return false;
46
- }
47
-
48
- // Cannot contain special characters (control chars, space, ~^:?*[\)
49
- // biome-ignore lint/suspicious/noControlCharactersInRegex: Git ref validation requires checking for control characters
50
- if (/[\x00-\x1f\x7f ~^:?*[\\]/.test(name)) {
51
- return false;
52
- }
53
-
54
- // Cannot end with .lock
55
- if (name.endsWith(".lock")) {
56
- return false;
57
- }
58
-
59
- // Cannot start with -
60
- if (name.startsWith("-")) {
61
- return false;
62
- }
63
-
64
- // Cannot be @
65
- if (name === "@") {
66
- return false;
67
- }
68
-
69
- // Cannot contain @{
70
- if (name.includes("@{")) {
71
- return false;
72
- }
73
-
74
- return true;
75
- }
76
-
77
26
  /**
78
27
  * Create a tag (lightweight or annotated).
79
28
  *
@@ -371,7 +320,7 @@ export class ListTagCommand extends GitCommand<Ref[]> {
371
320
  }
372
321
 
373
322
  // Sort by name
374
- tags.sort((a, b) => a.name.localeCompare(b.name));
323
+ tags.sort((a, b) => compareRefNames(a.name, b.name));
375
324
 
376
325
  return tags;
377
326
  }
@@ -116,11 +116,7 @@ export async function writeTreeRestorePlan(
116
116
  throw new Error(`${operation} cannot restore ${path}: blob ${objectId} is missing`);
117
117
  }
118
118
 
119
- const chunks: Uint8Array[] = [];
120
- for await (const chunk of content) {
121
- chunks.push(chunk);
122
- }
123
-
124
- await worktree.writeContent(path, chunks, { mode, createParents: true });
119
+ // the blob streams into the file; it is never held whole in memory
120
+ await worktree.writeContent(path, content, { mode, createParents: true });
125
121
  }
126
122
  }
@@ -9,7 +9,7 @@
9
9
  * Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
10
10
  */
11
11
 
12
- import { type Blobs, FileMode } from "@statewalker/vcs-core";
12
+ import { type Blobs, EMPTY_BLOB_ID, FileMode } from "@statewalker/vcs-core";
13
13
  import {
14
14
  DeleteStagingEntry,
15
15
  type Staging,
@@ -17,6 +17,7 @@ import {
17
17
  type Worktree,
18
18
  } from "@statewalker/vcs-working-tree";
19
19
  import type { Add, AddOptions, AddResult } from "./add.command.js";
20
+ import { storeWorktreeFile } from "./store-worktree-file.js";
20
21
 
21
22
  /**
22
23
  * Options for creating an AddCommand.
@@ -205,10 +206,15 @@ export class AddCommand implements Add {
205
206
  const worktreeEntry = await this.worktree.getEntry(file.path);
206
207
  const mode = worktreeEntry?.mode ?? FileMode.REGULAR_FILE;
207
208
  editor.add(
208
- new UpdateStagingEntry(file.path, "", mode, {
209
- size: 0,
210
- mtime: Date.now(),
211
- }),
209
+ // the empty blob's id, flagged intent-to-add, as git records it (never an empty
210
+ // or all-zero id, which a worktree hash could be compared against)
211
+ new UpdateStagingEntry(
212
+ file.path,
213
+ EMPTY_BLOB_ID,
214
+ mode,
215
+ { size: 0, mtime: Date.now() },
216
+ { intentToAdd: true },
217
+ ),
212
218
  );
213
219
  added.push(file.path);
214
220
  continue;
@@ -222,13 +228,14 @@ export class AddCommand implements Add {
222
228
  }
223
229
 
224
230
  // Hash and store content
225
- const objectId = await this.storeFileContent(file.path);
231
+ // the stat that matched the stored content (a fresh one after a retry)
232
+ const stored = await storeWorktreeFile(this.blobs, this.worktree, file.path, worktreeEntry);
226
233
 
227
234
  // Add to staging
228
235
  editor.add(
229
- new UpdateStagingEntry(file.path, objectId, worktreeEntry.mode, {
230
- size: worktreeEntry.size,
231
- mtime: worktreeEntry.mtime,
236
+ new UpdateStagingEntry(file.path, stored.id, stored.entry.mode, {
237
+ size: stored.entry.size,
238
+ mtime: stored.entry.mtime,
232
239
  }),
233
240
  );
234
241
  added.push(file.path);
@@ -251,16 +258,6 @@ export class AddCommand implements Add {
251
258
  async addAll(options: AddOptions = {}): Promise<AddResult> {
252
259
  return this.add(["**/*"], { ...options, all: true });
253
260
  }
254
-
255
- /**
256
- * Store file content as blob and return object ID.
257
- */
258
- private async storeFileContent(path: string): Promise<string> {
259
- // Read content from working tree
260
- const content = this.worktree.readContent(path);
261
- // Store using BlobStore which handles Git header automatically
262
- return await this.blobs.store(content);
263
- }
264
261
  }
265
262
 
266
263
  /**
@@ -11,17 +11,20 @@
11
11
  */
12
12
 
13
13
  import {
14
+ assertValidWorktreePath,
14
15
  type Blobs,
15
16
  type Commits,
16
17
  FileMode,
17
18
  type FilesApi,
19
+ isValidBranchName,
18
20
  joinPath,
19
21
  type ObjectId,
20
- type RefStore,
22
+ type Refs,
21
23
  type TreeEntry,
22
24
  type Trees,
23
25
  } from "@statewalker/vcs-core";
24
26
  import type { Staging } from "@statewalker/vcs-working-tree";
27
+ import { InvalidRefNameError } from "../errors/index.js";
25
28
  import type { Checkout, CheckoutOptions, CheckoutResult } from "./checkout.command.js";
26
29
 
27
30
  /**
@@ -52,7 +55,7 @@ export interface CheckoutCommandOptions {
52
55
  commits: Commits;
53
56
 
54
57
  /** Reference storage for resolving refs and updating HEAD */
55
- refs: RefStore;
58
+ refs: Refs;
56
59
 
57
60
  /** Staging area (index) for updating after checkout */
58
61
  staging: Staging;
@@ -67,7 +70,7 @@ export class CheckoutCommand implements Checkout {
67
70
  private readonly blobs: Blobs;
68
71
  private readonly trees: Trees;
69
72
  private readonly commits: Commits;
70
- private readonly refs: RefStore;
73
+ private readonly refs: Refs;
71
74
  private readonly staging: Staging;
72
75
 
73
76
  constructor(options: CheckoutCommandOptions) {
@@ -84,6 +87,9 @@ export class CheckoutCommand implements Checkout {
84
87
  * Checkout a branch, tag, or commit.
85
88
  */
86
89
  async checkout(target: string, options: CheckoutOptions = {}): Promise<CheckoutResult> {
90
+ if (options.createBranch !== undefined && !isValidBranchName(options.createBranch)) {
91
+ throw new InvalidRefNameError(options.createBranch);
92
+ }
87
93
  // Resolve target to commit
88
94
  const commitId = await this.resolveTarget(target);
89
95
  if (!commitId) {
@@ -292,6 +298,8 @@ export class CheckoutCommand implements Checkout {
292
298
  * Write file content to working tree.
293
299
  */
294
300
  private async writeFileContent(path: string, objectId: ObjectId, _mode: number): Promise<void> {
301
+ // Tree and index paths may come from a crafted repository: never write into `.git`.
302
+ assertValidWorktreePath(path);
295
303
  const absolutePath = joinPath(this.workTreeRoot, path);
296
304
 
297
305
  // Ensure parent directory exists
@@ -301,33 +309,22 @@ export class CheckoutCommand implements Checkout {
301
309
  await this.files.mkdir(parentDir);
302
310
  }
303
311
 
304
- // Load and write content
305
- const content = await this.loadBlobContent(objectId);
306
- await this.files.write(absolutePath, [content]);
312
+ // Stream the blob straight into the file
313
+ const content = await this.blobs.load(objectId);
314
+ if (!content) {
315
+ throw new Error(`Blob ${objectId} not found`);
316
+ }
317
+ await this.files.write(absolutePath, content);
307
318
 
308
319
  // Note: FilesApi doesn't support chmod, so executable bit is not set
309
320
  // This could be extended with FilesApiAdapter if needed
310
321
  }
311
322
 
312
- /**
313
- * Load blob content as Uint8Array.
314
- */
315
- private async loadBlobContent(objectId: ObjectId): Promise<Uint8Array> {
316
- const result = await this.blobs.load(objectId);
317
- if (!result) {
318
- throw new Error(`Blob ${objectId} not found`);
319
- }
320
- const chunks: Uint8Array[] = [];
321
- for await (const chunk of result) {
322
- chunks.push(chunk);
323
- }
324
- return concatBytes(chunks);
325
- }
326
-
327
323
  /**
328
324
  * Remove file from working tree.
329
325
  */
330
326
  private async removeFile(path: string): Promise<void> {
327
+ assertValidWorktreePath(path);
331
328
  const absolutePath = joinPath(this.workTreeRoot, path);
332
329
  await this.files.remove(absolutePath);
333
330
 
@@ -556,25 +553,6 @@ export class CheckoutCommand implements Checkout {
556
553
  }
557
554
  }
558
555
 
559
- /**
560
- * Concatenate Uint8Arrays.
561
- */
562
- function concatBytes(arrays: Uint8Array[]): Uint8Array {
563
- if (arrays.length === 0) return new Uint8Array(0);
564
- if (arrays.length === 1) return arrays[0];
565
-
566
- const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
567
- const result = new Uint8Array(totalLength);
568
- let offset = 0;
569
-
570
- for (const arr of arrays) {
571
- result.set(arr, offset);
572
- offset += arr.length;
573
- }
574
-
575
- return result;
576
- }
577
-
578
556
  /**
579
557
  * Create a CheckoutCommand.
580
558
  *
@@ -11,3 +11,4 @@ export type {
11
11
  CheckoutOptions,
12
12
  } from "./checkout.command.js";
13
13
  export { CheckoutConflictReason as CheckoutConflictReasonValues } from "./checkout.command.js";
14
+ export * from "./store-worktree-file.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `storeWorktreeFile` lives in `@statewalker/vcs-working-tree`, so the stash and
3
+ * the add commands share it; re-exported here for existing imports.
4
+ */
5
+ export { storeWorktreeFile } from "@statewalker/vcs-working-tree";
@@ -245,6 +245,17 @@ export class RemoteConfigStore {
245
245
  return this.strings(name, "url")[0];
246
246
  }
247
247
 
248
+ /** A config variable (`push.default`, `branch.main.merge`), the last value when repeated. */
249
+ value(key: string): string | undefined {
250
+ const value = this.config.get(key);
251
+ return value === undefined || value === null ? undefined : String(value);
252
+ }
253
+
254
+ /** Sets a config variable, replacing every value it had. */
255
+ setValue(key: string, value: string): void {
256
+ this.config.set(key, value);
257
+ }
258
+
248
259
  /** Flush to the backing file, if the config has one. */
249
260
  async save(): Promise<void> {
250
261
  await this.config.save?.();
@@ -4,7 +4,7 @@
4
4
  * Based on JGit's DiffFormatter class.
5
5
  */
6
6
 
7
- import type { Blobs, ObjectId } from "@statewalker/vcs-core";
7
+ import { type Blobs, DEFAULT_BIG_FILE_THRESHOLD, probeBlob } from "@statewalker/vcs-core";
8
8
  import {
9
9
  DEFAULT_ALGORITHM,
10
10
  type DiffAlgorithm,
@@ -31,6 +31,11 @@ export interface DiffFormatterOptions {
31
31
  abbreviationLength?: number;
32
32
  /** Diff algorithm to use (default: histogram) */
33
33
  algorithm?: SupportedAlgorithm;
34
+ /**
35
+ * Files larger than this are binary: they show as "Binary files differ" and are
36
+ * never loaded (git's `core.bigFileThreshold`). Default 50 MiB.
37
+ */
38
+ bigFileThreshold?: number;
34
39
  }
35
40
 
36
41
  /**
@@ -67,9 +72,9 @@ export interface FileContentDiff {
67
72
  indexLine?: string;
68
73
  /** Hunks of changes */
69
74
  hunks: DiffHunk[];
70
- /** Raw old content (for binary display or further processing) */
75
+ /** Raw old content of a text file (binary files are not loaded) */
71
76
  oldContent?: Uint8Array;
72
- /** Raw new content (for binary display or further processing) */
77
+ /** Raw new content of a text file (binary files are not loaded) */
73
78
  newContent?: Uint8Array;
74
79
  }
75
80
 
@@ -96,6 +101,7 @@ export class DiffFormatter {
96
101
  private abbreviateIds: boolean;
97
102
  private abbreviationLength: number;
98
103
  private diffAlgorithm: DiffAlgorithm;
104
+ private bigFileThreshold: number;
99
105
 
100
106
  constructor(
101
107
  private readonly blobs: Blobs,
@@ -106,23 +112,31 @@ export class DiffFormatter {
106
112
  this.abbreviateIds = options.abbreviateIds ?? true;
107
113
  this.abbreviationLength = options.abbreviationLength ?? 7;
108
114
  this.diffAlgorithm = getAlgorithm(options.algorithm ?? DEFAULT_ALGORITHM);
115
+ this.bigFileThreshold = options.bigFileThreshold ?? DEFAULT_BIG_FILE_THRESHOLD;
109
116
  }
110
117
 
111
118
  /**
112
119
  * Format a DiffEntry into a content diff.
113
120
  *
121
+ * Each side is probed first (its size, and a NUL byte in its first 8000
122
+ * bytes, as git checks). A side over `bigFileThreshold` or binary makes the
123
+ * entry binary, and then the other side is not loaded. Text sides are loaded
124
+ * whole, as the diff algorithms need them, by the same single read as the probe.
125
+ *
114
126
  * @param entry The diff entry to format
115
127
  * @returns Content diff with hunks
116
128
  */
117
129
  async format(entry: DiffEntry): Promise<FileContentDiff> {
118
- // Load content for old and new
119
- const oldContent = entry.oldId ? await this.loadContent(entry.oldId) : null;
120
- const newContent = entry.newId ? await this.loadContent(entry.newId) : null;
130
+ // The probe of a text side reads it whole, once; a binary side only to 8000 bytes
131
+ const options = { bigFileThreshold: this.bigFileThreshold, loadText: true };
132
+ const oldProbe = entry.oldId ? await probeBlob(this.blobs, entry.oldId, options) : null;
133
+ const newProbe =
134
+ !oldProbe?.binary && entry.newId ? await probeBlob(this.blobs, entry.newId, options) : null;
135
+ const isBinary = (oldProbe?.binary ?? false) || (newProbe?.binary ?? false);
121
136
 
122
- // Check for binary content
123
- const isBinary =
124
- (oldContent !== null && RawText.isBinary(oldContent)) ||
125
- (newContent !== null && RawText.isBinary(newContent));
137
+ // Text only: binary and big files are never loaded
138
+ const oldContent = !isBinary ? (oldProbe?.content ?? null) : null;
139
+ const newContent = !isBinary ? (newProbe?.content ?? null) : null;
126
140
 
127
141
  // Build headers
128
142
  const result: FileContentDiff = {
@@ -180,9 +194,13 @@ export class DiffFormatter {
180
194
  }
181
195
 
182
196
  if (diff.isBinary) {
183
- lines.push(
184
- `Binary files ${diff.entry.oldPath ?? "/dev/null"} and ${diff.entry.newPath ?? "/dev/null"} differ`,
185
- );
197
+ // git's wording: a/ and b/ prefixes, /dev/null for a side that does not exist
198
+ const e = diff.entry;
199
+ const oldName =
200
+ e.changeType === ChangeType.ADD || !e.oldPath ? "/dev/null" : `a/${e.oldPath}`;
201
+ const newName =
202
+ e.changeType === ChangeType.DELETE || !e.newPath ? "/dev/null" : `b/${e.newPath}`;
203
+ lines.push(`Binary files ${oldName} and ${newName} differ`);
186
204
  return lines.join("\n");
187
205
  }
188
206
 
@@ -220,31 +238,6 @@ export class DiffFormatter {
220
238
  return parts.join("\n");
221
239
  }
222
240
 
223
- /**
224
- * Load blob content from storage.
225
- */
226
- private async loadContent(objectId: ObjectId): Promise<Uint8Array> {
227
- const content = await this.blobs.load(objectId);
228
- if (!content) {
229
- throw new Error(`Blob not found: ${objectId}`);
230
- }
231
- const chunks: Uint8Array[] = [];
232
- for await (const chunk of content) {
233
- chunks.push(chunk);
234
- }
235
-
236
- // Combine chunks
237
- const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
238
- const result = new Uint8Array(totalLength);
239
- let offset = 0;
240
- for (const chunk of chunks) {
241
- result.set(chunk, offset);
242
- offset += chunk.length;
243
- }
244
-
245
- return result;
246
- }
247
-
248
241
  /**
249
242
  * Build the diff header line.
250
243
  */
@@ -16,6 +16,13 @@ export interface TrackingRefUpdate {
16
16
  newObjectId: ObjectId;
17
17
  /** Update result status */
18
18
  status: RefUpdateStatus;
19
+ /**
20
+ * How git prints the update: `[new branch]`, `[new tag]`, `abc1234..def5678` (fast-forward),
21
+ * `+ abc1234...def5678` (forced), `[rejected]`, `[up to date]`
22
+ */
23
+ summary?: string;
24
+ /** Why a ref was rejected (`non-fast-forward`, `would clobber existing tag`, a lock failure) */
25
+ reason?: string;
19
26
  }
20
27
 
21
28
  /**
@@ -10,6 +10,8 @@ export enum PushStatus {
10
10
  OK = "ok",
11
11
  /** Update was rejected (not fast-forward) */
12
12
  REJECTED_NONFASTFORWARD = "rejected-nonfastforward",
13
+ /** Update was rejected: the remote ref no longer has the leased value (`--force-with-lease`) */
14
+ REJECTED_REMOTE_CHANGED = "rejected-remote-changed",
13
15
  /** Update was rejected (other reason) */
14
16
  REJECTED_OTHER = "rejected-other",
15
17
  /** Update failed (remote error) */
@@ -38,9 +40,14 @@ export interface RemoteRefUpdate {
38
40
  newObjectId: ObjectId;
39
41
  /** Status of the update */
40
42
  status: PushStatus;
41
- /** Message from server (if any) */
43
+ /** Why the update was refused: the server's reason, or git's status column */
42
44
  message?: string;
43
- /** Whether this was a forced update */
45
+ /**
46
+ * git's status column (`[new branch]`, `abc1234..def5678`, `[rejected] (fetch first)`,
47
+ * `[remote rejected] (hook declined)`, …)
48
+ */
49
+ summary?: string;
50
+ /** Whether the update was allowed to be a non-fast-forward (`+`, setForce, a lease that held) */
44
51
  forceUpdate: boolean;
45
52
  /** Whether this was a delete operation */
46
53
  delete: boolean;
@@ -1,8 +0,0 @@
1
- /**
2
- * Pack-import plumbing shared by the commands that receive packs
3
- * (`clone`, `fetch`).
4
- *
5
- * Internal: not re-exported from `src/index.ts`.
6
- */
7
- export { importPackIntoHistory } from "./pack-import.js";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pack-import/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { History } from "@statewalker/vcs-core";
2
- /**
3
- * Unpack pack data into a history's object stores.
4
- *
5
- * Uses the history's own {@link SerializationApi} when it exposes one
6
- * (a `HistoryWithOperations`), otherwise builds a default one over its
7
- * object stores — `WorkingCopy.history` is typed as a plain `History`,
8
- * so `serialization` is not statically available.
9
- */
10
- export declare function importPackIntoHistory(history: History, packData: Uint8Array): Promise<void>;
11
- //# sourceMappingURL=pack-import.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pack-import.d.ts","sourceRoot":"","sources":["../../src/pack-import/pack-import.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAyB,MAAM,uBAAuB,CAAC;AAK5E;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAUjG"}
@@ -1,8 +0,0 @@
1
- /**
2
- * Pack-import plumbing shared by the commands that receive packs
3
- * (`clone`, `fetch`).
4
- *
5
- * Internal: not re-exported from `src/index.ts`.
6
- */
7
-
8
- export { importPackIntoHistory } from "./pack-import.js";
@@ -1,24 +0,0 @@
1
- import type { History, HistoryWithOperations } 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 { DefaultSerializationApi } from "@statewalker/vcs-core";
5
-
6
- /**
7
- * Unpack pack data into a history's object stores.
8
- *
9
- * Uses the history's own {@link SerializationApi} when it exposes one
10
- * (a `HistoryWithOperations`), otherwise builds a default one over its
11
- * object stores — `WorkingCopy.history` is typed as a plain `History`,
12
- * so `serialization` is not statically available.
13
- */
14
- export async function importPackIntoHistory(history: History, packData: Uint8Array): Promise<void> {
15
- const serialization =
16
- (history as Partial<HistoryWithOperations>).serialization ??
17
- new DefaultSerializationApi({ history });
18
-
19
- const packStream = (async function* () {
20
- yield packData;
21
- })();
22
-
23
- await serialization.importPack(packStream);
24
- }