@statewalker/vcs-commands 0.3.2 → 0.5.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 (133) hide show
  1. package/README.md +19 -0
  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 +7 -24
  8. package/dist/commands/checkout-command.d.ts.map +1 -1
  9. package/dist/commands/clean-command.d.ts +34 -4
  10. package/dist/commands/clean-command.d.ts.map +1 -1
  11. package/dist/commands/clone-command.d.ts +61 -21
  12. package/dist/commands/clone-command.d.ts.map +1 -1
  13. package/dist/commands/core-config.d.ts +16 -0
  14. package/dist/commands/core-config.d.ts.map +1 -0
  15. package/dist/commands/fetch-command.d.ts +104 -37
  16. package/dist/commands/fetch-command.d.ts.map +1 -1
  17. package/dist/commands/index.d.ts +1 -0
  18. package/dist/commands/index.d.ts.map +1 -1
  19. package/dist/commands/index.js +2 -2
  20. package/dist/commands/init-command.d.ts.map +1 -1
  21. package/dist/commands/merge-command.d.ts +15 -2
  22. package/dist/commands/merge-command.d.ts.map +1 -1
  23. package/dist/commands/push-command.d.ts +58 -25
  24. package/dist/commands/push-command.d.ts.map +1 -1
  25. package/dist/commands/remote-command.d.ts +115 -6
  26. package/dist/commands/remote-command.d.ts.map +1 -1
  27. package/dist/commands/reset-command.d.ts.map +1 -1
  28. package/dist/commands/stash-apply-command.d.ts +35 -13
  29. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  30. package/dist/commands/stash-create-command.d.ts +59 -25
  31. package/dist/commands/stash-create-command.d.ts.map +1 -1
  32. package/dist/commands/stash-drop-command.d.ts +8 -2
  33. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  34. package/dist/commands/stash-list-command.d.ts +2 -4
  35. package/dist/commands/stash-list-command.d.ts.map +1 -1
  36. package/dist/commands/stash-working-tree.d.ts +72 -0
  37. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  38. package/dist/commands/status-command.d.ts +29 -22
  39. package/dist/commands/status-command.d.ts.map +1 -1
  40. package/dist/commands/tag-command.d.ts.map +1 -1
  41. package/dist/commands/tree-restore.d.ts +52 -5
  42. package/dist/commands/tree-restore.d.ts.map +1 -1
  43. package/dist/commands/worktree-overwrite-checks.d.ts +64 -0
  44. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  45. package/dist/{commands-COO4tJhv.js → commands-CsLNyvZ1.js} +3370 -1057
  46. package/dist/core-commands/add.command.impl.d.ts +0 -4
  47. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  48. package/dist/core-commands/index.d.ts +1 -3
  49. package/dist/core-commands/index.d.ts.map +1 -1
  50. package/dist/core-commands/store-worktree-file.d.ts +6 -0
  51. package/dist/core-commands/store-worktree-file.d.ts.map +1 -0
  52. package/dist/errors/checkout-errors.d.ts +13 -0
  53. package/dist/errors/checkout-errors.d.ts.map +1 -1
  54. package/dist/errors/index.js +18 -1
  55. package/dist/git-command.d.ts +10 -1
  56. package/dist/git-command.d.ts.map +1 -1
  57. package/dist/git.d.ts +21 -3
  58. package/dist/git.d.ts.map +1 -1
  59. package/dist/index.js +4 -4
  60. package/dist/remote-config/index.d.ts +1 -0
  61. package/dist/remote-config/index.d.ts.map +1 -1
  62. package/dist/remote-config/remote-config-store.d.ts +22 -0
  63. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  64. package/dist/remote-config/remote-refs.d.ts +37 -0
  65. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  66. package/dist/results/clone-result.d.ts +6 -0
  67. package/dist/results/clone-result.d.ts.map +1 -1
  68. package/dist/results/diff-formatter.d.ts +14 -7
  69. package/dist/results/diff-formatter.d.ts.map +1 -1
  70. package/dist/results/fetch-result.d.ts +16 -1
  71. package/dist/results/fetch-result.d.ts.map +1 -1
  72. package/dist/results/index.js +28 -23
  73. package/dist/results/push-result.d.ts +9 -2
  74. package/dist/results/push-result.d.ts.map +1 -1
  75. package/dist/results/status-result.d.ts +91 -20
  76. package/dist/results/status-result.d.ts.map +1 -1
  77. package/dist/{status-result-BwAyxq6R.js → status-result-BpyUK1Sg.js} +115 -5
  78. package/dist/transport-command.d.ts +12 -0
  79. package/dist/transport-command.d.ts.map +1 -1
  80. package/package.json +14 -12
  81. package/src/commands/add-command.ts +23 -30
  82. package/src/commands/blame-command.ts +41 -0
  83. package/src/commands/branch-command.ts +2 -53
  84. package/src/commands/checkout-command.ts +205 -127
  85. package/src/commands/clean-command.ts +187 -81
  86. package/src/commands/clone-command.ts +334 -137
  87. package/src/commands/core-config.ts +41 -0
  88. package/src/commands/fetch-command.ts +536 -211
  89. package/src/commands/gc-command.ts +1 -1
  90. package/src/commands/index.ts +1 -0
  91. package/src/commands/init-command.ts +108 -11
  92. package/src/commands/merge-command.ts +60 -27
  93. package/src/commands/pack-refs-command.ts +2 -2
  94. package/src/commands/push-command.ts +242 -308
  95. package/src/commands/reflog-command.ts +2 -2
  96. package/src/commands/remote-command.ts +429 -19
  97. package/src/commands/reset-command.ts +18 -5
  98. package/src/commands/stash-apply-command.ts +632 -97
  99. package/src/commands/stash-create-command.ts +142 -62
  100. package/src/commands/stash-drop-command.ts +53 -5
  101. package/src/commands/stash-list-command.ts +10 -4
  102. package/src/commands/stash-working-tree.ts +243 -0
  103. package/src/commands/status-command.ts +197 -91
  104. package/src/commands/tag-command.ts +2 -53
  105. package/src/commands/tree-restore.ts +143 -18
  106. package/src/commands/worktree-overwrite-checks.ts +215 -0
  107. package/src/core-commands/add.command.impl.ts +15 -20
  108. package/src/core-commands/index.ts +1 -8
  109. package/src/core-commands/store-worktree-file.ts +5 -0
  110. package/src/errors/checkout-errors.ts +20 -0
  111. package/src/git-command.ts +42 -1
  112. package/src/git.ts +30 -2
  113. package/src/remote-config/index.ts +1 -0
  114. package/src/remote-config/remote-config-store.ts +95 -8
  115. package/src/remote-config/remote-refs.ts +103 -0
  116. package/src/results/clone-result.ts +6 -0
  117. package/src/results/diff-formatter.ts +31 -38
  118. package/src/results/fetch-result.ts +16 -1
  119. package/src/results/push-result.ts +9 -2
  120. package/src/results/status-result.ts +212 -29
  121. package/src/transport-command.ts +18 -0
  122. package/dist/core-commands/checkout.command.d.ts +0 -103
  123. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  124. package/dist/core-commands/checkout.command.impl.d.ts +0 -114
  125. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  126. package/dist/pack-import/index.d.ts +0 -8
  127. package/dist/pack-import/index.d.ts.map +0 -1
  128. package/dist/pack-import/pack-import.d.ts +0 -11
  129. package/dist/pack-import/pack-import.d.ts.map +0 -1
  130. package/src/core-commands/checkout.command.impl.ts +0 -586
  131. package/src/core-commands/checkout.command.ts +0 -125
  132. package/src/pack-import/index.ts +0 -8
  133. package/src/pack-import/pack-import.ts +0 -24
