type-git 0.0.1

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/dist/adapters/bun/exec.d.ts +13 -0
  4. package/dist/adapters/bun/exec.d.ts.map +1 -0
  5. package/dist/adapters/bun/exec.js +242 -0
  6. package/dist/adapters/bun/exec.js.map +1 -0
  7. package/dist/adapters/bun/fs.d.ts +20 -0
  8. package/dist/adapters/bun/fs.d.ts.map +1 -0
  9. package/dist/adapters/bun/fs.js +148 -0
  10. package/dist/adapters/bun/fs.js.map +1 -0
  11. package/dist/adapters/bun/index.d.ts +11 -0
  12. package/dist/adapters/bun/index.d.ts.map +1 -0
  13. package/dist/adapters/bun/index.js +17 -0
  14. package/dist/adapters/bun/index.js.map +1 -0
  15. package/dist/adapters/deno/exec.d.ts +14 -0
  16. package/dist/adapters/deno/exec.d.ts.map +1 -0
  17. package/dist/adapters/deno/exec.js +266 -0
  18. package/dist/adapters/deno/exec.js.map +1 -0
  19. package/dist/adapters/deno/fs.d.ts +21 -0
  20. package/dist/adapters/deno/fs.d.ts.map +1 -0
  21. package/dist/adapters/deno/fs.js +191 -0
  22. package/dist/adapters/deno/fs.js.map +1 -0
  23. package/dist/adapters/deno/index.d.ts +11 -0
  24. package/dist/adapters/deno/index.d.ts.map +1 -0
  25. package/dist/adapters/deno/index.js +17 -0
  26. package/dist/adapters/deno/index.js.map +1 -0
  27. package/dist/adapters/node/exec.d.ts +11 -0
  28. package/dist/adapters/node/exec.d.ts.map +1 -0
  29. package/dist/adapters/node/exec.js +161 -0
  30. package/dist/adapters/node/exec.js.map +1 -0
  31. package/dist/adapters/node/fs.d.ts +18 -0
  32. package/dist/adapters/node/fs.d.ts.map +1 -0
  33. package/dist/adapters/node/fs.js +164 -0
  34. package/dist/adapters/node/fs.js.map +1 -0
  35. package/dist/adapters/node/index.d.ts +61 -0
  36. package/dist/adapters/node/index.d.ts.map +1 -0
  37. package/dist/adapters/node/index.js +76 -0
  38. package/dist/adapters/node/index.js.map +1 -0
  39. package/dist/core/adapters.d.ts +192 -0
  40. package/dist/core/adapters.d.ts.map +1 -0
  41. package/dist/core/adapters.js +10 -0
  42. package/dist/core/adapters.js.map +1 -0
  43. package/dist/core/git.d.ts +160 -0
  44. package/dist/core/git.d.ts.map +1 -0
  45. package/dist/core/git.js +5 -0
  46. package/dist/core/git.js.map +1 -0
  47. package/dist/core/index.d.ts +8 -0
  48. package/dist/core/index.d.ts.map +1 -0
  49. package/dist/core/index.js +8 -0
  50. package/dist/core/index.js.map +1 -0
  51. package/dist/core/repo.d.ts +1275 -0
  52. package/dist/core/repo.d.ts.map +1 -0
  53. package/dist/core/repo.js +5 -0
  54. package/dist/core/repo.js.map +1 -0
  55. package/dist/core/types.d.ts +376 -0
  56. package/dist/core/types.d.ts.map +1 -0
  57. package/dist/core/types.js +100 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/impl/bare-repo-impl.d.ts +72 -0
  60. package/dist/impl/bare-repo-impl.d.ts.map +1 -0
  61. package/dist/impl/bare-repo-impl.js +328 -0
  62. package/dist/impl/bare-repo-impl.js.map +1 -0
  63. package/dist/impl/git-impl.d.ts +92 -0
  64. package/dist/impl/git-impl.d.ts.map +1 -0
  65. package/dist/impl/git-impl.js +350 -0
  66. package/dist/impl/git-impl.js.map +1 -0
  67. package/dist/impl/index.d.ts +7 -0
  68. package/dist/impl/index.d.ts.map +1 -0
  69. package/dist/impl/index.js +7 -0
  70. package/dist/impl/index.js.map +1 -0
  71. package/dist/impl/worktree-repo-impl.d.ts +180 -0
  72. package/dist/impl/worktree-repo-impl.d.ts.map +1 -0
  73. package/dist/impl/worktree-repo-impl.js +1931 -0
  74. package/dist/impl/worktree-repo-impl.js.map +1 -0
  75. package/dist/index.d.ts +9 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +14 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/parsers/index.d.ts +230 -0
  80. package/dist/parsers/index.d.ts.map +1 -0
  81. package/dist/parsers/index.js +529 -0
  82. package/dist/parsers/index.js.map +1 -0
  83. package/dist/runner/cli-runner.d.ts +94 -0
  84. package/dist/runner/cli-runner.d.ts.map +1 -0
  85. package/dist/runner/cli-runner.js +315 -0
  86. package/dist/runner/cli-runner.js.map +1 -0
  87. package/dist/runner/index.d.ts +5 -0
  88. package/dist/runner/index.d.ts.map +1 -0
  89. package/dist/runner/index.js +5 -0
  90. package/dist/runner/index.js.map +1 -0
  91. package/package.json +86 -0
