type-git 0.0.2 → 0.1.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 (102) hide show
  1. package/README.md +33 -4
  2. package/dist/adapters/bun/index.cjs +421 -0
  3. package/dist/adapters/bun/index.cjs.map +1 -0
  4. package/dist/adapters/bun/index.d.cts +44 -0
  5. package/dist/adapters/bun/index.d.ts +38 -5
  6. package/dist/adapters/bun/index.js +388 -13
  7. package/dist/adapters/bun/index.js.map +1 -1
  8. package/dist/adapters/deno/index.cjs +472 -0
  9. package/dist/adapters/deno/index.cjs.map +1 -0
  10. package/dist/adapters/deno/index.d.cts +46 -0
  11. package/dist/adapters/deno/index.d.ts +40 -5
  12. package/dist/adapters/deno/index.js +439 -13
  13. package/dist/adapters/deno/index.js.map +1 -1
  14. package/dist/adapters/node/index.cjs +6254 -0
  15. package/dist/adapters/node/index.cjs.map +1 -0
  16. package/dist/{core/repo.d.ts → adapters/node/index.d.cts} +1452 -184
  17. package/dist/adapters/node/index.d.ts +4123 -13
  18. package/dist/adapters/node/index.js +6210 -119
  19. package/dist/adapters/node/index.js.map +1 -1
  20. package/dist/{core/types.d.ts → adapters-DehG3CsV.d.cts} +223 -29
  21. package/dist/adapters-DehG3CsV.d.ts +574 -0
  22. package/dist/index.cjs +6383 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +2 -0
  25. package/dist/index.d.ts +2 -9
  26. package/dist/index.js +6320 -13
  27. package/dist/index.js.map +1 -1
  28. package/package.json +13 -7
  29. package/dist/adapters/bun/exec.d.ts +0 -13
  30. package/dist/adapters/bun/exec.d.ts.map +0 -1
  31. package/dist/adapters/bun/exec.js +0 -242
  32. package/dist/adapters/bun/exec.js.map +0 -1
  33. package/dist/adapters/bun/fs.d.ts +0 -20
  34. package/dist/adapters/bun/fs.d.ts.map +0 -1
  35. package/dist/adapters/bun/fs.js +0 -148
  36. package/dist/adapters/bun/fs.js.map +0 -1
  37. package/dist/adapters/bun/index.d.ts.map +0 -1
  38. package/dist/adapters/deno/exec.d.ts +0 -14
  39. package/dist/adapters/deno/exec.d.ts.map +0 -1
  40. package/dist/adapters/deno/exec.js +0 -266
  41. package/dist/adapters/deno/exec.js.map +0 -1
  42. package/dist/adapters/deno/fs.d.ts +0 -21
  43. package/dist/adapters/deno/fs.d.ts.map +0 -1
  44. package/dist/adapters/deno/fs.js +0 -191
  45. package/dist/adapters/deno/fs.js.map +0 -1
  46. package/dist/adapters/deno/index.d.ts.map +0 -1
  47. package/dist/adapters/node/exec.d.ts +0 -11
  48. package/dist/adapters/node/exec.d.ts.map +0 -1
  49. package/dist/adapters/node/exec.js +0 -161
  50. package/dist/adapters/node/exec.js.map +0 -1
  51. package/dist/adapters/node/fs.d.ts +0 -18
  52. package/dist/adapters/node/fs.d.ts.map +0 -1
  53. package/dist/adapters/node/fs.js +0 -164
  54. package/dist/adapters/node/fs.js.map +0 -1
  55. package/dist/adapters/node/index.d.ts.map +0 -1
  56. package/dist/core/adapters.d.ts +0 -192
  57. package/dist/core/adapters.d.ts.map +0 -1
  58. package/dist/core/adapters.js +0 -10
  59. package/dist/core/adapters.js.map +0 -1
  60. package/dist/core/git.d.ts +0 -426
  61. package/dist/core/git.d.ts.map +0 -1
  62. package/dist/core/git.js +0 -5
  63. package/dist/core/git.js.map +0 -1
  64. package/dist/core/index.d.ts +0 -8
  65. package/dist/core/index.d.ts.map +0 -1
  66. package/dist/core/index.js +0 -8
  67. package/dist/core/index.js.map +0 -1
  68. package/dist/core/repo.d.ts.map +0 -1
  69. package/dist/core/repo.js +0 -5
  70. package/dist/core/repo.js.map +0 -1
  71. package/dist/core/types.d.ts.map +0 -1
  72. package/dist/core/types.js +0 -100
  73. package/dist/core/types.js.map +0 -1
  74. package/dist/impl/bare-repo-impl.d.ts +0 -91
  75. package/dist/impl/bare-repo-impl.d.ts.map +0 -1
  76. package/dist/impl/bare-repo-impl.js +0 -446
  77. package/dist/impl/bare-repo-impl.js.map +0 -1
  78. package/dist/impl/git-impl.d.ts +0 -125
  79. package/dist/impl/git-impl.d.ts.map +0 -1
  80. package/dist/impl/git-impl.js +0 -554
  81. package/dist/impl/git-impl.js.map +0 -1
  82. package/dist/impl/index.d.ts +0 -7
  83. package/dist/impl/index.d.ts.map +0 -1
  84. package/dist/impl/index.js +0 -7
  85. package/dist/impl/index.js.map +0 -1
  86. package/dist/impl/worktree-repo-impl.d.ts +0 -226
  87. package/dist/impl/worktree-repo-impl.d.ts.map +0 -1
  88. package/dist/impl/worktree-repo-impl.js +0 -3887
  89. package/dist/impl/worktree-repo-impl.js.map +0 -1
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/parsers/index.d.ts +0 -230
  92. package/dist/parsers/index.d.ts.map +0 -1
  93. package/dist/parsers/index.js +0 -529
  94. package/dist/parsers/index.js.map +0 -1
  95. package/dist/runner/cli-runner.d.ts +0 -94
  96. package/dist/runner/cli-runner.d.ts.map +0 -1
  97. package/dist/runner/cli-runner.js +0 -315
  98. package/dist/runner/cli-runner.js.map +0 -1
  99. package/dist/runner/index.d.ts +0 -5
  100. package/dist/runner/index.d.ts.map +0 -1
  101. package/dist/runner/index.js +0 -5
  102. package/dist/runner/index.js.map +0 -1