@@ -1,586 +0,0 @@
1
- /**
2
- * CheckoutCommand - Materializes tree contents to filesystem.
3
- *
4
- * Implements the Checkout interface to:
5
- * - Checkout branches, tags, or commits
6
- * - Checkout specific paths from index or commits
7
- * - Detect and report conflicts
8
- * - Update HEAD and index after checkout
9
- *
10
- * Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
11
- */
12
-
13
- import {
14
- type Blobs,
15
- type Commits,
16
- FileMode,
17
- type FilesApi,
18
- joinPath,
19
- type ObjectId,
20
- type RefStore,
21
- type TreeEntry,
22
- type Trees,
23
- } from "@statewalker/vcs-core";
24
- import type { Staging } from "@statewalker/vcs-working-tree";
25
- import type { Checkout, CheckoutOptions, CheckoutResult } from "./checkout.command.js";
26
-
27
- /**
28
- * Flattened tree entry with full path.
29
- */
30
- interface FlatTreeEntry extends TreeEntry {
31
- /** Full path from repository root */
32
- path: string;
33
- }
34
-
35
- /**
36
- * Options for creating a CheckoutCommand.
37
- */
38
- export interface CheckoutCommandOptions {
39
- /** FilesApi for filesystem operations */
40
- files: FilesApi;
41
-
42
- /** Working tree root path */
43
- workTreeRoot: string;
44
-
45
- /** Blob storage for loading file content */
46
- blobs: Blobs;
47
-
48
- /** Tree storage for loading tree entries */
49
- trees: Trees;
50
-
51
- /** Commit storage for resolving commits */
52
- commits: Commits;
53
-
54
- /** Reference storage for resolving refs and updating HEAD */
55
- refs: RefStore;
56
-
57
- /** Staging area (index) for updating after checkout */
58
- staging: Staging;
59
- }
60
-
61
- /**
62
- * CheckoutCommand implementation.
63
- */
64
- export class CheckoutCommand implements Checkout {
65
- private readonly files: FilesApi;
66
- private readonly workTreeRoot: string;
67
- private readonly blobs: Blobs;
68
- private readonly trees: Trees;
69
- private readonly commits: Commits;
70
- private readonly refs: RefStore;
71
- private readonly staging: Staging;
72
-
73
- constructor(options: CheckoutCommandOptions) {
74
- this.files = options.files;
75
- this.workTreeRoot = options.workTreeRoot;
76
- this.blobs = options.blobs;
77
- this.trees = options.trees;
78
- this.commits = options.commits;
79
- this.refs = options.refs;
80
- this.staging = options.staging;
81
- }
82
-
83
- /**
84
- * Checkout a branch, tag, or commit.
85
- */
86
- async checkout(target: string, options: CheckoutOptions = {}): Promise<CheckoutResult> {
87
- // Resolve target to commit
88
- const commitId = await this.resolveTarget(target);
89
- if (!commitId) {
90
- throw new Error(`Cannot resolve '${target}' to a commit`);
91
- }
92
-
93
- // Get target tree
94
- const treeId = await this.commits.getTree(commitId);
95
- if (!treeId) {
96
- throw new Error(`Cannot get tree for commit ${commitId}`);
97
- }
98
-
99
- // Check for conflicts unless force
100
- if (!options.force) {
101
- const conflicts = await this.detectConflicts(treeId);
102
- if (conflicts.length > 0) {
103
- return {
104
- updated: [],
105
- added: [],
106
- removed: [],
107
- conflicts,
108
- };
109
- }
110
- }
111
-
112
- // Perform checkout
113
- const result = await this.checkoutTree(treeId, options);
114
-
115
- // Update HEAD
116
- if (await this.isLocalBranch(target)) {
117
- await this.refs.setSymbolic("HEAD", `refs/heads/${target}`);
118
- result.newBranch = target;
119
- } else {
120
- await this.refs.set("HEAD", commitId);
121
- }
122
-
123
- // Create new branch if requested
124
- if (options.createBranch) {
125
- await this.refs.set(`refs/heads/${options.createBranch}`, commitId);
126
- await this.refs.setSymbolic("HEAD", `refs/heads/${options.createBranch}`);
127
- result.newBranch = options.createBranch;
128
- }
129
-
130
- result.newHead = commitId;
131
- return result;
132
- }
133
-
134
- /**
135
- * Checkout specific paths from index or commit.
136
- */
137
- async checkoutPaths(paths: string[], options: CheckoutOptions = {}): Promise<CheckoutResult> {
138
- const source = options.source ?? "index";
139
-
140
- const result: CheckoutResult = {
141
- updated: [],
142
- added: [],
143
- removed: [],
144
- conflicts: [],
145
- };
146
-
147
- for (const path of paths) {
148
- try {
149
- if (source === "index") {
150
- await this.checkoutFromIndex(path);
151
- } else {
152
- const treeId =
153
- source === "head" ? await this.getHeadTreeId() : await this.commits.getTree(source);
154
- if (treeId) {
155
- await this.checkoutFromTree(path, treeId);
156
- }
157
- }
158
- result.updated.push(path);
159
- } catch {
160
- result.conflicts.push(path);
161
- }
162
- }
163
-
164
- return result;
165
- }
166
-
167
- /**
168
- * Checkout a path from the index.
169
- */
170
- private async checkoutFromIndex(path: string): Promise<void> {
171
- const entry = await this.staging.getEntry(path);
172
- if (!entry) {
173
- throw new Error(`Path not in index: ${path}`);
174
- }
175
-
176
- await this.writeFileContent(path, entry.objectId, entry.mode);
177
- }
178
-
179
- /**
180
- * Checkout a path from a tree.
181
- */
182
- private async checkoutFromTree(path: string, treeId: ObjectId): Promise<void> {
183
- // Find the entry in the tree
184
- const parts = path.split("/");
185
- let currentTreeId = treeId;
186
- let entry: TreeEntry | undefined;
187
-
188
- for (let i = 0; i < parts.length; i++) {
189
- const name = parts[i];
190
- entry = await this.trees.getEntry(currentTreeId, name);
191
-
192
- if (!entry) {
193
- throw new Error(`Path not found in tree: ${path}`);
194
- }
195
-
196
- if (i < parts.length - 1) {
197
- // Navigate into subtree
198
- if (entry.mode !== FileMode.TREE) {
199
- throw new Error(`Not a directory: ${parts.slice(0, i + 1).join("/")}`);
200
- }
201
- currentTreeId = entry.id;
202
- }
203
- }
204
-
205
- if (!entry) {
206
- throw new Error(`Path not found in tree: ${path}`);
207
- }
208
-
209
- await this.writeFileContent(path, entry.id, entry.mode);
210
- }
211
-
212
- /**
213
- * Checkout an entire tree to the working directory.
214
- */
215
- private async checkoutTree(treeId: ObjectId, options: CheckoutOptions): Promise<CheckoutResult> {
216
- const result: CheckoutResult = {
217
- updated: [],
218
- added: [],
219
- removed: [],
220
- conflicts: [],
221
- };
222
-
223
- // Build current index map
224
- const currentIndex = new Map<string, { objectId: ObjectId; mode: number }>();
225
- for await (const entry of this.staging.entries()) {
226
- if (entry.stage === 0) {
227
- // Only stage 0 entries
228
- currentIndex.set(entry.path, { objectId: entry.objectId, mode: entry.mode });
229
- }
230
- }
231
-
232
- // Build target tree map
233
- const targetTree = await this.flattenTree(treeId, "");
234
-
235
- // Calculate operations
236
- const toRemove = new Set<string>();
237
- const toUpdate = new Map<string, FlatTreeEntry>();
238
-
239
- // Find files to remove (in current but not in target)
240
- for (const path of currentIndex.keys()) {
241
- if (!targetTree.has(path)) {
242
- toRemove.add(path);
243
- }
244
- }
245
-
246
- // Find files to add/update
247
- for (const [path, entry] of targetTree) {
248
- const current = currentIndex.get(path);
249
- if (!current || current.objectId !== entry.id) {
250
- toUpdate.set(path, entry);
251
- }
252
- }
253
-
254
- // Execute removals
255
- for (const path of toRemove) {
256
- try {
257
- await this.removeFile(path);
258
- result.removed.push(path);
259
- } catch {
260
- result.conflicts.push(path);
261
- }
262
- }
263
-
264
- // Execute updates
265
- let processed = 0;
266
- const total = toUpdate.size;
267
-
268
- for (const [path, entry] of toUpdate) {
269
- try {
270
- await this.writeFileContent(path, entry.id, entry.mode);
271
-
272
- if (currentIndex.has(path)) {
273
- result.updated.push(path);
274
- } else {
275
- result.added.push(path);
276
- }
277
- } catch {
278
- result.conflicts.push(path);
279
- }
280
-
281
- processed++;
282
- options.onProgress?.(processed, total, path);
283
- }
284
-
285
- // Update index from target tree
286
- await this.rebuildIndex(targetTree);
287
-
288
- return result;
289
- }
290
-
291
- /**
292
- * Write file content to working tree.
293
- */
294
- private async writeFileContent(path: string, objectId: ObjectId, _mode: number): Promise<void> {
295
- const absolutePath = joinPath(this.workTreeRoot, path);
296
-
297
- // Ensure parent directory exists
298
- const lastSlash = path.lastIndexOf("/");
299
- if (lastSlash > 0) {
300
- const parentDir = joinPath(this.workTreeRoot, path.substring(0, lastSlash));
301
- await this.files.mkdir(parentDir);
302
- }
303
-
304
- // Load and write content
305
- const content = await this.loadBlobContent(objectId);
306
- await this.files.write(absolutePath, [content]);
307
-
308
- // Note: FilesApi doesn't support chmod, so executable bit is not set
309
- // This could be extended with FilesApiAdapter if needed
310
- }
311
-
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
- /**
328
- * Remove file from working tree.
329
- */
330
- private async removeFile(path: string): Promise<void> {
331
- const absolutePath = joinPath(this.workTreeRoot, path);
332
- await this.files.remove(absolutePath);
333
-
334
- // Try to remove empty parent directories
335
- await this.cleanEmptyParents(path);
336
- }
337
-
338
- /**
339
- * Remove empty parent directories.
340
- */
341
- private async cleanEmptyParents(path: string): Promise<void> {
342
- const parts = path.split("/");
343
- parts.pop(); // Remove filename
344
-
345
- while (parts.length > 0) {
346
- const dirPath = joinPath(this.workTreeRoot, parts.join("/"));
347
-
348
- try {
349
- let isEmpty = true;
350
- for await (const _ of this.files.list(dirPath)) {
351
- isEmpty = false;
352
- break;
353
- }
354
-
355
- if (isEmpty) {
356
- await this.files.remove(dirPath);
357
- parts.pop();
358
- } else {
359
- break;
360
- }
361
- } catch {
362
- break;
363
- }
364
- }
365
- }
366
-
367
- /**
368
- * Flatten a tree into a map of path -> entry.
369
- */
370
- private async flattenTree(treeId: ObjectId, prefix: string): Promise<Map<string, FlatTreeEntry>> {
371
- const map = new Map<string, FlatTreeEntry>();
372
- const entries = await this.trees.load(treeId);
373
- if (!entries) {
374
- return map;
375
- }
376
-
377
- for await (const entry of entries) {
378
- const path = prefix ? `${prefix}/${entry.name}` : entry.name;
379
-
380
- if (entry.mode === FileMode.TREE) {
381
- // Recurse into subtree
382
- const subtree = await this.flattenTree(entry.id, path);
383
- for (const [subPath, subEntry] of subtree) {
384
- map.set(subPath, subEntry);
385
- }
386
- } else {
387
- map.set(path, { ...entry, path });
388
- }
389
- }
390
-
391
- return map;
392
- }
393
-
394
- /**
395
- * Resolve target to commit ID.
396
- */
397
- private async resolveTarget(target: string): Promise<ObjectId | undefined> {
398
- // Try as branch first
399
- let ref = await this.refs.resolve(`refs/heads/${target}`);
400
- if (ref?.objectId) {
401
- return ref.objectId;
402
- }
403
-
404
- // Try as tag
405
- ref = await this.refs.resolve(`refs/tags/${target}`);
406
- if (ref?.objectId) {
407
- return ref.objectId;
408
- }
409
-
410
- // Try as direct ref
411
- ref = await this.refs.resolve(target);
412
- if (ref?.objectId) {
413
- return ref.objectId;
414
- }
415
-
416
- // Try as commit ID
417
- if (await this.commits.has(target)) {
418
- return target;
419
- }
420
-
421
- return undefined;
422
- }
423
-
424
- /**
425
- * Check if name is a local branch.
426
- */
427
- private async isLocalBranch(name: string): Promise<boolean> {
428
- return this.refs.has(`refs/heads/${name}`);
429
- }
430
-
431
- /**
432
- * Get HEAD's tree ID.
433
- */
434
- private async getHeadTreeId(): Promise<ObjectId | undefined> {
435
- const headRef = await this.refs.resolve("HEAD");
436
- if (headRef?.objectId) {
437
- return this.commits.getTree(headRef.objectId);
438
- }
439
- return undefined;
440
- }
441
-
442
- /**
443
- * Detect conflicts - files that would be overwritten.
444
- */
445
- private async detectConflicts(targetTreeId: ObjectId): Promise<string[]> {
446
- const conflicts: string[] = [];
447
-
448
- // Get current HEAD tree
449
- const headTreeId = await this.getHeadTreeId();
450
- const headTree = headTreeId
451
- ? await this.flattenTree(headTreeId, "")
452
- : new Map<string, FlatTreeEntry>();
453
-
454
- // Get current index
455
- const indexEntries = new Map<string, { objectId: ObjectId; size: number; mtime: number }>();
456
- for await (const entry of this.staging.entries()) {
457
- if (entry.stage === 0) {
458
- indexEntries.set(entry.path, {
459
- objectId: entry.objectId,
460
- size: entry.size,
461
- mtime: entry.mtime,
462
- });
463
- }
464
- }
465
-
466
- // Get target tree
467
- const targetTree = await this.flattenTree(targetTreeId, "");
468
-
469
- // Check each path that differs between HEAD and target
470
- for (const [path, targetEntry] of targetTree) {
471
- const headEntry = headTree.get(path);
472
- const indexEntry = indexEntries.get(path);
473
-
474
- // If path is same in HEAD and target, no conflict possible
475
- if (headEntry && headEntry.id === targetEntry.id) {
476
- continue;
477
- }
478
-
479
- // If index differs from HEAD, user has staged changes
480
- if (indexEntry && headEntry && indexEntry.objectId !== headEntry.id) {
481
- conflicts.push(path);
482
- continue;
483
- }
484
-
485
- // Check working tree for modifications
486
- const fullPath = joinPath(this.workTreeRoot, path);
487
- try {
488
- const stats = await this.files.stats(fullPath);
489
- if (stats && indexEntry) {
490
- // If size or mtime differs, might be modified
491
- if (stats.size !== indexEntry.size || (stats.lastModified ?? 0) > indexEntry.mtime) {
492
- conflicts.push(path);
493
- }
494
- }
495
- } catch {
496
- // File doesn't exist, no conflict
497
- }
498
- }
499
-
500
- // Check for files that would be removed but have local changes
501
- for (const [path] of headTree) {
502
- if (!targetTree.has(path)) {
503
- const indexEntry = indexEntries.get(path);
504
- const fullPath = joinPath(this.workTreeRoot, path);
505
-
506
- try {
507
- const stats = await this.files.stats(fullPath);
508
- if (stats && indexEntry) {
509
- if (stats.size !== indexEntry.size || (stats.lastModified ?? 0) > indexEntry.mtime) {
510
- conflicts.push(path);
511
- }
512
- }
513
- } catch {
514
- // File already deleted, no conflict
515
- }
516
- }
517
- }
518
-
519
- return [...new Set(conflicts)]; // Remove duplicates
520
- }
521
-
522
- /**
523
- * Rebuild index from tree.
524
- */
525
- private async rebuildIndex(targetTree: Map<string, FlatTreeEntry>): Promise<void> {
526
- const builder = this.staging.createBuilder();
527
-
528
- for (const [path, entry] of targetTree) {
529
- // Get file stats from working tree
530
- const fullPath = joinPath(this.workTreeRoot, path);
531
- let size = 0;
532
- let mtime = Date.now();
533
-
534
- try {
535
- const stats = await this.files.stats(fullPath);
536
- if (stats) {
537
- size = stats.size ?? 0;
538
- mtime = stats.lastModified ?? Date.now();
539
- }
540
- } catch {
541
- // Use defaults
542
- }
543
-
544
- builder.add({
545
- path,
546
- mode: entry.mode,
547
- objectId: entry.id,
548
- stage: 0,
549
- size,
550
- mtime,
551
- });
552
- }
553
-
554
- builder.finish();
555
- await this.staging.write();
556
- }
557
- }
558
-
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
- /**
579
- * Create a CheckoutCommand.
580
- *
581
- * @param options Command options
582
- * @returns New CheckoutCommand instance
583
- */
584
- export function createCheckoutCommand(options: CheckoutCommandOptions): Checkout {
585
- return new CheckoutCommand(options);
586
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * Checkout interface for materializing tree contents to filesystem.
3
- *
4
- * Supports:
5
- * - Branch/tag/commit checkout
6
- * - Path-specific checkout
7
- * - Conflict detection
8
- * - Progress reporting
9
- *
10
- * Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
11
- */
12
-
13
- import type { ObjectId } from "@statewalker/vcs-core";
14
-
15
- /**
16
- * Options for checkout operations.
17
- */
18
- export interface CheckoutOptions {
19
- /** Force checkout even if working tree has changes */
20
- force?: boolean;
21
-
22
- /** Create branch at target commit */
23
- createBranch?: string;
24
-
25
- /** Checkout specific paths only */
26
- paths?: string[];
27
-
28
- /** Source for path checkout (default: "index") */
29
- source?: "index" | "head" | ObjectId;
30
-
31
- /** Progress callback */
32
- onProgress?: (current: number, total: number, path: string) => void;
33
- }
34
-
35
- /**
36
- * Result of a checkout operation.
37
- */
38
- export interface CheckoutResult {
39
- /** Files updated in working tree */
40
- updated: string[];
41
-
42
- /** Files added to working tree */
43
- added: string[];
44
-
45
- /** Files removed from working tree */
46
- removed: string[];
47
-
48
- /** Files that couldn't be checked out (conflicts) */
49
- conflicts: string[];
50
-
51
- /** New HEAD after checkout */
52
- newHead?: ObjectId;
53
-
54
- /** New branch name if created */
55
- newBranch?: string;
56
- }
57
-
58
- /**
59
- * Checkout command interface.
60
- *
61
- * Materializes tree contents from commits, branches, or tags to the working tree.
62
- * Handles conflict detection and index updates.
63
- */
64
- export interface Checkout {
65
- /**
66
- * Checkout a branch, tag, or commit.
67
- *
68
- * If target is a branch name, HEAD becomes a symbolic ref to that branch.
69
- * If target is a tag or commit, HEAD becomes detached.
70
- *
71
- * @param target Branch name, tag name, or commit ID
72
- * @param options Checkout options
73
- * @returns Checkout result with lists of affected files
74
- * @throws Error if target cannot be resolved or conflicts exist (without force)
75
- */
76
- checkout(target: string, options?: CheckoutOptions): Promise<CheckoutResult>;
77
-
78
- /**
79
- * Checkout specific paths from index or commit.
80
- *
81
- * Unlike full checkout, this:
82
- * - Does not move HEAD
83
- * - Only updates specified paths
84
- * - Restores files from index (default) or a specific commit
85
- *
86
- * @param paths Paths to checkout
87
- * @param options Checkout options (source specifies where to get files)
88
- * @returns Checkout result
89
- */
90
- checkoutPaths(paths: string[], options?: CheckoutOptions): Promise<CheckoutResult>;
91
- }
92
-
93
- /**
94
- * Conflict information for a path.
95
- */
96
- export interface CheckoutConflict {
97
- /** Path with conflict */
98
- path: string;
99
-
100
- /** Reason for conflict */
101
- reason: CheckoutConflictReason;
102
-
103
- /** Local changes that would be overwritten (if applicable) */
104
- localChanges?: "modified" | "deleted" | "untracked";
105
- }
106
-
107
- /**
108
- * Reasons why checkout failed for a path.
109
- */
110
- export const CheckoutConflictReason = {
111
- /** Local modifications would be overwritten */
112
- LOCAL_MODIFIED: "LOCAL_MODIFIED",
113
-
114
- /** Untracked file would be overwritten */
115
- UNTRACKED_OVERWRITTEN: "UNTRACKED_OVERWRITTEN",
116
-
117
- /** File deleted locally but modified in target */
118
- DELETED_LOCALLY: "DELETED_LOCALLY",
119
-
120
- /** Cannot delete directory - not empty */
121
- DIRECTORY_NOT_EMPTY: "DIRECTORY_NOT_EMPTY",
122
- } as const;
123
-
124
- export type CheckoutConflictReason =
125
- (typeof CheckoutConflictReason)[keyof typeof CheckoutConflictReason];
@@ -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";