@@ -0,0 +1,1931 @@
1
+ /**
2
+ * WorktreeRepo implementation - repository with working directory
3
+ */
4
+ import { GIT_LOG_FORMAT, parseGitLog, parseLines, parsePorcelainV2, parseWorktreeList, } from '../parsers/index.js';
5
+ /**
6
+ * WorktreeRepo implementation
7
+ */
8
+ export class WorktreeRepoImpl {
9
+ workdir;
10
+ runner;
11
+ _lfsMode = 'enabled';
12
+ lfs;
13
+ lfsExtra;
14
+ worktree;
15
+ branch;
16
+ stash;
17
+ tag;
18
+ submodule;
19
+ remote;
20
+ config;
21
+ constructor(runner, workdir, options) {
22
+ this.runner = runner;
23
+ this.workdir = workdir;
24
+ if (options?.lfs) {
25
+ this._lfsMode = options.lfs;
26
+ }
27
+ // Initialize LFS operations
28
+ this.lfs = {
29
+ pull: this.lfsPull.bind(this),
30
+ push: this.lfsPush.bind(this),
31
+ status: this.lfsStatus.bind(this),
32
+ prune: this.lfsPrune.bind(this),
33
+ };
34
+ // Initialize LFS extra operations
35
+ this.lfsExtra = {
36
+ preUpload: this.lfsPreUpload.bind(this),
37
+ preDownload: this.lfsPreDownload.bind(this),
38
+ };
39
+ // Initialize worktree operations
40
+ this.worktree = {
41
+ list: this.worktreeList.bind(this),
42
+ add: this.worktreeAdd.bind(this),
43
+ remove: this.worktreeRemove.bind(this),
44
+ prune: this.worktreePrune.bind(this),
45
+ lock: this.worktreeLock.bind(this),
46
+ unlock: this.worktreeUnlock.bind(this),
47
+ };
48
+ // Initialize branch operations
49
+ this.branch = {
50
+ list: this.branchList.bind(this),
51
+ current: this.branchCurrent.bind(this),
52
+ create: this.branchCreate.bind(this),
53
+ delete: this.branchDelete.bind(this),
54
+ rename: this.branchRename.bind(this),
55
+ };
56
+ // Initialize stash operations
57
+ this.stash = {
58
+ list: this.stashList.bind(this),
59
+ push: this.stashPush.bind(this),
60
+ pop: this.stashPop.bind(this),
61
+ apply: this.stashApply.bind(this),
62
+ drop: this.stashDrop.bind(this),
63
+ clear: this.stashClear.bind(this),
64
+ };
65
+ // Initialize tag operations
66
+ this.tag = {
67
+ list: this.tagList.bind(this),
68
+ create: this.tagCreate.bind(this),
69
+ delete: this.tagDelete.bind(this),
70
+ show: this.tagShow.bind(this),
71
+ };
72
+ // Initialize submodule operations
73
+ this.submodule = {
74
+ list: this.submoduleList.bind(this),
75
+ init: this.submoduleInit.bind(this),
76
+ update: this.submoduleUpdate.bind(this),
77
+ add: this.submoduleAdd.bind(this),
78
+ deinit: this.submoduleDeinit.bind(this),
79
+ };
80
+ // Initialize remote operations
81
+ this.remote = {
82
+ list: this.remoteList.bind(this),
83
+ add: this.remoteAdd.bind(this),
84
+ remove: this.remoteRemove.bind(this),
85
+ rename: this.remoteRename.bind(this),
86
+ getUrl: this.remoteGetUrl.bind(this),
87
+ setUrl: this.remoteSetUrl.bind(this),
88
+ };
89
+ // Initialize config operations (repository-level)
90
+ this.config = {
91
+ get: this.configGet.bind(this),
92
+ getAll: this.configGetAll.bind(this),
93
+ set: this.configSet.bind(this),
94
+ add: this.configAdd.bind(this),
95
+ unset: this.configUnset.bind(this),
96
+ getRaw: this.configGetRaw.bind(this),
97
+ setRaw: this.configSetRaw.bind(this),
98
+ unsetRaw: this.configUnsetRaw.bind(this),
99
+ list: this.configList.bind(this),
100
+ };
101
+ }
102
+ get context() {
103
+ return { type: 'worktree', workdir: this.workdir };
104
+ }
105
+ /**
106
+ * Execute a raw git command in this repository context
107
+ */
108
+ async raw(argv, opts) {
109
+ return this.runner.run(this.context, argv, opts);
110
+ }
111
+ /**
112
+ * Get repository status
113
+ */
114
+ async status(opts) {
115
+ const args = ['status', '--porcelain=v2'];
116
+ if (opts?.untracked) {
117
+ switch (opts.untracked) {
118
+ case 'no':
119
+ args.push('-uno');
120
+ break;
121
+ case 'normal':
122
+ args.push('-unormal');
123
+ break;
124
+ case 'all':
125
+ args.push('-uall');
126
+ break;
127
+ }
128
+ }
129
+ // Add branch info
130
+ args.push('--branch');
131
+ const result = await this.runner.runOrThrow(this.context, args, {
132
+ signal: opts?.signal,
133
+ });
134
+ return this.parseStatus(result.stdout);
135
+ }
136
+ parseStatus(stdout) {
137
+ const lines = parseLines(stdout);
138
+ const entries = [];
139
+ let branch;
140
+ let upstream;
141
+ let ahead;
142
+ let behind;
143
+ for (const line of lines) {
144
+ if (line.startsWith('# branch.head ')) {
145
+ branch = line.slice('# branch.head '.length);
146
+ }
147
+ else if (line.startsWith('# branch.upstream ')) {
148
+ upstream = line.slice('# branch.upstream '.length);
149
+ }
150
+ else if (line.startsWith('# branch.ab ')) {
151
+ const match = line.match(/# branch\.ab \+(\d+) -(\d+)/);
152
+ const aheadStr = match?.[1];
153
+ const behindStr = match?.[2];
154
+ if (aheadStr !== undefined && behindStr !== undefined) {
155
+ ahead = Number.parseInt(aheadStr, 10);
156
+ behind = Number.parseInt(behindStr, 10);
157
+ }
158
+ }
159
+ else if (line.startsWith('1 ') || line.startsWith('2 ')) {
160
+ // Regular or renamed entry
161
+ const parsed = parsePorcelainV2(line);
162
+ const entry = parsed[0];
163
+ if (entry?.type === 'changed') {
164
+ const indexStatus = entry.xy[0];
165
+ const workdirStatus = entry.xy[1];
166
+ if (indexStatus !== undefined && workdirStatus !== undefined) {
167
+ entries.push({
168
+ path: entry.path,
169
+ index: indexStatus,
170
+ workdir: workdirStatus,
171
+ originalPath: entry.origPath,
172
+ });
173
+ }
174
+ }
175
+ }
176
+ else if (line.startsWith('u ')) {
177
+ // Unmerged entry
178
+ const parsed = parsePorcelainV2(line);
179
+ const entry = parsed[0];
180
+ if (entry?.type === 'unmerged') {
181
+ const indexStatus = entry.xy[0];
182
+ const workdirStatus = entry.xy[1];
183
+ if (indexStatus !== undefined && workdirStatus !== undefined) {
184
+ entries.push({
185
+ path: entry.path,
186
+ index: indexStatus,
187
+ workdir: workdirStatus,
188
+ });
189
+ }
190
+ }
191
+ }
192
+ else if (line.startsWith('? ')) {
193
+ // Untracked
194
+ entries.push({
195
+ path: line.slice(2),
196
+ index: '?',
197
+ workdir: '?',
198
+ });
199
+ }
200
+ else if (line.startsWith('! ')) {
201
+ // Ignored
202
+ entries.push({
203
+ path: line.slice(2),
204
+ index: '!',
205
+ workdir: '!',
206
+ });
207
+ }
208
+ }
209
+ return {
210
+ entries,
211
+ branch,
212
+ upstream,
213
+ ahead,
214
+ behind,
215
+ };
216
+ }
217
+ /**
218
+ * Get commit log
219
+ */
220
+ async log(opts) {
221
+ const args = ['log', `--format=${GIT_LOG_FORMAT}`];
222
+ if (opts?.maxCount !== undefined) {
223
+ args.push(`-n${opts.maxCount}`);
224
+ }
225
+ if (opts?.skip !== undefined) {
226
+ args.push(`--skip=${opts.skip}`);
227
+ }
228
+ if (opts?.since) {
229
+ const since = opts.since instanceof Date ? opts.since.toISOString() : opts.since;
230
+ args.push(`--since=${since}`);
231
+ }
232
+ if (opts?.until) {
233
+ const until = opts.until instanceof Date ? opts.until.toISOString() : opts.until;
234
+ args.push(`--until=${until}`);
235
+ }
236
+ if (opts?.author) {
237
+ args.push(`--author=${opts.author}`);
238
+ }
239
+ if (opts?.grep) {
240
+ args.push(`--grep=${opts.grep}`);
241
+ }
242
+ if (opts?.all) {
243
+ args.push('--all');
244
+ }
245
+ if (opts?.firstParent) {
246
+ args.push('--first-parent');
247
+ }
248
+ const result = await this.runner.runOrThrow(this.context, args, {
249
+ signal: opts?.signal,
250
+ });
251
+ const parsed = parseGitLog(result.stdout);
252
+ return parsed.map((p) => ({
253
+ hash: p.hash,
254
+ abbrevHash: p.abbrevHash,
255
+ parents: p.parents,
256
+ author: {
257
+ name: p.authorName,
258
+ email: p.authorEmail,
259
+ timestamp: p.authorTimestamp,
260
+ },
261
+ committer: {
262
+ name: p.committerName,
263
+ email: p.committerEmail,
264
+ timestamp: p.committerTimestamp,
265
+ },
266
+ subject: p.subject,
267
+ body: p.body,
268
+ }));
269
+ }
270
+ /**
271
+ * Fetch from remote
272
+ */
273
+ async fetch(opts) {
274
+ const args = ['fetch'];
275
+ if (opts?.onProgress) {
276
+ args.push('--progress');
277
+ }
278
+ if (opts?.prune) {
279
+ args.push('--prune');
280
+ }
281
+ if (opts?.tags) {
282
+ args.push('--tags');
283
+ }
284
+ if (opts?.depth !== undefined) {
285
+ args.push(`--depth=${opts.depth}`);
286
+ }
287
+ if (opts?.remote) {
288
+ args.push(opts.remote);
289
+ }
290
+ if (opts?.refspec) {
291
+ const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
292
+ args.push(...refspecs);
293
+ }
294
+ await this.runner.runOrThrow(this.context, args, {
295
+ signal: opts?.signal,
296
+ onProgress: opts?.onProgress,
297
+ });
298
+ }
299
+ /**
300
+ * Push to remote
301
+ */
302
+ async push(opts) {
303
+ const args = ['push'];
304
+ if (opts?.onProgress) {
305
+ args.push('--progress');
306
+ }
307
+ if (opts?.force) {
308
+ args.push('--force');
309
+ }
310
+ else if (opts?.forceWithLease !== undefined && opts.forceWithLease !== false) {
311
+ if (opts.forceWithLease === true) {
312
+ args.push('--force-with-lease');
313
+ }
314
+ else {
315
+ // ForceWithLeaseOpts: { refname: string; expect?: string }
316
+ const leaseOpts = opts.forceWithLease;
317
+ if (leaseOpts.expect !== undefined) {
318
+ args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
319
+ }
320
+ else {
321
+ args.push(`--force-with-lease=${leaseOpts.refname}`);
322
+ }
323
+ }
324
+ }
325
+ if (opts?.tags) {
326
+ args.push('--tags');
327
+ }
328
+ if (opts?.setUpstream) {
329
+ args.push('--set-upstream');
330
+ }
331
+ if (opts?.noVerify) {
332
+ args.push('--no-verify');
333
+ }
334
+ if (opts?.signed !== undefined) {
335
+ if (opts.signed === true) {
336
+ args.push('--signed');
337
+ }
338
+ else if (opts.signed === 'if-asked') {
339
+ args.push('--signed=if-asked');
340
+ }
341
+ }
342
+ if (opts?.remote) {
343
+ args.push(opts.remote);
344
+ }
345
+ if (opts?.refspec) {
346
+ const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
347
+ args.push(...refspecs);
348
+ }
349
+ await this.runner.runOrThrow(this.context, args, {
350
+ signal: opts?.signal,
351
+ onProgress: opts?.onProgress,
352
+ });
353
+ }
354
+ /**
355
+ * Configure LFS mode for this repository
356
+ */
357
+ setLfsMode(mode) {
358
+ this._lfsMode = mode;
359
+ }
360
+ // ==========================================================================
361
+ // LFS Operations
362
+ // ==========================================================================
363
+ async lfsPull(opts) {
364
+ if (this._lfsMode === 'disabled') {
365
+ return;
366
+ }
367
+ const args = ['lfs', 'pull'];
368
+ if (opts?.remote) {
369
+ args.push(opts.remote);
370
+ }
371
+ if (opts?.ref) {
372
+ args.push(opts.ref);
373
+ }
374
+ if (opts?.include && opts.include.length > 0) {
375
+ args.push('--include', opts.include.join(','));
376
+ }
377
+ if (opts?.exclude && opts.exclude.length > 0) {
378
+ args.push('--exclude', opts.exclude.join(','));
379
+ }
380
+ await this.runner.runOrThrow(this.context, args, {
381
+ signal: opts?.signal,
382
+ onProgress: opts?.onProgress,
383
+ });
384
+ }
385
+ async lfsPush(opts) {
386
+ if (this._lfsMode === 'disabled') {
387
+ return;
388
+ }
389
+ const args = ['lfs', 'push', '--all'];
390
+ if (opts?.remote) {
391
+ args.push(opts.remote);
392
+ }
393
+ else {
394
+ args.push('origin');
395
+ }
396
+ if (opts?.ref) {
397
+ args.push(opts.ref);
398
+ }
399
+ await this.runner.runOrThrow(this.context, args, {
400
+ signal: opts?.signal,
401
+ onProgress: opts?.onProgress,
402
+ });
403
+ }
404
+ async lfsStatus(opts) {
405
+ const args = ['lfs', 'status'];
406
+ if (opts?.json) {
407
+ args.push('--json');
408
+ }
409
+ const result = await this.runner.runOrThrow(this.context, args, {
410
+ signal: opts?.signal,
411
+ });
412
+ // Parse LFS status output
413
+ // For now, return a simplified version
414
+ const files = [];
415
+ if (opts?.json) {
416
+ try {
417
+ const json = JSON.parse(result.stdout);
418
+ // Process JSON output
419
+ if (json.files) {
420
+ for (const [name, info] of Object.entries(json.files)) {
421
+ files.push({
422
+ name,
423
+ size: info.size ?? 0,
424
+ status: 'unknown',
425
+ });
426
+ }
427
+ }
428
+ }
429
+ catch {
430
+ // Fallback to text parsing
431
+ }
432
+ }
433
+ return { files };
434
+ }
435
+ /**
436
+ * Pre-upload LFS objects before commit/push (2-phase commit pattern)
437
+ *
438
+ * This allows uploading LFS objects to the remote before creating a commit,
439
+ * ensuring reliable large file handling. Objects are batched to handle
440
+ * Windows command line length limits (8KB).
441
+ *
442
+ * Usage pattern:
443
+ * 1. Stage changes: git add
444
+ * 2. Pre-upload LFS: await repo.lfs.preUpload()
445
+ * 3. Commit: git commit
446
+ * 4. Push refs: git push (only refs, objects already uploaded)
447
+ */
448
+ async lfsPreUpload(opts) {
449
+ if (this._lfsMode === 'disabled') {
450
+ return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
451
+ }
452
+ const remote = opts?.remote ?? 'origin';
453
+ const batchSize = opts?.batchSize ?? 50; // Default 50 OIDs per batch (Windows 8KB limit)
454
+ // Get OIDs to upload
455
+ let oids;
456
+ if (opts?.oids && opts.oids.length > 0) {
457
+ oids = opts.oids;
458
+ }
459
+ else {
460
+ // Get all LFS objects that need to be pushed
461
+ const lsFilesResult = await this.runner.run(this.context, ['lfs', 'ls-files', '--all', '--long'], { signal: opts?.signal });
462
+ if (lsFilesResult.exitCode !== 0) {
463
+ return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
464
+ }
465
+ // Parse OIDs from ls-files output (format: <oid> [-|*] <path>)
466
+ oids = [];
467
+ for (const line of parseLines(lsFilesResult.stdout)) {
468
+ const match = line.match(/^([a-f0-9]{64})\s+[-*]\s+/);
469
+ const oid = match?.[1];
470
+ if (oid !== undefined) {
471
+ oids.push(oid);
472
+ }
473
+ }
474
+ }
475
+ if (oids.length === 0) {
476
+ return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
477
+ }
478
+ // Process in batches
479
+ let uploadedCount = 0;
480
+ let uploadedBytes = 0;
481
+ let skippedCount = 0;
482
+ for (let i = 0; i < oids.length; i += batchSize) {
483
+ const batch = oids.slice(i, i + batchSize);
484
+ const args = ['lfs', 'push', remote, '--object-id', ...batch];
485
+ const result = await this.runner.run(this.context, args, {
486
+ signal: opts?.signal,
487
+ onProgress: opts?.onProgress,
488
+ });
489
+ if (result.exitCode === 0) {
490
+ // Parse upload stats from output if available
491
+ uploadedCount += batch.length;
492
+ // Try to extract bytes from progress output
493
+ const bytesMatch = result.stderr.match(/Uploading LFS objects:.*?\((\d+(?:\.\d+)?)\s*([KMG]?B)/i);
494
+ const bytesStr = bytesMatch?.[1];
495
+ if (bytesStr !== undefined) {
496
+ let bytes = Number.parseFloat(bytesStr);
497
+ const unit = bytesMatch?.[2]?.toUpperCase();
498
+ if (unit === 'KB') {
499
+ bytes *= 1024;
500
+ }
501
+ else if (unit === 'MB') {
502
+ bytes *= 1024 * 1024;
503
+ }
504
+ else if (unit === 'GB') {
505
+ bytes *= 1024 * 1024 * 1024;
506
+ }
507
+ uploadedBytes += bytes;
508
+ }
509
+ }
510
+ else {
511
+ // Some objects may have been skipped (already on remote)
512
+ skippedCount += batch.length;
513
+ }
514
+ }
515
+ return { uploadedCount, uploadedBytes, skippedCount };
516
+ }
517
+ /**
518
+ * Pre-download LFS objects before checkout (2-phase fetch pattern)
519
+ *
520
+ * This allows downloading LFS objects before switching branches,
521
+ * ensuring files are available locally before checkout.
522
+ *
523
+ * Usage pattern:
524
+ * 1. Fetch refs: git fetch
525
+ * 2. Pre-download LFS: await repo.lfs.preDownload({ ref: 'origin/feature' })
526
+ * 3. Checkout: git checkout feature
527
+ */
528
+ async lfsPreDownload(opts) {
529
+ if (this._lfsMode === 'disabled') {
530
+ return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
531
+ }
532
+ const remote = opts?.remote ?? 'origin';
533
+ const batchSize = opts?.batchSize ?? 50;
534
+ // Get OIDs to download
535
+ let oids;
536
+ if (opts?.oids && opts.oids.length > 0) {
537
+ oids = opts.oids;
538
+ }
539
+ else if (opts?.ref) {
540
+ // Get LFS objects for a specific ref
541
+ const lsFilesResult = await this.runner.run(this.context, ['lfs', 'ls-files', '--long', opts.ref], { signal: opts?.signal });
542
+ if (lsFilesResult.exitCode !== 0) {
543
+ return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
544
+ }
545
+ // Parse OIDs from ls-files output
546
+ oids = [];
547
+ for (const line of parseLines(lsFilesResult.stdout)) {
548
+ const match = line.match(/^([a-f0-9]{64})\s+[-*]\s+/);
549
+ const oid = match?.[1];
550
+ if (oid !== undefined) {
551
+ oids.push(oid);
552
+ }
553
+ }
554
+ }
555
+ else {
556
+ // No ref specified and no OIDs provided
557
+ return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
558
+ }
559
+ if (oids.length === 0) {
560
+ return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
561
+ }
562
+ // Process in batches
563
+ let downloadedCount = 0;
564
+ let downloadedBytes = 0;
565
+ let skippedCount = 0;
566
+ for (let i = 0; i < oids.length; i += batchSize) {
567
+ const batch = oids.slice(i, i + batchSize);
568
+ const args = ['lfs', 'fetch', remote, '--', ...batch];
569
+ const result = await this.runner.run(this.context, args, {
570
+ signal: opts?.signal,
571
+ onProgress: opts?.onProgress,
572
+ });
573
+ if (result.exitCode === 0) {
574
+ downloadedCount += batch.length;
575
+ // Try to extract bytes from progress output
576
+ const bytesMatch = result.stderr.match(/Downloading LFS objects:.*?\((\d+(?:\.\d+)?)\s*([KMG]?B)/i);
577
+ const bytesStr = bytesMatch?.[1];
578
+ if (bytesStr !== undefined) {
579
+ let bytes = Number.parseFloat(bytesStr);
580
+ const unit = bytesMatch?.[2]?.toUpperCase();
581
+ if (unit === 'KB') {
582
+ bytes *= 1024;
583
+ }
584
+ else if (unit === 'MB') {
585
+ bytes *= 1024 * 1024;
586
+ }
587
+ else if (unit === 'GB') {
588
+ bytes *= 1024 * 1024 * 1024;
589
+ }
590
+ downloadedBytes += bytes;
591
+ }
592
+ }
593
+ else {
594
+ skippedCount += batch.length;
595
+ }
596
+ }
597
+ return { downloadedCount, downloadedBytes, skippedCount };
598
+ }
599
+ /**
600
+ * Prune old and unreferenced LFS objects from local storage
601
+ */
602
+ async lfsPrune(opts) {
603
+ if (this._lfsMode === 'disabled') {
604
+ return;
605
+ }
606
+ const args = ['lfs', 'prune'];
607
+ if (opts?.force) {
608
+ args.push('--force');
609
+ }
610
+ if (opts?.dryRun) {
611
+ args.push('--dry-run');
612
+ }
613
+ if (opts?.verifyRemote) {
614
+ args.push('--verify-remote');
615
+ }
616
+ if (opts?.verifyUnreferenced) {
617
+ args.push('--verify-unreferenced');
618
+ }
619
+ await this.runner.runOrThrow(this.context, args, {
620
+ signal: opts?.signal,
621
+ onProgress: opts?.onProgress,
622
+ });
623
+ }
624
+ // ==========================================================================
625
+ // Worktree Operations
626
+ // ==========================================================================
627
+ async worktreeList(opts) {
628
+ const result = await this.runner.runOrThrow(this.context, ['worktree', 'list', '--porcelain'], {
629
+ signal: opts?.signal,
630
+ });
631
+ return parseWorktreeList(result.stdout);
632
+ }
633
+ async worktreeAdd(path, opts) {
634
+ const args = ['worktree', 'add'];
635
+ if (opts?.detach) {
636
+ args.push('--detach');
637
+ }
638
+ if (opts?.track) {
639
+ args.push('--track');
640
+ }
641
+ args.push(path);
642
+ if (opts?.branch) {
643
+ if (!opts.detach) {
644
+ args.push('-b', opts.branch);
645
+ }
646
+ }
647
+ await this.runner.runOrThrow(this.context, args, {
648
+ signal: opts?.signal,
649
+ onProgress: opts?.onProgress,
650
+ });
651
+ }
652
+ async worktreeRemove(path, opts) {
653
+ const args = ['worktree', 'remove'];
654
+ if (opts?.force) {
655
+ args.push('--force');
656
+ }
657
+ args.push(path);
658
+ await this.runner.runOrThrow(this.context, args, {
659
+ signal: opts?.signal,
660
+ });
661
+ }
662
+ async worktreePrune(opts) {
663
+ const args = ['worktree', 'prune'];
664
+ if (opts?.dryRun) {
665
+ args.push('--dry-run');
666
+ }
667
+ if (opts?.verbose) {
668
+ args.push('--verbose');
669
+ }
670
+ const result = await this.runner.runOrThrow(this.context, args, {
671
+ signal: opts?.signal,
672
+ });
673
+ // Parse pruned paths from output
674
+ return parseLines(result.stdout);
675
+ }
676
+ async worktreeLock(path, opts) {
677
+ const args = ['worktree', 'lock'];
678
+ if (opts?.reason) {
679
+ args.push('--reason', opts.reason);
680
+ }
681
+ args.push(path);
682
+ await this.runner.runOrThrow(this.context, args, {
683
+ signal: opts?.signal,
684
+ });
685
+ }
686
+ async worktreeUnlock(path, opts) {
687
+ await this.runner.runOrThrow(this.context, ['worktree', 'unlock', path], {
688
+ signal: opts?.signal,
689
+ });
690
+ }
691
+ // ==========================================================================
692
+ // High-level API - add
693
+ // ==========================================================================
694
+ async add(paths, opts) {
695
+ const args = ['add'];
696
+ if (opts?.all) {
697
+ args.push('--all');
698
+ }
699
+ if (opts?.dryRun) {
700
+ args.push('--dry-run');
701
+ }
702
+ if (opts?.update) {
703
+ args.push('--update');
704
+ }
705
+ if (opts?.force) {
706
+ args.push('--force');
707
+ }
708
+ const pathList = Array.isArray(paths) ? paths : [paths];
709
+ args.push('--', ...pathList);
710
+ await this.runner.runOrThrow(this.context, args, {
711
+ signal: opts?.signal,
712
+ });
713
+ }
714
+ // ==========================================================================
715
+ // High-level API - Branch Operations
716
+ // ==========================================================================
717
+ async branchList(opts) {
718
+ const args = [
719
+ 'branch',
720
+ '--list',
721
+ '--format=%(refname:short)%00%(objectname:short)%00%(upstream:short)%00%(upstream:track,nobracket)%00%(HEAD)',
722
+ ];
723
+ if (opts?.all) {
724
+ args.push('--all');
725
+ }
726
+ if (opts?.remotes) {
727
+ args.push('--remotes');
728
+ }
729
+ const result = await this.runner.runOrThrow(this.context, args, {
730
+ signal: opts?.signal,
731
+ });
732
+ const branches = [];
733
+ for (const line of parseLines(result.stdout)) {
734
+ const parts = line.split('\0');
735
+ const name = parts[0];
736
+ const commit = parts[1];
737
+ const upstream = parts[2];
738
+ const trackInfo = parts[3];
739
+ const head = parts[4];
740
+ if (name !== undefined && commit !== undefined) {
741
+ branches.push({
742
+ name,
743
+ commit,
744
+ current: head === '*',
745
+ upstream: upstream || undefined,
746
+ gone: trackInfo?.includes('gone'),
747
+ });
748
+ }
749
+ }
750
+ return branches;
751
+ }
752
+ async branchCurrent(opts) {
753
+ const result = await this.runner.run(this.context, ['symbolic-ref', '--short', 'HEAD'], {
754
+ signal: opts?.signal,
755
+ });
756
+ if (result.exitCode !== 0) {
757
+ // Detached HEAD
758
+ return null;
759
+ }
760
+ return result.stdout.trim();
761
+ }
762
+ async branchCreate(name, opts) {
763
+ const args = ['branch'];
764
+ if (opts?.force) {
765
+ args.push('--force');
766
+ }
767
+ if (opts?.track) {
768
+ args.push('--track');
769
+ }
770
+ args.push(name);
771
+ if (opts?.startPoint) {
772
+ args.push(opts.startPoint);
773
+ }
774
+ await this.runner.runOrThrow(this.context, args, {
775
+ signal: opts?.signal,
776
+ });
777
+ }
778
+ async branchDelete(name, opts) {
779
+ const args = ['branch'];
780
+ if (opts?.remote) {
781
+ args.push('-r');
782
+ }
783
+ if (opts?.force) {
784
+ args.push('-D');
785
+ }
786
+ else {
787
+ args.push('-d');
788
+ }
789
+ args.push(name);
790
+ await this.runner.runOrThrow(this.context, args, {
791
+ signal: opts?.signal,
792
+ });
793
+ }
794
+ async branchRename(oldName, newName, opts) {
795
+ await this.runner.runOrThrow(this.context, ['branch', '-m', oldName, newName], {
796
+ signal: opts?.signal,
797
+ });
798
+ }
799
+ // ==========================================================================
800
+ // High-level API - checkout
801
+ // ==========================================================================
802
+ async checkout(target, opts) {
803
+ const args = ['checkout'];
804
+ if (opts?.force) {
805
+ args.push('--force');
806
+ }
807
+ if (opts?.createBranch) {
808
+ args.push('-b');
809
+ }
810
+ if (opts?.track) {
811
+ args.push('--track');
812
+ }
813
+ args.push(target);
814
+ if (opts?.startPoint) {
815
+ args.push(opts.startPoint);
816
+ }
817
+ await this.runner.runOrThrow(this.context, args, {
818
+ signal: opts?.signal,
819
+ });
820
+ }
821
+ // ==========================================================================
822
+ // High-level API - commit
823
+ // ==========================================================================
824
+ async commit(opts) {
825
+ const args = ['commit'];
826
+ if (opts?.message) {
827
+ args.push('-m', opts.message);
828
+ }
829
+ if (opts?.allowEmpty) {
830
+ args.push('--allow-empty');
831
+ }
832
+ if (opts?.amend) {
833
+ args.push('--amend');
834
+ }
835
+ if (opts?.all) {
836
+ args.push('-a');
837
+ }
838
+ if (opts?.author) {
839
+ args.push('--author', opts.author);
840
+ }
841
+ if (opts?.date) {
842
+ const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
843
+ args.push('--date', date);
844
+ }
845
+ if (opts?.dryRun) {
846
+ args.push('--dry-run');
847
+ }
848
+ if (opts?.noVerify) {
849
+ args.push('--no-verify');
850
+ }
851
+ if (opts?.gpgSign) {
852
+ args.push('-S');
853
+ }
854
+ else if (opts?.noGpgSign) {
855
+ args.push('--no-gpg-sign');
856
+ }
857
+ const result = await this.runner.runOrThrow(this.context, args, {
858
+ signal: opts?.signal,
859
+ });
860
+ // Parse commit output
861
+ const output = result.stdout;
862
+ let hash = '';
863
+ let branch = '';
864
+ let summary = '';
865
+ let filesChanged = 0;
866
+ let insertions = 0;
867
+ let deletions = 0;
868
+ // Get the commit hash
869
+ const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'], {
870
+ signal: opts?.signal,
871
+ });
872
+ hash = hashResult.stdout.trim();
873
+ // Get the branch name
874
+ const branchResult = await this.runner.run(this.context, ['symbolic-ref', '--short', 'HEAD'], {
875
+ signal: opts?.signal,
876
+ });
877
+ branch = branchResult.exitCode === 0 ? branchResult.stdout.trim() : 'HEAD';
878
+ // Parse stats from output if available
879
+ const statsMatch = output.match(/(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/);
880
+ if (statsMatch) {
881
+ filesChanged = Number.parseInt(statsMatch[1] || '0', 10);
882
+ insertions = Number.parseInt(statsMatch[2] || '0', 10);
883
+ deletions = Number.parseInt(statsMatch[3] || '0', 10);
884
+ }
885
+ // Get subject from log
886
+ const logResult = await this.runner.runOrThrow(this.context, ['log', '-1', '--format=%s'], {
887
+ signal: opts?.signal,
888
+ });
889
+ summary = logResult.stdout.trim();
890
+ return {
891
+ hash,
892
+ branch,
893
+ summary,
894
+ filesChanged,
895
+ insertions,
896
+ deletions,
897
+ };
898
+ }
899
+ // ==========================================================================
900
+ // High-level API - diff
901
+ // ==========================================================================
902
+ async diff(target, opts) {
903
+ const args = ['diff'];
904
+ if (opts?.staged) {
905
+ args.push('--staged');
906
+ }
907
+ if (opts?.nameOnly) {
908
+ args.push('--name-only');
909
+ }
910
+ else if (opts?.nameStatus) {
911
+ args.push('--name-status');
912
+ }
913
+ else if (opts?.stat) {
914
+ args.push('--stat');
915
+ }
916
+ if (opts?.context !== undefined) {
917
+ args.push(`-U${opts.context}`);
918
+ }
919
+ if (opts?.ignoreWhitespace) {
920
+ args.push('-w');
921
+ }
922
+ if (target) {
923
+ args.push(target);
924
+ }
925
+ if (opts?.paths && opts.paths.length > 0) {
926
+ args.push('--', ...opts.paths);
927
+ }
928
+ const result = await this.runner.runOrThrow(this.context, args, {
929
+ signal: opts?.signal,
930
+ });
931
+ // Parse nameStatus result
932
+ if (opts?.nameStatus) {
933
+ const files = [];
934
+ for (const line of parseLines(result.stdout)) {
935
+ const match = line.match(/^([AMDRTCUX])\t(.+?)(?:\t(.+))?$/);
936
+ const status = match?.[1];
937
+ const pathOrOld = match?.[2];
938
+ const newPath = match?.[3];
939
+ if (status !== undefined && pathOrOld !== undefined) {
940
+ const entry = {
941
+ status,
942
+ path: newPath ?? pathOrOld,
943
+ };
944
+ if (newPath !== undefined) {
945
+ entry.oldPath = pathOrOld;
946
+ }
947
+ files.push(entry);
948
+ }
949
+ }
950
+ return { files };
951
+ }
952
+ // Parse nameOnly result
953
+ if (opts?.nameOnly) {
954
+ const files = [];
955
+ for (const line of parseLines(result.stdout)) {
956
+ files.push({ status: 'M', path: line });
957
+ }
958
+ return { files };
959
+ }
960
+ // Return raw result (default)
961
+ return { files: [], raw: result.stdout };
962
+ }
963
+ // ==========================================================================
964
+ // High-level API - merge
965
+ // ==========================================================================
966
+ async merge(branch, opts) {
967
+ if (opts?.abort) {
968
+ await this.runner.runOrThrow(this.context, ['merge', '--abort'], {
969
+ signal: opts?.signal,
970
+ });
971
+ return { success: true };
972
+ }
973
+ if (opts?.continue) {
974
+ await this.runner.runOrThrow(this.context, ['merge', '--continue'], {
975
+ signal: opts?.signal,
976
+ });
977
+ const hash = (await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'])).stdout.trim();
978
+ return { success: true, hash };
979
+ }
980
+ const args = ['merge'];
981
+ if (opts?.message) {
982
+ args.push('-m', opts.message);
983
+ }
984
+ if (opts?.ff === 'only') {
985
+ args.push('--ff-only');
986
+ }
987
+ else if (opts?.ff === 'no' || opts?.ff === false) {
988
+ args.push('--no-ff');
989
+ }
990
+ if (opts?.squash) {
991
+ args.push('--squash');
992
+ }
993
+ if (opts?.noCommit) {
994
+ args.push('--no-commit');
995
+ }
996
+ if (opts?.strategy) {
997
+ args.push('-s', opts.strategy);
998
+ }
999
+ if (opts?.strategyOption) {
1000
+ const strategyOpts = Array.isArray(opts.strategyOption)
1001
+ ? opts.strategyOption
1002
+ : [opts.strategyOption];
1003
+ for (const opt of strategyOpts) {
1004
+ args.push('-X', opt);
1005
+ }
1006
+ }
1007
+ if (opts?.noVerify) {
1008
+ args.push('--no-verify');
1009
+ }
1010
+ args.push(branch);
1011
+ const result = await this.runner.run(this.context, args, {
1012
+ signal: opts?.signal,
1013
+ });
1014
+ if (result.exitCode !== 0) {
1015
+ // Check for conflicts
1016
+ const statusResult = await this.runner.runOrThrow(this.context, ['status', '--porcelain'], {
1017
+ signal: opts?.signal,
1018
+ });
1019
+ const conflicts = parseLines(statusResult.stdout)
1020
+ .filter((line) => line.startsWith('UU ') || line.startsWith('AA ') || line.startsWith('DD '))
1021
+ .map((line) => line.slice(3));
1022
+ return {
1023
+ success: false,
1024
+ conflicts,
1025
+ };
1026
+ }
1027
+ // Get the new HEAD
1028
+ const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'], {
1029
+ signal: opts?.signal,
1030
+ });
1031
+ // Check if it was a fast-forward
1032
+ const fastForward = result.stdout.includes('Fast-forward') || result.stderr.includes('Fast-forward');
1033
+ return {
1034
+ success: true,
1035
+ hash: hashResult.stdout.trim(),
1036
+ fastForward,
1037
+ };
1038
+ }
1039
+ // ==========================================================================
1040
+ // High-level API - pull
1041
+ // ==========================================================================
1042
+ async pull(opts) {
1043
+ const args = ['pull'];
1044
+ if (opts?.onProgress) {
1045
+ args.push('--progress');
1046
+ }
1047
+ if (opts?.rebase === true) {
1048
+ args.push('--rebase');
1049
+ }
1050
+ else if (opts?.rebase === 'merges') {
1051
+ args.push('--rebase=merges');
1052
+ }
1053
+ else if (opts?.rebase === 'interactive') {
1054
+ args.push('--rebase=interactive');
1055
+ }
1056
+ if (opts?.ff === 'only') {
1057
+ args.push('--ff-only');
1058
+ }
1059
+ else if (opts?.ff === 'no' || opts?.ff === false) {
1060
+ args.push('--no-ff');
1061
+ }
1062
+ if (opts?.tags) {
1063
+ args.push('--tags');
1064
+ }
1065
+ if (opts?.prune) {
1066
+ args.push('--prune');
1067
+ }
1068
+ if (opts?.remote) {
1069
+ args.push(opts.remote);
1070
+ }
1071
+ if (opts?.branch) {
1072
+ args.push(opts.branch);
1073
+ }
1074
+ await this.runner.runOrThrow(this.context, args, {
1075
+ signal: opts?.signal,
1076
+ onProgress: opts?.onProgress,
1077
+ });
1078
+ }
1079
+ // ==========================================================================
1080
+ // High-level API - reset
1081
+ // ==========================================================================
1082
+ async reset(target, opts) {
1083
+ const args = ['reset'];
1084
+ if (opts?.mode) {
1085
+ args.push(`--${opts.mode}`);
1086
+ }
1087
+ if (target) {
1088
+ args.push(target);
1089
+ }
1090
+ await this.runner.runOrThrow(this.context, args, {
1091
+ signal: opts?.signal,
1092
+ });
1093
+ }
1094
+ // ==========================================================================
1095
+ // High-level API - rm
1096
+ // ==========================================================================
1097
+ async rm(paths, opts) {
1098
+ const args = ['rm'];
1099
+ if (opts?.force) {
1100
+ args.push('--force');
1101
+ }
1102
+ if (opts?.cached) {
1103
+ args.push('--cached');
1104
+ }
1105
+ if (opts?.recursive) {
1106
+ args.push('-r');
1107
+ }
1108
+ if (opts?.dryRun) {
1109
+ args.push('--dry-run');
1110
+ }
1111
+ const pathList = Array.isArray(paths) ? paths : [paths];
1112
+ args.push('--', ...pathList);
1113
+ await this.runner.runOrThrow(this.context, args, {
1114
+ signal: opts?.signal,
1115
+ });
1116
+ }
1117
+ // ==========================================================================
1118
+ // High-level API - Stash Operations
1119
+ // ==========================================================================
1120
+ async stashList(opts) {
1121
+ const result = await this.runner.runOrThrow(this.context, ['stash', 'list'], {
1122
+ signal: opts?.signal,
1123
+ });
1124
+ const entries = [];
1125
+ for (const line of parseLines(result.stdout)) {
1126
+ // Default format: stash@{0}: On branch: message
1127
+ // Or: stash@{0}: WIP on branch: hash (when using -m)
1128
+ const match = line.match(/^stash@\{(\d+)\}:\s*(?:On\s+)?(.+?):\s*(.+)$/);
1129
+ const indexStr = match?.[1];
1130
+ const branchOrContext = match?.[2];
1131
+ const message = match?.[3];
1132
+ if (indexStr !== undefined && message !== undefined) {
1133
+ // Check if branchOrContext includes "WIP on" format
1134
+ const wipMatch = branchOrContext?.match(/^WIP on (.+)$/);
1135
+ entries.push({
1136
+ index: Number.parseInt(indexStr, 10),
1137
+ message,
1138
+ branch: wipMatch?.[1] ?? branchOrContext,
1139
+ commit: '', // We'd need another command to get the commit hash
1140
+ });
1141
+ }
1142
+ }
1143
+ // Get commit hashes if entries were found
1144
+ if (entries.length > 0) {
1145
+ for (const entry of entries) {
1146
+ try {
1147
+ const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', `stash@{${entry.index}}`], { signal: opts?.signal });
1148
+ entry.commit = hashResult.stdout.trim();
1149
+ }
1150
+ catch {
1151
+ // Ignore errors getting commit hash
1152
+ }
1153
+ }
1154
+ }
1155
+ return entries;
1156
+ }
1157
+ async stashPush(opts) {
1158
+ const args = ['stash', 'push'];
1159
+ if (opts?.message) {
1160
+ args.push('-m', opts.message);
1161
+ }
1162
+ if (opts?.includeUntracked) {
1163
+ args.push('--include-untracked');
1164
+ }
1165
+ if (opts?.keepIndex) {
1166
+ args.push('--keep-index');
1167
+ }
1168
+ if (opts?.paths && opts.paths.length > 0) {
1169
+ args.push('--', ...opts.paths);
1170
+ }
1171
+ await this.runner.runOrThrow(this.context, args, {
1172
+ signal: opts?.signal,
1173
+ });
1174
+ }
1175
+ async stashPop(opts) {
1176
+ const args = ['stash', 'pop'];
1177
+ if (opts?.reinstateIndex) {
1178
+ args.push('--index');
1179
+ }
1180
+ if (opts?.index !== undefined) {
1181
+ args.push(`stash@{${opts.index}}`);
1182
+ }
1183
+ await this.runner.runOrThrow(this.context, args, {
1184
+ signal: opts?.signal,
1185
+ });
1186
+ }
1187
+ async stashApply(opts) {
1188
+ const args = ['stash', 'apply'];
1189
+ if (opts?.reinstateIndex) {
1190
+ args.push('--index');
1191
+ }
1192
+ if (opts?.index !== undefined) {
1193
+ args.push(`stash@{${opts.index}}`);
1194
+ }
1195
+ await this.runner.runOrThrow(this.context, args, {
1196
+ signal: opts?.signal,
1197
+ });
1198
+ }
1199
+ async stashDrop(index, opts) {
1200
+ const args = ['stash', 'drop'];
1201
+ if (index !== undefined) {
1202
+ args.push(`stash@{${index}}`);
1203
+ }
1204
+ await this.runner.runOrThrow(this.context, args, {
1205
+ signal: opts?.signal,
1206
+ });
1207
+ }
1208
+ async stashClear(opts) {
1209
+ await this.runner.runOrThrow(this.context, ['stash', 'clear'], {
1210
+ signal: opts?.signal,
1211
+ });
1212
+ }
1213
+ // ==========================================================================
1214
+ // High-level API - switch
1215
+ // ==========================================================================
1216
+ async switch(branch, opts) {
1217
+ const args = ['switch'];
1218
+ if (opts?.create) {
1219
+ args.push('-c');
1220
+ }
1221
+ else if (opts?.forceCreate) {
1222
+ args.push('-C');
1223
+ }
1224
+ if (opts?.discard) {
1225
+ args.push('--discard-changes');
1226
+ }
1227
+ if (opts?.track) {
1228
+ args.push('--track');
1229
+ }
1230
+ if (opts?.detach) {
1231
+ args.push('--detach');
1232
+ }
1233
+ args.push(branch);
1234
+ if (opts?.startPoint) {
1235
+ args.push(opts.startPoint);
1236
+ }
1237
+ await this.runner.runOrThrow(this.context, args, {
1238
+ signal: opts?.signal,
1239
+ });
1240
+ }
1241
+ // ==========================================================================
1242
+ // High-level API - Tag Operations
1243
+ // ==========================================================================
1244
+ async tagList(opts) {
1245
+ const args = ['tag', '--list'];
1246
+ if (opts?.sort) {
1247
+ args.push(`--sort=${opts.sort}`);
1248
+ }
1249
+ if (opts?.pattern) {
1250
+ args.push(opts.pattern);
1251
+ }
1252
+ const result = await this.runner.runOrThrow(this.context, args, {
1253
+ signal: opts?.signal,
1254
+ });
1255
+ return parseLines(result.stdout);
1256
+ }
1257
+ async tagCreate(name, opts) {
1258
+ const args = ['tag'];
1259
+ if (opts?.sign) {
1260
+ args.push('-s');
1261
+ }
1262
+ if (opts?.message) {
1263
+ // If signing with -s, we don't need -a (signed tags are always annotated)
1264
+ if (!opts.sign) {
1265
+ args.push('-a');
1266
+ }
1267
+ args.push('-m', opts.message);
1268
+ }
1269
+ if (opts?.force) {
1270
+ args.push('--force');
1271
+ }
1272
+ args.push(name);
1273
+ if (opts?.commit) {
1274
+ args.push(opts.commit);
1275
+ }
1276
+ await this.runner.runOrThrow(this.context, args, {
1277
+ signal: opts?.signal,
1278
+ });
1279
+ }
1280
+ async tagDelete(name, opts) {
1281
+ await this.runner.runOrThrow(this.context, ['tag', '-d', name], {
1282
+ signal: opts?.signal,
1283
+ });
1284
+ }
1285
+ async tagShow(name, opts) {
1286
+ // Try to get tag info using cat-file
1287
+ const typeResult = await this.runner.runOrThrow(this.context, ['cat-file', '-t', name], {
1288
+ signal: opts?.signal,
1289
+ });
1290
+ const isAnnotated = typeResult.stdout.trim() === 'tag';
1291
+ if (isAnnotated) {
1292
+ const result = await this.runner.runOrThrow(this.context, ['cat-file', 'tag', name], {
1293
+ signal: opts?.signal,
1294
+ });
1295
+ const lines = result.stdout.split('\n');
1296
+ let commit = '';
1297
+ let taggerName = '';
1298
+ let taggerEmail = '';
1299
+ let taggerDate;
1300
+ const messageLines = [];
1301
+ let inMessage = false;
1302
+ for (const line of lines) {
1303
+ if (line.startsWith('object ')) {
1304
+ commit = line.slice(7);
1305
+ }
1306
+ else if (line.startsWith('tagger ')) {
1307
+ const match = line.match(/^tagger (.+?) <(.+?)> (\d+)/);
1308
+ if (match) {
1309
+ const matchedName = match[1];
1310
+ const matchedEmail = match[2];
1311
+ const matchedTimestamp = match[3];
1312
+ if (matchedName !== undefined &&
1313
+ matchedEmail !== undefined &&
1314
+ matchedTimestamp !== undefined) {
1315
+ taggerName = matchedName;
1316
+ taggerEmail = matchedEmail;
1317
+ taggerDate = new Date(Number.parseInt(matchedTimestamp, 10) * 1000);
1318
+ }
1319
+ }
1320
+ }
1321
+ else if (line === '') {
1322
+ inMessage = true;
1323
+ }
1324
+ else if (inMessage) {
1325
+ messageLines.push(line);
1326
+ }
1327
+ }
1328
+ return {
1329
+ name,
1330
+ commit,
1331
+ annotated: true,
1332
+ message: messageLines.join('\n').trim() || undefined,
1333
+ tagger: taggerName && taggerDate
1334
+ ? {
1335
+ name: taggerName,
1336
+ email: taggerEmail,
1337
+ date: taggerDate,
1338
+ }
1339
+ : undefined,
1340
+ };
1341
+ }
1342
+ else {
1343
+ // Lightweight tag - get the commit it points to
1344
+ const result = await this.runner.runOrThrow(this.context, ['rev-parse', name], {
1345
+ signal: opts?.signal,
1346
+ });
1347
+ return {
1348
+ name,
1349
+ commit: result.stdout.trim(),
1350
+ annotated: false,
1351
+ };
1352
+ }
1353
+ }
1354
+ // ==========================================================================
1355
+ // Medium Priority - cherry-pick
1356
+ // ==========================================================================
1357
+ async cherryPick(commits, opts) {
1358
+ if (opts?.abort) {
1359
+ await this.runner.runOrThrow(this.context, ['cherry-pick', '--abort'], {
1360
+ signal: opts?.signal,
1361
+ });
1362
+ return;
1363
+ }
1364
+ if (opts?.continue) {
1365
+ await this.runner.runOrThrow(this.context, ['cherry-pick', '--continue'], {
1366
+ signal: opts?.signal,
1367
+ });
1368
+ return;
1369
+ }
1370
+ if (opts?.skip) {
1371
+ await this.runner.runOrThrow(this.context, ['cherry-pick', '--skip'], {
1372
+ signal: opts?.signal,
1373
+ });
1374
+ return;
1375
+ }
1376
+ const args = ['cherry-pick'];
1377
+ if (opts?.edit) {
1378
+ args.push('-e');
1379
+ }
1380
+ if (opts?.noCommit) {
1381
+ args.push('-n');
1382
+ }
1383
+ if (opts?.signoff) {
1384
+ args.push('-s');
1385
+ }
1386
+ if (opts?.mainline !== undefined) {
1387
+ args.push('-m', opts.mainline.toString());
1388
+ }
1389
+ if (opts?.strategy) {
1390
+ args.push('-s', opts.strategy);
1391
+ }
1392
+ if (opts?.noVerify) {
1393
+ args.push('--no-verify');
1394
+ }
1395
+ const commitList = Array.isArray(commits) ? commits : [commits];
1396
+ args.push(...commitList);
1397
+ await this.runner.runOrThrow(this.context, args, {
1398
+ signal: opts?.signal,
1399
+ });
1400
+ }
1401
+ // ==========================================================================
1402
+ // Medium Priority - clean
1403
+ // ==========================================================================
1404
+ async clean(opts) {
1405
+ const args = ['clean'];
1406
+ if (opts?.force) {
1407
+ args.push('-f');
1408
+ }
1409
+ if (opts?.directories) {
1410
+ args.push('-d');
1411
+ }
1412
+ if (opts?.ignored) {
1413
+ args.push('-x');
1414
+ }
1415
+ else if (opts?.onlyIgnored) {
1416
+ args.push('-X');
1417
+ }
1418
+ if (opts?.dryRun) {
1419
+ args.push('-n');
1420
+ }
1421
+ if (opts?.paths && opts.paths.length > 0) {
1422
+ args.push('--', ...opts.paths);
1423
+ }
1424
+ const result = await this.runner.runOrThrow(this.context, args, {
1425
+ signal: opts?.signal,
1426
+ });
1427
+ // Parse cleaned/would-be-cleaned paths from output
1428
+ const cleaned = [];
1429
+ for (const line of parseLines(result.stdout)) {
1430
+ // Output is like "Removing file.txt" or "Would remove file.txt"
1431
+ const match = line.match(/^(?:Removing|Would remove) (.+)$/);
1432
+ const matchedPath = match?.[1];
1433
+ if (matchedPath !== undefined) {
1434
+ cleaned.push(matchedPath);
1435
+ }
1436
+ }
1437
+ return cleaned;
1438
+ }
1439
+ // ==========================================================================
1440
+ // Medium Priority - mv
1441
+ // ==========================================================================
1442
+ async mv(source, destination, opts) {
1443
+ const args = ['mv'];
1444
+ if (opts?.force) {
1445
+ args.push('-f');
1446
+ }
1447
+ if (opts?.dryRun) {
1448
+ args.push('-n');
1449
+ }
1450
+ args.push(source, destination);
1451
+ await this.runner.runOrThrow(this.context, args, {
1452
+ signal: opts?.signal,
1453
+ });
1454
+ }
1455
+ // ==========================================================================
1456
+ // Medium Priority - rebase
1457
+ // ==========================================================================
1458
+ async rebase(opts) {
1459
+ if (opts?.abort) {
1460
+ await this.runner.runOrThrow(this.context, ['rebase', '--abort'], {
1461
+ signal: opts?.signal,
1462
+ });
1463
+ return;
1464
+ }
1465
+ if (opts?.continue) {
1466
+ await this.runner.runOrThrow(this.context, ['rebase', '--continue'], {
1467
+ signal: opts?.signal,
1468
+ });
1469
+ return;
1470
+ }
1471
+ if (opts?.skip) {
1472
+ await this.runner.runOrThrow(this.context, ['rebase', '--skip'], {
1473
+ signal: opts?.signal,
1474
+ });
1475
+ return;
1476
+ }
1477
+ const args = ['rebase'];
1478
+ if (opts?.onto) {
1479
+ args.push('--onto', opts.onto);
1480
+ }
1481
+ if (opts?.rebaseMerges) {
1482
+ args.push('--rebase-merges');
1483
+ }
1484
+ if (opts?.noVerify) {
1485
+ args.push('--no-verify');
1486
+ }
1487
+ if (opts?.upstream) {
1488
+ args.push(opts.upstream);
1489
+ }
1490
+ await this.runner.runOrThrow(this.context, args, {
1491
+ signal: opts?.signal,
1492
+ });
1493
+ }
1494
+ // ==========================================================================
1495
+ // Medium Priority - restore
1496
+ // ==========================================================================
1497
+ async restore(paths, opts) {
1498
+ const args = ['restore'];
1499
+ if (opts?.staged) {
1500
+ args.push('--staged');
1501
+ }
1502
+ if (opts?.worktree) {
1503
+ args.push('--worktree');
1504
+ }
1505
+ if (opts?.source) {
1506
+ args.push('--source', opts.source);
1507
+ }
1508
+ if (opts?.ours) {
1509
+ args.push('--ours');
1510
+ }
1511
+ else if (opts?.theirs) {
1512
+ args.push('--theirs');
1513
+ }
1514
+ const pathList = Array.isArray(paths) ? paths : [paths];
1515
+ args.push('--', ...pathList);
1516
+ await this.runner.runOrThrow(this.context, args, {
1517
+ signal: opts?.signal,
1518
+ });
1519
+ }
1520
+ // ==========================================================================
1521
+ // Medium Priority - revert
1522
+ // ==========================================================================
1523
+ async revert(commits, opts) {
1524
+ if (opts?.abort) {
1525
+ await this.runner.runOrThrow(this.context, ['revert', '--abort'], {
1526
+ signal: opts?.signal,
1527
+ });
1528
+ return;
1529
+ }
1530
+ if (opts?.continue) {
1531
+ await this.runner.runOrThrow(this.context, ['revert', '--continue'], {
1532
+ signal: opts?.signal,
1533
+ });
1534
+ return;
1535
+ }
1536
+ if (opts?.skip) {
1537
+ await this.runner.runOrThrow(this.context, ['revert', '--skip'], {
1538
+ signal: opts?.signal,
1539
+ });
1540
+ return;
1541
+ }
1542
+ const args = ['revert'];
1543
+ if (opts?.edit) {
1544
+ args.push('-e');
1545
+ }
1546
+ if (opts?.noCommit) {
1547
+ args.push('-n');
1548
+ }
1549
+ if (opts?.mainline !== undefined) {
1550
+ args.push('-m', opts.mainline.toString());
1551
+ }
1552
+ if (opts?.noVerify) {
1553
+ args.push('--no-verify');
1554
+ }
1555
+ const commitList = Array.isArray(commits) ? commits : [commits];
1556
+ args.push(...commitList);
1557
+ await this.runner.runOrThrow(this.context, args, {
1558
+ signal: opts?.signal,
1559
+ });
1560
+ }
1561
+ // ==========================================================================
1562
+ // Medium Priority - show
1563
+ // ==========================================================================
1564
+ async show(object, opts) {
1565
+ const args = ['show'];
1566
+ if (opts?.stat) {
1567
+ args.push('--stat');
1568
+ }
1569
+ if (opts?.nameOnly) {
1570
+ args.push('--name-only');
1571
+ }
1572
+ else if (opts?.nameStatus) {
1573
+ args.push('--name-status');
1574
+ }
1575
+ if (opts?.format) {
1576
+ args.push(`--format=${opts.format}`);
1577
+ }
1578
+ args.push(object);
1579
+ const result = await this.runner.runOrThrow(this.context, args, {
1580
+ signal: opts?.signal,
1581
+ });
1582
+ return result.stdout;
1583
+ }
1584
+ // ==========================================================================
1585
+ // Plumbing Operations
1586
+ // ==========================================================================
1587
+ /**
1588
+ * Parse revision specification and return the object name (SHA)
1589
+ */
1590
+ async revParse(ref, opts) {
1591
+ const result = await this.runner.runOrThrow(this.context, ['rev-parse', ref], {
1592
+ signal: opts?.signal,
1593
+ });
1594
+ return result.stdout.trim();
1595
+ }
1596
+ /**
1597
+ * Count the number of commits reachable from a ref
1598
+ */
1599
+ async revListCount(ref, opts) {
1600
+ const args = ['rev-list', '--count'];
1601
+ if (ref) {
1602
+ args.push(ref);
1603
+ }
1604
+ else {
1605
+ args.push('HEAD');
1606
+ }
1607
+ const result = await this.runner.runOrThrow(this.context, args, {
1608
+ signal: opts?.signal,
1609
+ });
1610
+ return Number.parseInt(result.stdout.trim(), 10);
1611
+ }
1612
+ /**
1613
+ * Read or modify symbolic refs
1614
+ */
1615
+ async symbolicRef(name, newRef, opts) {
1616
+ if (newRef !== undefined) {
1617
+ // Set the symbolic ref
1618
+ await this.runner.runOrThrow(this.context, ['symbolic-ref', name, newRef], {
1619
+ signal: opts?.signal,
1620
+ });
1621
+ return undefined;
1622
+ }
1623
+ // Read the symbolic ref
1624
+ const result = await this.runner.runOrThrow(this.context, ['symbolic-ref', name], {
1625
+ signal: opts?.signal,
1626
+ });
1627
+ return result.stdout.trim();
1628
+ }
1629
+ // ==========================================================================
1630
+ // Medium Priority - Submodule Operations
1631
+ // ==========================================================================
1632
+ async submoduleList(opts) {
1633
+ const result = await this.runner.run(this.context, ['submodule', 'status'], {
1634
+ signal: opts?.signal,
1635
+ });
1636
+ if (result.exitCode !== 0) {
1637
+ return [];
1638
+ }
1639
+ const submodules = [];
1640
+ for (const line of parseLines(result.stdout)) {
1641
+ // Format: [+-U ]<sha1> <path> (<describe>)
1642
+ const match = line.match(/^[ +-U]?([a-f0-9]+) (.+?)(?: \((.+)\))?$/);
1643
+ if (match) {
1644
+ const commit = match[1];
1645
+ const path = match[2];
1646
+ if (commit === undefined || path === undefined) {
1647
+ continue;
1648
+ }
1649
+ // Get URL from .gitmodules
1650
+ const urlResult = await this.runner.run(this.context, ['config', '-f', '.gitmodules', '--get', `submodule.${path}.url`], { signal: opts?.signal });
1651
+ const url = urlResult.exitCode === 0 ? urlResult.stdout.trim() : '';
1652
+ // Get branch if configured
1653
+ const branchResult = await this.runner.run(this.context, ['config', '-f', '.gitmodules', '--get', `submodule.${path}.branch`], { signal: opts?.signal });
1654
+ const branch = branchResult.exitCode === 0 ? branchResult.stdout.trim() : undefined;
1655
+ submodules.push({
1656
+ name: path,
1657
+ path: path,
1658
+ url,
1659
+ branch,
1660
+ commit: commit,
1661
+ });
1662
+ }
1663
+ }
1664
+ return submodules;
1665
+ }
1666
+ async submoduleInit(paths, opts) {
1667
+ const args = ['submodule', 'init'];
1668
+ if (paths && paths.length > 0) {
1669
+ args.push('--', ...paths);
1670
+ }
1671
+ await this.runner.runOrThrow(this.context, args, {
1672
+ signal: opts?.signal,
1673
+ });
1674
+ }
1675
+ async submoduleUpdate(opts) {
1676
+ const args = ['submodule', 'update'];
1677
+ if (opts?.init) {
1678
+ args.push('--init');
1679
+ }
1680
+ if (opts?.recursive) {
1681
+ args.push('--recursive');
1682
+ }
1683
+ if (opts?.remote) {
1684
+ args.push('--remote');
1685
+ }
1686
+ if (opts?.force) {
1687
+ args.push('--force');
1688
+ }
1689
+ await this.runner.runOrThrow(this.context, args, {
1690
+ signal: opts?.signal,
1691
+ });
1692
+ }
1693
+ async submoduleAdd(url, path, opts) {
1694
+ await this.runner.runOrThrow(this.context, ['submodule', 'add', url, path], {
1695
+ signal: opts?.signal,
1696
+ });
1697
+ }
1698
+ async submoduleDeinit(path, opts) {
1699
+ await this.runner.runOrThrow(this.context, ['submodule', 'deinit', path], {
1700
+ signal: opts?.signal,
1701
+ });
1702
+ }
1703
+ // ==========================================================================
1704
+ // Remote Operations
1705
+ // ==========================================================================
1706
+ async remoteList(opts) {
1707
+ const result = await this.runner.runOrThrow(this.context, ['remote', '-v'], {
1708
+ signal: opts?.signal,
1709
+ });
1710
+ const remotes = new Map();
1711
+ for (const line of parseLines(result.stdout)) {
1712
+ // Format: origin https://github.com/user/repo.git (fetch)
1713
+ // Format: origin https://github.com/user/repo.git (push)
1714
+ const match = line.match(/^(\S+)\t(.+?)\s+\((fetch|push)\)$/);
1715
+ if (match) {
1716
+ const name = match[1];
1717
+ const url = match[2];
1718
+ const type = match[3];
1719
+ if (name !== undefined && url !== undefined) {
1720
+ const existing = remotes.get(name);
1721
+ if (existing) {
1722
+ if (type === 'fetch') {
1723
+ existing.fetchUrl = url;
1724
+ }
1725
+ else if (type === 'push') {
1726
+ existing.pushUrl = url;
1727
+ }
1728
+ }
1729
+ else {
1730
+ remotes.set(name, {
1731
+ name,
1732
+ fetchUrl: type === 'fetch' ? url : '',
1733
+ pushUrl: type === 'push' ? url : '',
1734
+ });
1735
+ }
1736
+ }
1737
+ }
1738
+ }
1739
+ // Fill in missing URLs (they're often the same)
1740
+ for (const remote of remotes.values()) {
1741
+ if (!remote.fetchUrl && remote.pushUrl) {
1742
+ remote.fetchUrl = remote.pushUrl;
1743
+ }
1744
+ if (!remote.pushUrl && remote.fetchUrl) {
1745
+ remote.pushUrl = remote.fetchUrl;
1746
+ }
1747
+ }
1748
+ return Array.from(remotes.values());
1749
+ }
1750
+ async remoteAdd(name, url, opts) {
1751
+ const args = ['remote', 'add'];
1752
+ if (opts?.track) {
1753
+ args.push('-t', opts.track);
1754
+ }
1755
+ if (opts?.fetch) {
1756
+ args.push('-f');
1757
+ }
1758
+ if (opts?.mirror === 'fetch') {
1759
+ args.push('--mirror=fetch');
1760
+ }
1761
+ else if (opts?.mirror === 'push') {
1762
+ args.push('--mirror=push');
1763
+ }
1764
+ args.push(name, url);
1765
+ await this.runner.runOrThrow(this.context, args, {
1766
+ signal: opts?.signal,
1767
+ });
1768
+ }
1769
+ async remoteRemove(name, opts) {
1770
+ await this.runner.runOrThrow(this.context, ['remote', 'remove', name], {
1771
+ signal: opts?.signal,
1772
+ });
1773
+ }
1774
+ async remoteRename(oldName, newName, opts) {
1775
+ await this.runner.runOrThrow(this.context, ['remote', 'rename', oldName, newName], {
1776
+ signal: opts?.signal,
1777
+ });
1778
+ }
1779
+ async remoteGetUrl(name, opts) {
1780
+ const args = ['remote', 'get-url'];
1781
+ if (opts?.push) {
1782
+ args.push('--push');
1783
+ }
1784
+ args.push(name);
1785
+ const result = await this.runner.runOrThrow(this.context, args, {
1786
+ signal: opts?.signal,
1787
+ });
1788
+ return result.stdout.trim();
1789
+ }
1790
+ async remoteSetUrl(name, url, opts) {
1791
+ const args = ['remote', 'set-url'];
1792
+ if (opts?.push) {
1793
+ args.push('--push');
1794
+ }
1795
+ args.push(name, url);
1796
+ await this.runner.runOrThrow(this.context, args, {
1797
+ signal: opts?.signal,
1798
+ });
1799
+ }
1800
+ // ==========================================================================
1801
+ // Config Operations (Repository-level)
1802
+ // ==========================================================================
1803
+ /**
1804
+ * Get a typed config value
1805
+ */
1806
+ async configGet(key, opts) {
1807
+ const result = await this.runner.run(this.context, ['config', '--get', key], {
1808
+ signal: opts?.signal,
1809
+ });
1810
+ if (result.exitCode !== 0) {
1811
+ return undefined;
1812
+ }
1813
+ return result.stdout.trim();
1814
+ }
1815
+ /**
1816
+ * Get all values for a typed multi-valued config key
1817
+ */
1818
+ async configGetAll(key, opts) {
1819
+ const result = await this.runner.run(this.context, ['config', '--get-all', key], {
1820
+ signal: opts?.signal,
1821
+ });
1822
+ if (result.exitCode !== 0) {
1823
+ return [];
1824
+ }
1825
+ return parseLines(result.stdout);
1826
+ }
1827
+ /**
1828
+ * Set a typed config value
1829
+ */
1830
+ async configSet(key, value, opts) {
1831
+ await this.runner.runOrThrow(this.context, ['config', key, String(value)], {
1832
+ signal: opts?.signal,
1833
+ });
1834
+ }
1835
+ /**
1836
+ * Add a value to a typed multi-valued config key
1837
+ */
1838
+ async configAdd(key, value, opts) {
1839
+ await this.runner.runOrThrow(this.context, ['config', '--add', key, String(value)], {
1840
+ signal: opts?.signal,
1841
+ });
1842
+ }
1843
+ /**
1844
+ * Unset a typed config value
1845
+ */
1846
+ async configUnset(key, opts) {
1847
+ await this.runner.runOrThrow(this.context, ['config', '--unset', key], {
1848
+ signal: opts?.signal,
1849
+ });
1850
+ }
1851
+ /**
1852
+ * Get a raw config value (for arbitrary keys)
1853
+ */
1854
+ async configGetRaw(key, opts) {
1855
+ const args = ['config'];
1856
+ if (opts?.all) {
1857
+ args.push('--get-all');
1858
+ }
1859
+ else {
1860
+ args.push('--get');
1861
+ }
1862
+ args.push(key);
1863
+ const result = await this.runner.run(this.context, args, {
1864
+ signal: opts?.signal,
1865
+ });
1866
+ if (result.exitCode !== 0) {
1867
+ return undefined;
1868
+ }
1869
+ if (opts?.all) {
1870
+ return parseLines(result.stdout);
1871
+ }
1872
+ return result.stdout.trim();
1873
+ }
1874
+ /**
1875
+ * Set a raw config value (for arbitrary keys)
1876
+ */
1877
+ async configSetRaw(key, value, opts) {
1878
+ const args = ['config'];
1879
+ if (opts?.add) {
1880
+ args.push('--add');
1881
+ }
1882
+ args.push(key, value);
1883
+ await this.runner.runOrThrow(this.context, args, {
1884
+ signal: opts?.signal,
1885
+ });
1886
+ }
1887
+ /**
1888
+ * Unset a raw config value (for arbitrary keys)
1889
+ */
1890
+ async configUnsetRaw(key, opts) {
1891
+ await this.runner.runOrThrow(this.context, ['config', '--unset', key], {
1892
+ signal: opts?.signal,
1893
+ });
1894
+ }
1895
+ /**
1896
+ * List all config values
1897
+ */
1898
+ async configList(opts) {
1899
+ const args = ['config', '--list'];
1900
+ if (opts?.showOrigin) {
1901
+ args.push('--show-origin');
1902
+ }
1903
+ if (opts?.showScope) {
1904
+ args.push('--show-scope');
1905
+ }
1906
+ const result = await this.runner.runOrThrow(this.context, args, {
1907
+ signal: opts?.signal,
1908
+ });
1909
+ const entries = [];
1910
+ for (const line of parseLines(result.stdout)) {
1911
+ // Format: key=value or origin\tkey=value or scope\tkey=value
1912
+ // When showOrigin or showScope is used, there's a tab separator
1913
+ let keyValue = line;
1914
+ if (opts?.showOrigin || opts?.showScope) {
1915
+ const tabIndex = line.lastIndexOf('\t');
1916
+ if (tabIndex !== -1) {
1917
+ keyValue = line.slice(tabIndex + 1);
1918
+ }
1919
+ }
1920
+ const eqIndex = keyValue.indexOf('=');
1921
+ if (eqIndex !== -1) {
1922
+ entries.push({
1923
+ key: keyValue.slice(0, eqIndex),
1924
+ value: keyValue.slice(eqIndex + 1),
1925
+ });
1926
+ }
1927
+ }
1928
+ return entries;
1929
+ }
1930
+ }
1931
+ //# sourceMappingURL=worktree-repo-impl.js.map