@@ -1,125 +0,0 @@
1
- /**
2
- * Git implementation - repository-agnostic operations
3
- */
4
- import type { RuntimeAdapters } from '../core/adapters.js';
5
- import type { CloneOpts, Git, GlobalConfigOperations, GlobalLfsOperations, InitOpts, LsRemoteOpts, LsRemoteResult } from '../core/git.js';
6
- import type { BareRepo, WorktreeRepo } from '../core/repo.js';
7
- import type { ExecOpts, GitOpenOptions, RawResult } from '../core/types.js';
8
- import { type CliRunnerOptions } from '../runner/cli-runner.js';
9
- /**
10
- * Options for creating a Git instance
11
- */
12
- export type CreateGitOptions = CliRunnerOptions & {
13
- /** Runtime adapters (exec, fs) */
14
- adapters: RuntimeAdapters;
15
- };
16
- /**
17
- * Git implementation
18
- */
19
- export declare class GitImpl implements Git {
20
- private readonly runner;
21
- private readonly adapters;
22
- readonly config: GlobalConfigOperations;
23
- readonly lfs: GlobalLfsOperations;
24
- constructor(options: CreateGitOptions);
25
- /**
26
- * Open an existing worktree repository
27
- * Throws GitError if the repository is bare.
28
- */
29
- open(path: string, opts?: GitOpenOptions): Promise<WorktreeRepo>;
30
- /**
31
- * Open an existing bare repository
32
- * Throws GitError if the repository is not bare.
33
- */
34
- openBare(path: string, opts?: GitOpenOptions): Promise<BareRepo>;
35
- /**
36
- * Open an existing repository without type guarantee
37
- * Returns either WorktreeRepo or BareRepo depending on the repository type.
38
- */
39
- openRaw(path: string, opts?: GitOpenOptions): Promise<WorktreeRepo | BareRepo>;
40
- /**
41
- * Clone a repository
42
- */
43
- clone(url: string, path: string, opts: CloneOpts & {
44
- bare: true;
45
- } & ExecOpts): Promise<BareRepo>;
46
- clone(url: string, path: string, opts: CloneOpts & {
47
- mirror: true;
48
- } & ExecOpts): Promise<BareRepo>;
49
- clone(url: string, path: string, opts?: CloneOpts & ExecOpts): Promise<WorktreeRepo>;
50
- /**
51
- * Initialize a new repository
52
- */
53
- init(path: string, opts: InitOpts & {
54
- bare: true;
55
- } & ExecOpts): Promise<BareRepo>;
56
- init(path: string, opts?: InitOpts & ExecOpts): Promise<WorktreeRepo>;
57
- /**
58
- * List references in a remote repository
59
- */
60
- lsRemote(url: string, opts?: LsRemoteOpts & ExecOpts): Promise<LsRemoteResult>;
61
- /**
62
- * Get git version
63
- */
64
- version(opts?: ExecOpts): Promise<string>;
65
- /**
66
- * Execute a raw git command (repository-agnostic)
67
- */
68
- raw(argv: Array<string>, opts?: ExecOpts): Promise<RawResult>;
69
- /**
70
- * Get a typed global config value
71
- */
72
- private configGet;
73
- /**
74
- * Get all values for a typed multi-valued global config key
75
- */
76
- private configGetAll;
77
- /**
78
- * Set a typed global config value
79
- */
80
- private configSet;
81
- /**
82
- * Add a value to a typed multi-valued global config key
83
- */
84
- private configAdd;
85
- /**
86
- * Unset a typed global config value
87
- */
88
- private configUnset;
89
- /**
90
- * Get a raw global config value (for arbitrary keys)
91
- */
92
- private configGetRaw;
93
- /**
94
- * Set a raw global config value (for arbitrary keys)
95
- */
96
- private configSetRaw;
97
- /**
98
- * Unset a raw global config value (for arbitrary keys)
99
- */
100
- private configUnsetRaw;
101
- /**
102
- * List all global config values
103
- */
104
- private configList;
105
- /**
106
- * Install Git LFS hooks globally
107
- */
108
- private lfsInstall;
109
- /**
110
- * Uninstall Git LFS hooks globally
111
- */
112
- private lfsUninstall;
113
- /**
114
- * Get Git LFS version
115
- */
116
- private lfsVersion;
117
- }
118
- /**
119
- * Create a new Git instance
120
- *
121
- * @param options - Creation options including runtime adapters
122
- * @returns Git instance
123
- */
124
- export declare function createGit(options: CreateGitOptions): Git;
125
- //# sourceMappingURL=git-impl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"git-impl.d.ts","sourceRoot":"","sources":["../../src/impl/git-impl.ts"],"names":[],"mappings":"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"}
@@ -1,554 +0,0 @@
1
- /**
2
- * Git implementation - repository-agnostic operations
3
- */
4
- import { GitError } from '../core/types.js';
5
- import { parseLines, parseLsRemote } from '../parsers/index.js';
6
- import { CliRunner } from '../runner/cli-runner.js';
7
- import { BareRepoImpl } from './bare-repo-impl.js';
8
- import { WorktreeRepoImpl } from './worktree-repo-impl.js';
9
- /**
10
- * Convert GitOpenOptions to CliRunnerOptions
11
- */
12
- function toCliRunnerOptions(opts) {
13
- if (!opts) {
14
- return {};
15
- }
16
- return {
17
- env: opts.env,
18
- pathPrefix: opts.pathPrefix,
19
- home: opts.home,
20
- credential: opts.credential
21
- ? {
22
- helper: opts.credential.helper,
23
- helperPath: opts.credential.helperPath,
24
- }
25
- : undefined,
26
- };
27
- }
28
- /**
29
- * Git implementation
30
- */
31
- export class GitImpl {
32
- runner;
33
- adapters;
34
- config;
35
- lfs;
36
- constructor(options) {
37
- this.runner = new CliRunner(options.adapters, options);
38
- this.adapters = options.adapters;
39
- // Initialize global config operations
40
- this.config = {
41
- get: this.configGet.bind(this),
42
- getAll: this.configGetAll.bind(this),
43
- set: this.configSet.bind(this),
44
- add: this.configAdd.bind(this),
45
- unset: this.configUnset.bind(this),
46
- getRaw: this.configGetRaw.bind(this),
47
- setRaw: this.configSetRaw.bind(this),
48
- unsetRaw: this.configUnsetRaw.bind(this),
49
- list: this.configList.bind(this),
50
- };
51
- // Initialize global LFS operations
52
- this.lfs = {
53
- install: this.lfsInstall.bind(this),
54
- uninstall: this.lfsUninstall.bind(this),
55
- version: this.lfsVersion.bind(this),
56
- };
57
- }
58
- /**
59
- * Open an existing worktree repository
60
- * Throws GitError if the repository is bare.
61
- */
62
- async open(path, opts) {
63
- const repo = await this.openRaw(path, opts);
64
- if (!('workdir' in repo)) {
65
- throw new GitError('NotWorktreeRepo', `Expected worktree repository but found bare repository: ${path}`, {
66
- gitDir: path,
67
- });
68
- }
69
- return repo;
70
- }
71
- /**
72
- * Open an existing bare repository
73
- * Throws GitError if the repository is not bare.
74
- */
75
- async openBare(path, opts) {
76
- const repo = await this.openRaw(path, opts);
77
- if ('workdir' in repo) {
78
- throw new GitError('NotBareRepo', `Expected bare repository but found worktree repository: ${path}`, {
79
- workdir: path,
80
- });
81
- }
82
- return repo;
83
- }
84
- /**
85
- * Open an existing repository without type guarantee
86
- * Returns either WorktreeRepo or BareRepo depending on the repository type.
87
- */
88
- async openRaw(path, opts) {
89
- // Create a runner with custom options if provided
90
- const repoRunner = opts ? this.runner.withOptions(toCliRunnerOptions(opts)) : this.runner;
91
- // Check if it's a bare repository
92
- const result = await repoRunner.run({ type: 'worktree', workdir: path }, [
93
- 'rev-parse',
94
- '--is-bare-repository',
95
- ]);
96
- if (result.exitCode !== 0) {
97
- // Try as git-dir directly
98
- const bareResult = await repoRunner.run({ type: 'bare', gitDir: path }, [
99
- 'rev-parse',
100
- '--is-bare-repository',
101
- ]);
102
- if (bareResult.exitCode !== 0) {
103
- throw new GitError('NonZeroExit', `Not a git repository: ${path}`, {
104
- exitCode: bareResult.exitCode,
105
- stderr: bareResult.stderr,
106
- });
107
- }
108
- if (bareResult.stdout.trim() === 'true') {
109
- return new BareRepoImpl(repoRunner, path, opts);
110
- }
111
- }
112
- const isBare = result.stdout.trim() === 'true';
113
- if (isBare) {
114
- // For bare repositories, use the path directly as gitDir
115
- // (git-dir is typically '.' when queried from within a bare repo)
116
- return new BareRepoImpl(repoRunner, path, opts);
117
- }
118
- return new WorktreeRepoImpl(repoRunner, path, opts);
119
- }
120
- async clone(url, path, opts) {
121
- const args = ['clone'];
122
- // Add progress flag for progress tracking
123
- if (opts?.onProgress) {
124
- args.push('--progress');
125
- }
126
- // Verbosity options
127
- if (opts?.verbose) {
128
- args.push('--verbose');
129
- }
130
- if (opts?.quiet) {
131
- args.push('--quiet');
132
- }
133
- // Repository type options
134
- if (opts?.bare) {
135
- args.push('--bare');
136
- }
137
- if (opts?.mirror) {
138
- args.push('--mirror');
139
- }
140
- // Shallow clone options
141
- if (opts?.depth !== undefined) {
142
- args.push('--depth', String(opts.depth));
143
- }
144
- if (opts?.shallowSince) {
145
- const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
146
- args.push('--shallow-since', since);
147
- }
148
- if (opts?.shallowExclude) {
149
- const excludes = Array.isArray(opts.shallowExclude)
150
- ? opts.shallowExclude
151
- : [opts.shallowExclude];
152
- for (const exclude of excludes) {
153
- args.push('--shallow-exclude', exclude);
154
- }
155
- }
156
- if (opts?.rejectShallow) {
157
- args.push('--reject-shallow');
158
- }
159
- // Branch options
160
- if (opts?.branch) {
161
- args.push('--branch', opts.branch);
162
- }
163
- if (opts?.singleBranch) {
164
- args.push('--single-branch');
165
- }
166
- // Checkout options
167
- if (opts?.noCheckout) {
168
- args.push('--no-checkout');
169
- }
170
- if (opts?.sparse) {
171
- args.push('--sparse');
172
- }
173
- // Local clone options
174
- if (opts?.local) {
175
- args.push('--local');
176
- }
177
- if (opts?.noHardlinks) {
178
- args.push('--no-hardlinks');
179
- }
180
- if (opts?.shared) {
181
- args.push('--shared');
182
- }
183
- // Reference options
184
- if (opts?.reference) {
185
- args.push('--reference', opts.reference);
186
- }
187
- if (opts?.referenceIfAble) {
188
- args.push('--reference-if-able', opts.referenceIfAble);
189
- }
190
- if (opts?.dissociate) {
191
- args.push('--dissociate');
192
- }
193
- // Submodule options
194
- if (opts?.recurseSubmodules) {
195
- args.push('--recurse-submodules');
196
- }
197
- if (opts?.shallowSubmodules) {
198
- args.push('--shallow-submodules');
199
- }
200
- if (opts?.remoteSubmodules) {
201
- args.push('--remote-submodules');
202
- }
203
- if (opts?.jobs !== undefined) {
204
- args.push('--jobs', String(opts.jobs));
205
- }
206
- // Tag options
207
- if (opts?.noTags) {
208
- args.push('--no-tags');
209
- }
210
- // Template and config options
211
- if (opts?.template) {
212
- args.push('--template', opts.template);
213
- }
214
- if (opts?.origin) {
215
- args.push('--origin', opts.origin);
216
- }
217
- if (opts?.separateGitDir) {
218
- args.push('--separate-git-dir', opts.separateGitDir);
219
- }
220
- if (opts?.config) {
221
- for (const [key, value] of Object.entries(opts.config)) {
222
- args.push('-c', `${key}=${value}`);
223
- }
224
- }
225
- // Partial clone options
226
- if (opts?.filter) {
227
- args.push('--filter', opts.filter);
228
- }
229
- if (opts?.alsoFilterSubmodules) {
230
- args.push('--also-filter-submodules');
231
- }
232
- // Network options
233
- if (opts?.ipv4) {
234
- args.push('--ipv4');
235
- }
236
- if (opts?.ipv6) {
237
- args.push('--ipv6');
238
- }
239
- args.push(url, path);
240
- try {
241
- await this.runner.runOrThrow({ type: 'global' }, args, {
242
- signal: opts?.signal,
243
- onProgress: opts?.onProgress,
244
- });
245
- }
246
- catch (error) {
247
- // Clean up on abort if cleanupOnAbort is true (default)
248
- if (error instanceof GitError && error.kind === 'Aborted' && opts?.cleanupOnAbort !== false) {
249
- await this.adapters.fs.deleteDirectory(path);
250
- }
251
- throw error;
252
- }
253
- // Return the appropriate repo type
254
- if (opts?.bare || opts?.mirror) {
255
- return new BareRepoImpl(this.runner, path);
256
- }
257
- return new WorktreeRepoImpl(this.runner, path);
258
- }
259
- async init(path, opts) {
260
- const args = ['init'];
261
- // Quiet mode
262
- if (opts?.quiet) {
263
- args.push('--quiet');
264
- }
265
- // Repository type
266
- if (opts?.bare) {
267
- args.push('--bare');
268
- }
269
- // Template
270
- if (opts?.template) {
271
- args.push('--template', opts.template);
272
- }
273
- // Sharing
274
- if (opts?.shared !== undefined) {
275
- if (typeof opts.shared === 'boolean') {
276
- if (opts.shared) {
277
- args.push('--shared');
278
- }
279
- }
280
- else if (typeof opts.shared === 'number') {
281
- args.push(`--shared=${opts.shared.toString(8)}`);
282
- }
283
- else {
284
- args.push(`--shared=${opts.shared}`);
285
- }
286
- }
287
- // Initial branch
288
- if (opts?.initialBranch) {
289
- args.push('--initial-branch', opts.initialBranch);
290
- }
291
- // Object format
292
- if (opts?.objectFormat) {
293
- args.push('--object-format', opts.objectFormat);
294
- }
295
- // Separate git dir
296
- if (opts?.separateGitDir) {
297
- args.push('--separate-git-dir', opts.separateGitDir);
298
- }
299
- args.push(path);
300
- try {
301
- await this.runner.runOrThrow({ type: 'global' }, args, {
302
- signal: opts?.signal,
303
- onProgress: opts?.onProgress,
304
- });
305
- }
306
- catch (error) {
307
- // Clean up on abort if cleanupOnAbort is true (default)
308
- if (error instanceof GitError && error.kind === 'Aborted' && opts?.cleanupOnAbort !== false) {
309
- await this.adapters.fs.deleteDirectory(path);
310
- }
311
- throw error;
312
- }
313
- if (opts?.bare) {
314
- return new BareRepoImpl(this.runner, path);
315
- }
316
- return new WorktreeRepoImpl(this.runner, path);
317
- }
318
- /**
319
- * List references in a remote repository
320
- */
321
- async lsRemote(url, opts) {
322
- const args = ['ls-remote'];
323
- // Ref type filters
324
- if (opts?.heads) {
325
- args.push('--heads');
326
- }
327
- if (opts?.tags) {
328
- args.push('--tags');
329
- }
330
- if (opts?.refs) {
331
- args.push('--refs');
332
- }
333
- // New options
334
- if (opts?.getUrl) {
335
- args.push('--get-url');
336
- }
337
- if (opts?.sort) {
338
- args.push('--sort', opts.sort);
339
- }
340
- if (opts?.symref) {
341
- args.push('--symref');
342
- }
343
- args.push(url);
344
- const result = await this.runner.runOrThrow({ type: 'global' }, args, {
345
- signal: opts?.signal,
346
- onProgress: opts?.onProgress,
347
- });
348
- const refs = parseLsRemote(result.stdout);
349
- return { refs };
350
- }
351
- /**
352
- * Get git version
353
- */
354
- async version(opts) {
355
- const result = await this.runner.runOrThrow({ type: 'global' }, ['--version'], {
356
- signal: opts?.signal,
357
- });
358
- // Parse "git version X.Y.Z" format
359
- const match = result.stdout.match(/git version (\S+)/);
360
- const version = match?.[1];
361
- return version ?? result.stdout.trim();
362
- }
363
- /**
364
- * Execute a raw git command (repository-agnostic)
365
- */
366
- async raw(argv, opts) {
367
- return this.runner.run({ type: 'global' }, argv, opts);
368
- }
369
- // ==========================================================================
370
- // Global Config Operations
371
- // ==========================================================================
372
- /**
373
- * Get a typed global config value
374
- */
375
- async configGet(key, opts) {
376
- const result = await this.runner.run({ type: 'global' }, ['config', '--global', '--get', key], {
377
- signal: opts?.signal,
378
- });
379
- if (result.exitCode !== 0) {
380
- return undefined;
381
- }
382
- return result.stdout.trim();
383
- }
384
- /**
385
- * Get all values for a typed multi-valued global config key
386
- */
387
- async configGetAll(key, opts) {
388
- const result = await this.runner.run({ type: 'global' }, ['config', '--global', '--get-all', key], { signal: opts?.signal });
389
- if (result.exitCode !== 0) {
390
- return [];
391
- }
392
- return parseLines(result.stdout);
393
- }
394
- /**
395
- * Set a typed global config value
396
- */
397
- async configSet(key, value, opts) {
398
- await this.runner.runOrThrow({ type: 'global' }, ['config', '--global', key, String(value)], {
399
- signal: opts?.signal,
400
- });
401
- }
402
- /**
403
- * Add a value to a typed multi-valued global config key
404
- */
405
- async configAdd(key, value, opts) {
406
- await this.runner.runOrThrow({ type: 'global' }, ['config', '--global', '--add', key, String(value)], { signal: opts?.signal });
407
- }
408
- /**
409
- * Unset a typed global config value
410
- */
411
- async configUnset(key, opts) {
412
- await this.runner.runOrThrow({ type: 'global' }, ['config', '--global', '--unset', key], {
413
- signal: opts?.signal,
414
- });
415
- }
416
- /**
417
- * Get a raw global config value (for arbitrary keys)
418
- */
419
- async configGetRaw(key, opts) {
420
- const args = ['config', '--global'];
421
- if (opts?.all) {
422
- args.push('--get-all');
423
- }
424
- else {
425
- args.push('--get');
426
- }
427
- args.push(key);
428
- const result = await this.runner.run({ type: 'global' }, args, {
429
- signal: opts?.signal,
430
- });
431
- if (result.exitCode !== 0) {
432
- return undefined;
433
- }
434
- if (opts?.all) {
435
- return parseLines(result.stdout);
436
- }
437
- return result.stdout.trim();
438
- }
439
- /**
440
- * Set a raw global config value (for arbitrary keys)
441
- */
442
- async configSetRaw(key, value, opts) {
443
- const args = ['config', '--global'];
444
- if (opts?.add) {
445
- args.push('--add');
446
- }
447
- args.push(key, value);
448
- await this.runner.runOrThrow({ type: 'global' }, args, {
449
- signal: opts?.signal,
450
- });
451
- }
452
- /**
453
- * Unset a raw global config value (for arbitrary keys)
454
- */
455
- async configUnsetRaw(key, opts) {
456
- await this.runner.runOrThrow({ type: 'global' }, ['config', '--global', '--unset', key], {
457
- signal: opts?.signal,
458
- });
459
- }
460
- /**
461
- * List all global config values
462
- */
463
- async configList(opts) {
464
- const args = ['config', '--global', '--list'];
465
- if (opts?.showOrigin) {
466
- args.push('--show-origin');
467
- }
468
- if (opts?.showScope) {
469
- args.push('--show-scope');
470
- }
471
- const result = await this.runner.runOrThrow({ type: 'global' }, args, {
472
- signal: opts?.signal,
473
- });
474
- const entries = [];
475
- for (const line of parseLines(result.stdout)) {
476
- let keyValue = line;
477
- if (opts?.showOrigin || opts?.showScope) {
478
- const tabIndex = line.lastIndexOf('\t');
479
- if (tabIndex !== -1) {
480
- keyValue = line.slice(tabIndex + 1);
481
- }
482
- }
483
- const eqIndex = keyValue.indexOf('=');
484
- if (eqIndex !== -1) {
485
- entries.push({
486
- key: keyValue.slice(0, eqIndex),
487
- value: keyValue.slice(eqIndex + 1),
488
- });
489
- }
490
- }
491
- return entries;
492
- }
493
- // ==========================================================================
494
- // Global LFS Operations
495
- // ==========================================================================
496
- /**
497
- * Install Git LFS hooks globally
498
- */
499
- async lfsInstall(opts) {
500
- const args = ['lfs', 'install'];
501
- if (opts?.force) {
502
- args.push('--force');
503
- }
504
- if (opts?.system) {
505
- args.push('--system');
506
- }
507
- if (opts?.skipSmudge) {
508
- args.push('--skip-smudge');
509
- }
510
- if (opts?.skipRepo) {
511
- args.push('--skip-repo');
512
- }
513
- if (opts?.manual) {
514
- args.push('--manual');
515
- }
516
- await this.runner.runOrThrow({ type: 'global' }, args, {
517
- signal: opts?.signal,
518
- });
519
- }
520
- /**
521
- * Uninstall Git LFS hooks globally
522
- */
523
- async lfsUninstall(opts) {
524
- const args = ['lfs', 'uninstall'];
525
- if (opts?.system) {
526
- args.push('--system');
527
- }
528
- if (opts?.skipRepo) {
529
- args.push('--skip-repo');
530
- }
531
- await this.runner.runOrThrow({ type: 'global' }, args, {
532
- signal: opts?.signal,
533
- });
534
- }
535
- /**
536
- * Get Git LFS version
537
- */
538
- async lfsVersion(opts) {
539
- const result = await this.runner.runOrThrow({ type: 'global' }, ['lfs', 'version'], {
540
- signal: opts?.signal,
541
- });
542
- return result.stdout.trim();
543
- }
544
- }
545
- /**
546
- * Create a new Git instance
547
- *
548
- * @param options - Creation options including runtime adapters
549
- * @returns Git instance
550
- */
551
- export function createGit(options) {
552
- return new GitImpl(options);
553
- }
554
- //# sourceMappingURL=git-impl.js.map