just-git 1.1.11 → 1.2.3

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.
@@ -1,30 +1,91 @@
1
+ /** File/directory metadata returned by {@link FileSystem.stat} and {@link FileSystem.lstat}. */
1
2
  interface FileStat {
3
+ /** True if the path points to a regular file. */
2
4
  isFile: boolean;
5
+ /** True if the path points to a directory. */
3
6
  isDirectory: boolean;
7
+ /** True if the path is a symbolic link (only meaningful from {@link FileSystem.lstat}). */
4
8
  isSymbolicLink: boolean;
9
+ /** Unix file mode (e.g. `0o100644` for a regular file, `0o040755` for a directory). */
5
10
  mode: number;
11
+ /** File size in bytes (0 for directories). */
6
12
  size: number;
13
+ /** Last modification time. */
7
14
  mtime: Date;
8
15
  }
16
+ /**
17
+ * Filesystem interface required by just-git.
18
+ *
19
+ * Implement this to run git operations against any storage backend —
20
+ * in-memory, real disk, IndexedDB, remote, etc. All paths are absolute
21
+ * POSIX-style strings (e.g. `"/repo/src/index.ts"`).
22
+ *
23
+ * The three optional symlink methods (`lstat`, `readlink`, `symlink`) enable
24
+ * symlink support. When omitted, symlinks degrade to plain files containing
25
+ * the target path as content (`core.symlinks=false` behavior).
26
+ *
27
+ * See {@link MemoryFileSystem} for a ready-made in-memory implementation.
28
+ */
9
29
  interface FileSystem {
30
+ /**
31
+ * Read a file's contents as a UTF-8 string.
32
+ * @throws Error if the path doesn't exist or is a directory.
33
+ */
10
34
  readFile(path: string): Promise<string>;
35
+ /**
36
+ * Read a file's contents as raw bytes.
37
+ * @throws Error if the path doesn't exist or is a directory.
38
+ */
11
39
  readFileBuffer(path: string): Promise<Uint8Array>;
40
+ /**
41
+ * Write content to a file, creating it if it doesn't exist and
42
+ * overwriting if it does. Parent directories must already exist.
43
+ */
12
44
  writeFile(path: string, content: string | Uint8Array): Promise<void>;
45
+ /** Check whether a path exists (file, directory, or symlink). */
13
46
  exists(path: string): Promise<boolean>;
47
+ /**
48
+ * Get file/directory metadata, following symlinks.
49
+ * @throws Error if the path doesn't exist.
50
+ */
14
51
  stat(path: string): Promise<FileStat>;
52
+ /**
53
+ * Create a directory.
54
+ * @throws Error if the parent doesn't exist (unless `recursive: true`) or the path already exists as a file.
55
+ */
15
56
  mkdir(path: string, options?: {
16
57
  recursive?: boolean;
17
58
  }): Promise<void>;
59
+ /**
60
+ * List the names of entries in a directory (not full paths).
61
+ * @throws Error if the path doesn't exist or is not a directory.
62
+ */
18
63
  readdir(path: string): Promise<string[]>;
64
+ /**
65
+ * Remove a file or directory.
66
+ * @throws Error if the path doesn't exist (unless `force: true`) or is a non-empty directory (unless `recursive: true`).
67
+ */
19
68
  rm(path: string, options?: {
20
69
  recursive?: boolean;
21
70
  force?: boolean;
22
71
  }): Promise<void>;
23
- /** Stat without following symlinks. Falls back to stat() semantics when not implemented. */
72
+ /**
73
+ * Get file/directory metadata without following symlinks.
74
+ * Falls back to {@link stat} semantics when not implemented.
75
+ * @throws Error if the path doesn't exist.
76
+ */
24
77
  lstat?(path: string): Promise<FileStat>;
25
- /** Read the target of a symbolic link. */
78
+ /**
79
+ * Read the target path of a symbolic link.
80
+ * @throws Error if the path doesn't exist or is not a symlink.
81
+ */
26
82
  readlink?(path: string): Promise<string>;
27
- /** Create a symbolic link pointing to target at the given path. */
83
+ /**
84
+ * Create a symbolic link at `path` pointing to `target`.
85
+ * @param target - The path the symlink should point to.
86
+ * @param path - Where to create the symlink.
87
+ * @throws Error if `path` already exists.
88
+ */
28
89
  symlink?(target: string, path: string): Promise<void>;
29
90
  }
30
91
 
@@ -91,6 +152,7 @@ interface Index {
91
152
  version: number;
92
153
  entries: IndexEntry[];
93
154
  }
155
+ /** A resolved ref name and its target commit hash. */
94
156
  interface RefEntry {
95
157
  name: string;
96
158
  hash: ObjectId;
@@ -186,6 +248,8 @@ interface GitContext extends GitRepo {
186
248
  networkPolicy?: NetworkPolicy | false;
187
249
  /** Resolves remote URLs to GitRepos on potentially different VFS instances. */
188
250
  resolveRemote?: RemoteResolver;
251
+ /** Operator-provided config overrides (locked values + defaults). */
252
+ configOverrides?: ConfigOverrides;
189
253
  }
190
254
  type DiffStatus = "added" | "deleted" | "modified";
191
255
  interface TreeDiffEntry {
@@ -199,6 +263,7 @@ interface TreeDiffEntry {
199
263
  newMode?: string;
200
264
  }
201
265
 
266
+ /** HTTP authentication credentials for Smart HTTP transport. */
202
267
  type HttpAuth = {
203
268
  type: "basic";
204
269
  username: string;
@@ -208,19 +273,52 @@ type HttpAuth = {
208
273
  token: string;
209
274
  };
210
275
 
276
+ /** Result of executing a git command. */
211
277
  interface ExecResult {
212
278
  stdout: string;
213
279
  stderr: string;
214
280
  exitCode: number;
215
281
  }
216
282
 
283
+ /**
284
+ * Callback that provides HTTP authentication for remote operations.
285
+ * Called with the remote URL; return credentials or null for anonymous access.
286
+ */
217
287
  type CredentialProvider = (url: string) => HttpAuth | null | Promise<HttpAuth | null>;
288
+ /**
289
+ * Override the author/committer identity for commits.
290
+ *
291
+ * When `locked` is true, this identity always wins — even if the agent
292
+ * sets `GIT_AUTHOR_NAME` or runs `git config user.name`. When unlocked
293
+ * (default), acts as a fallback when env vars and git config are absent.
294
+ */
218
295
  interface IdentityOverride {
219
296
  name: string;
220
297
  email: string;
298
+ /** When true, this identity cannot be overridden by env vars or git config. */
221
299
  locked?: boolean;
222
300
  }
301
+ /**
302
+ * Operator-level config overrides. Applied on every `getConfigValue()` read:
303
+ *
304
+ * - `locked` values take absolute precedence — the agent cannot override
305
+ * them via `git config`. Writes still succeed on the VFS (so the agent
306
+ * doesn't see errors), but the locked value always wins on read.
307
+ * - `defaults` supply fallback values when a key is absent from
308
+ * `.git/config`. The agent *can* override these with `git config`.
309
+ *
310
+ * Keys are dotted config names, e.g. `"push.default"`, `"merge.ff"`.
311
+ */
312
+ interface ConfigOverrides {
313
+ locked?: Record<string, string>;
314
+ defaults?: Record<string, string>;
315
+ }
316
+ /** Custom fetch function signature for HTTP transport. */
223
317
  type FetchFunction = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
318
+ /**
319
+ * Controls which remote URLs the git instance may access over HTTP.
320
+ * Set to `false` on {@link GitOptions.network} to block all HTTP access.
321
+ */
224
322
  interface NetworkPolicy {
225
323
  /**
226
324
  * Allowed URL patterns. Can be:
@@ -231,20 +329,28 @@ interface NetworkPolicy {
231
329
  /** Custom fetch function for HTTP transport. Falls back to globalThis.fetch. */
232
330
  fetch?: FetchFunction;
233
331
  }
332
+ /**
333
+ * Returned from pre-hooks to block an operation.
334
+ * The optional `message` is surfaced as stderr.
335
+ */
234
336
  interface Rejection {
235
337
  reject: true;
236
338
  message?: string;
237
339
  }
340
+ /** Type guard for {@link Rejection}. */
238
341
  declare function isRejection(value: unknown): value is Rejection;
342
+ /** Fired before a commit is created. Return a {@link Rejection} to block. */
239
343
  interface PreCommitEvent {
240
344
  readonly repo: GitRepo;
241
345
  readonly index: Index;
242
346
  readonly treeHash: ObjectId;
243
347
  }
348
+ /** Fired after `preCommit` passes. Mutate `message` to rewrite the commit message. */
244
349
  interface CommitMsgEvent {
245
350
  readonly repo: GitRepo;
246
351
  message: string;
247
352
  }
353
+ /** Fired before a merge commit. Mutate `message` to rewrite the merge message. */
248
354
  interface MergeMsgEvent {
249
355
  readonly repo: GitRepo;
250
356
  message: string;
@@ -252,6 +358,7 @@ interface MergeMsgEvent {
252
358
  readonly headHash: ObjectId;
253
359
  readonly theirsHash: ObjectId;
254
360
  }
361
+ /** Fired after a commit is successfully created. */
255
362
  interface PostCommitEvent {
256
363
  readonly repo: GitRepo;
257
364
  readonly hash: ObjectId;
@@ -260,6 +367,7 @@ interface PostCommitEvent {
260
367
  readonly parents: readonly ObjectId[];
261
368
  readonly author: Identity;
262
369
  }
370
+ /** Fired before a three-way merge commit is written. Return a {@link Rejection} to block. */
263
371
  interface PreMergeCommitEvent {
264
372
  readonly repo: GitRepo;
265
373
  readonly mergeMessage: string;
@@ -267,6 +375,7 @@ interface PreMergeCommitEvent {
267
375
  readonly headHash: ObjectId;
268
376
  readonly theirsHash: ObjectId;
269
377
  }
378
+ /** Fired after a merge completes (fast-forward or three-way). */
270
379
  interface PostMergeEvent {
271
380
  readonly repo: GitRepo;
272
381
  readonly headHash: ObjectId;
@@ -274,12 +383,14 @@ interface PostMergeEvent {
274
383
  readonly strategy: "fast-forward" | "three-way";
275
384
  readonly commitHash: ObjectId | null;
276
385
  }
386
+ /** Fired after a branch checkout or detached HEAD checkout completes. */
277
387
  interface PostCheckoutEvent {
278
388
  readonly repo: GitRepo;
279
389
  readonly prevHead: ObjectId | null;
280
390
  readonly newHead: ObjectId;
281
391
  readonly isBranchCheckout: boolean;
282
392
  }
393
+ /** Fired before objects are transferred during `git push`. Return a {@link Rejection} to block. */
283
394
  interface PrePushEvent {
284
395
  readonly repo: GitRepo;
285
396
  readonly remote: string;
@@ -293,17 +404,21 @@ interface PrePushEvent {
293
404
  delete: boolean;
294
405
  }>;
295
406
  }
407
+ /** Fired after a push completes. Same payload as {@link PrePushEvent}. */
296
408
  type PostPushEvent = PrePushEvent;
409
+ /** Fired before a rebase begins. Return a {@link Rejection} to block. */
297
410
  interface PreRebaseEvent {
298
411
  readonly repo: GitRepo;
299
412
  readonly upstream: string;
300
413
  readonly branch: string | null;
301
414
  }
415
+ /** Fired before a checkout or switch. Return a {@link Rejection} to block. */
302
416
  interface PreCheckoutEvent {
303
417
  readonly repo: GitRepo;
304
418
  readonly target: string;
305
419
  readonly mode: "switch" | "detach" | "create-branch" | "paths";
306
420
  }
421
+ /** Fired before a fetch begins. Return a {@link Rejection} to block. */
307
422
  interface PreFetchEvent {
308
423
  readonly repo: GitRepo;
309
424
  readonly remote: string;
@@ -312,12 +427,14 @@ interface PreFetchEvent {
312
427
  readonly prune: boolean;
313
428
  readonly tags: boolean;
314
429
  }
430
+ /** Fired after a fetch completes. */
315
431
  interface PostFetchEvent {
316
432
  readonly repo: GitRepo;
317
433
  readonly remote: string;
318
434
  readonly url: string;
319
435
  readonly refsUpdated: number;
320
436
  }
437
+ /** Fired before a clone begins. Return a {@link Rejection} to block. */
321
438
  interface PreCloneEvent {
322
439
  readonly repo?: GitRepo;
323
440
  readonly repository: string;
@@ -325,6 +442,7 @@ interface PreCloneEvent {
325
442
  readonly bare: boolean;
326
443
  readonly branch: string | null;
327
444
  }
445
+ /** Fired after a clone completes. */
328
446
  interface PostCloneEvent {
329
447
  readonly repo: GitRepo;
330
448
  readonly repository: string;
@@ -332,28 +450,33 @@ interface PostCloneEvent {
332
450
  readonly bare: boolean;
333
451
  readonly branch: string | null;
334
452
  }
453
+ /** Fired before a pull begins. Return a {@link Rejection} to block. */
335
454
  interface PrePullEvent {
336
455
  readonly repo: GitRepo;
337
456
  readonly remote: string;
338
457
  readonly branch: string | null;
339
458
  }
459
+ /** Fired after a pull completes. */
340
460
  interface PostPullEvent {
341
461
  readonly repo: GitRepo;
342
462
  readonly remote: string;
343
463
  readonly branch: string | null;
344
- readonly strategy: "up-to-date" | "fast-forward" | "three-way";
464
+ readonly strategy: "up-to-date" | "fast-forward" | "three-way" | "rebase";
345
465
  readonly commitHash: ObjectId | null;
346
466
  }
467
+ /** Fired before a reset. Return a {@link Rejection} to block. */
347
468
  interface PreResetEvent {
348
469
  readonly repo: GitRepo;
349
470
  readonly mode: "soft" | "mixed" | "hard" | "paths";
350
471
  readonly target: string | null;
351
472
  }
473
+ /** Fired after a reset completes. */
352
474
  interface PostResetEvent {
353
475
  readonly repo: GitRepo;
354
476
  readonly mode: "soft" | "mixed" | "hard" | "paths";
355
477
  readonly targetHash: ObjectId | null;
356
478
  }
479
+ /** Fired before `git clean`. Return a {@link Rejection} to block. */
357
480
  interface PreCleanEvent {
358
481
  readonly repo: GitRepo;
359
482
  readonly dryRun: boolean;
@@ -362,11 +485,13 @@ interface PreCleanEvent {
362
485
  readonly removeIgnored: boolean;
363
486
  readonly onlyIgnored: boolean;
364
487
  }
488
+ /** Fired after `git clean` completes. */
365
489
  interface PostCleanEvent {
366
490
  readonly repo: GitRepo;
367
491
  readonly removed: readonly string[];
368
492
  readonly dryRun: boolean;
369
493
  }
494
+ /** Fired before `git rm`. Return a {@link Rejection} to block. */
370
495
  interface PreRmEvent {
371
496
  readonly repo: GitRepo;
372
497
  readonly paths: readonly string[];
@@ -374,60 +499,71 @@ interface PreRmEvent {
374
499
  readonly recursive: boolean;
375
500
  readonly force: boolean;
376
501
  }
502
+ /** Fired after `git rm` completes. */
377
503
  interface PostRmEvent {
378
504
  readonly repo: GitRepo;
379
505
  readonly removedPaths: readonly string[];
380
506
  readonly cached: boolean;
381
507
  }
508
+ /** Fired before a cherry-pick. Return a {@link Rejection} to block. */
382
509
  interface PreCherryPickEvent {
383
510
  readonly repo: GitRepo;
384
511
  readonly mode: "pick" | "continue" | "abort";
385
512
  readonly commit: string | null;
386
513
  }
514
+ /** Fired after a cherry-pick completes. */
387
515
  interface PostCherryPickEvent {
388
516
  readonly repo: GitRepo;
389
517
  readonly mode: "pick" | "continue" | "abort";
390
518
  readonly commitHash: ObjectId | null;
391
519
  readonly hadConflicts: boolean;
392
520
  }
521
+ /** Fired before a revert. Return a {@link Rejection} to block. */
393
522
  interface PreRevertEvent {
394
523
  readonly repo: GitRepo;
395
524
  readonly mode: "revert" | "continue" | "abort";
396
525
  readonly commit: string | null;
397
526
  }
527
+ /** Fired after a revert completes. */
398
528
  interface PostRevertEvent {
399
529
  readonly repo: GitRepo;
400
530
  readonly mode: "revert" | "continue" | "abort";
401
531
  readonly commitHash: ObjectId | null;
402
532
  readonly hadConflicts: boolean;
403
533
  }
534
+ /** Fired before a stash operation. Return a {@link Rejection} to block. */
404
535
  interface PreStashEvent {
405
536
  readonly repo: GitRepo;
406
537
  readonly action: "push" | "pop" | "apply" | "list" | "drop" | "show" | "clear";
407
538
  readonly ref: string | null;
408
539
  }
540
+ /** Fired after a stash operation completes. */
409
541
  interface PostStashEvent {
410
542
  readonly repo: GitRepo;
411
543
  readonly action: "push" | "pop" | "apply" | "list" | "drop" | "show" | "clear";
412
544
  readonly ok: boolean;
413
545
  }
546
+ /** Fired whenever a ref is created or updated. */
414
547
  interface RefUpdateEvent {
415
548
  readonly repo: GitRepo;
416
549
  readonly ref: string;
417
550
  readonly oldHash: ObjectId | null;
418
551
  readonly newHash: ObjectId;
419
552
  }
553
+ /** Fired whenever a ref is deleted. */
420
554
  interface RefDeleteEvent {
421
555
  readonly repo: GitRepo;
422
556
  readonly ref: string;
423
557
  readonly oldHash: ObjectId | null;
424
558
  }
559
+ /** Fired whenever a git object (blob, tree, commit, tag) is written to the store. */
425
560
  interface ObjectWriteEvent {
426
561
  readonly repo: GitRepo;
427
562
  readonly type: ObjectType;
428
563
  readonly hash: ObjectId;
429
564
  }
430
565
 
566
+ /** Fired before any git subcommand executes. Return a {@link Rejection} to block. */
431
567
  interface BeforeCommandEvent {
432
568
  readonly command: string;
433
569
  readonly args: string[];
@@ -435,6 +571,7 @@ interface BeforeCommandEvent {
435
571
  readonly cwd: string;
436
572
  readonly env: Map<string, string>;
437
573
  }
574
+ /** Fired after any git subcommand completes. */
438
575
  interface AfterCommandEvent {
439
576
  readonly command: string;
440
577
  readonly args: string[];
@@ -442,6 +579,16 @@ interface AfterCommandEvent {
442
579
  }
443
580
  type PreHookReturn = void | Rejection | Promise<void | Rejection>;
444
581
  type PostHookReturn = void | Promise<void>;
582
+ /**
583
+ * Hook callbacks for intercepting git operations.
584
+ *
585
+ * Pre-hooks can return a {@link Rejection} to block the operation.
586
+ * Post-hooks are fire-and-forget. Low-level events (`onRefUpdate`,
587
+ * `onRefDelete`, `onObjectWrite`) fire synchronously on every
588
+ * ref/object write.
589
+ *
590
+ * Use {@link composeGitHooks} to combine multiple hook sets.
591
+ */
445
592
  interface GitHooks {
446
593
  preCommit?: (event: PreCommitEvent) => PreHookReturn;
447
594
  commitMsg?: (event: CommitMsgEvent) => PreHookReturn;
@@ -478,6 +625,13 @@ interface GitHooks {
478
625
  beforeCommand?: (event: BeforeCommandEvent) => PreHookReturn;
479
626
  afterCommand?: (event: AfterCommandEvent) => PostHookReturn;
480
627
  }
628
+ /**
629
+ * Combine multiple {@link GitHooks} objects into one.
630
+ *
631
+ * Pre-hooks chain in order, short-circuiting on the first {@link Rejection}.
632
+ * Post-hooks and low-level events chain in order, individually try/caught.
633
+ * Mutable-message hooks (`commitMsg`, `mergeMsg`) pass the mutated message through.
634
+ */
481
635
  declare function composeGitHooks(...hookSets: (GitHooks | undefined)[]): GitHooks;
482
636
 
483
- export { type Identity as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type PrePullEvent as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PrePushEvent as J, type PreRebaseEvent as K, type PreResetEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PostCheckoutEvent as P, type PreRevertEvent as Q, type RemoteResolver as R, type PreRmEvent as S, type PreStashEvent as T, type RefDeleteEvent as U, type RefEntry as V, type RefUpdateEvent as W, type Rejection as X, composeGitHooks as Y, isRejection as Z, type ObjectId as _, type RefStore as a, type TreeDiffEntry as a0, type Commit as a1, type ObjectType as a2, type RawObject as a3, type Ref as a4, type FetchFunction as b, type GitContext as c, type CommitMsgEvent as d, type FileStat as e, type GitRepo as f, type ObjectWriteEvent as g, type PostCherryPickEvent as h, type PostCleanEvent as i, type PostCloneEvent as j, type PostCommitEvent as k, type PostFetchEvent as l, type PostMergeEvent as m, type PostPullEvent as n, type PostPushEvent as o, type PostResetEvent as p, type PostRevertEvent as q, type PostRmEvent as r, type PostStashEvent as s, type PreCheckoutEvent as t, type PreCherryPickEvent as u, type PreCleanEvent as v, type PreCloneEvent as w, type PreCommitEvent as x, type PreFetchEvent as y, type PreMergeCommitEvent as z };
637
+ export { type Identity as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type PrePullEvent as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PrePushEvent as J, type PreRebaseEvent as K, type PreResetEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PostCheckoutEvent as P, type PreRevertEvent as Q, type RemoteResolver as R, type PreRmEvent as S, type PreStashEvent as T, type RefDeleteEvent as U, type RefEntry as V, type RefUpdateEvent as W, type Rejection as X, composeGitHooks as Y, isRejection as Z, type ObjectId as _, type RefStore as a, type TreeDiffEntry as a0, type Commit as a1, type ObjectType as a2, type RawObject as a3, type Ref as a4, type ConfigOverrides as b, type FileStat as c, type GitContext as d, type CommitMsgEvent as e, type GitRepo as f, type ObjectWriteEvent as g, type PostCherryPickEvent as h, type PostCleanEvent as i, type PostCloneEvent as j, type PostCommitEvent as k, type PostFetchEvent as l, type PostMergeEvent as m, type PostPullEvent as n, type PostPushEvent as o, type PostResetEvent as p, type PostRevertEvent as q, type PostRmEvent as r, type PostStashEvent as s, type PreCheckoutEvent as t, type PreCherryPickEvent as u, type PreCleanEvent as v, type PreCloneEvent as w, type PreCommitEvent as x, type PreFetchEvent as y, type PreMergeCommitEvent as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FileSystem, E as ExecResult, G as GitHooks, C as CredentialProvider, I as IdentityOverride, N as NetworkPolicy, R as RemoteResolver, O as ObjectStore, a as RefStore, b as FetchFunction, c as GitContext } from './hooks-OMCbhUGB.js';
2
- export { A as AfterCommandEvent, B as BeforeCommandEvent, d as CommitMsgEvent, e as FileStat, f as GitRepo, H as HttpAuth, M as MergeMsgEvent, g as ObjectWriteEvent, P as PostCheckoutEvent, h as PostCherryPickEvent, i as PostCleanEvent, j as PostCloneEvent, k as PostCommitEvent, l as PostFetchEvent, m as PostMergeEvent, n as PostPullEvent, o as PostPushEvent, p as PostResetEvent, q as PostRevertEvent, r as PostRmEvent, s as PostStashEvent, t as PreCheckoutEvent, u as PreCherryPickEvent, v as PreCleanEvent, w as PreCloneEvent, x as PreCommitEvent, y as PreFetchEvent, z as PreMergeCommitEvent, D as PrePullEvent, J as PrePushEvent, K as PreRebaseEvent, L as PreResetEvent, Q as PreRevertEvent, S as PreRmEvent, T as PreStashEvent, U as RefDeleteEvent, V as RefEntry, W as RefUpdateEvent, X as Rejection, Y as composeGitHooks, Z as isRejection } from './hooks-OMCbhUGB.js';
1
+ import { F as FileSystem, G as GitHooks, C as CredentialProvider, I as IdentityOverride, N as NetworkPolicy, R as RemoteResolver, O as ObjectStore, a as RefStore, b as ConfigOverrides, E as ExecResult, c as FileStat, d as GitContext } from './hooks-4DvkF2xT.js';
2
+ export { A as AfterCommandEvent, B as BeforeCommandEvent, e as CommitMsgEvent, f as GitRepo, H as HttpAuth, M as MergeMsgEvent, g as ObjectWriteEvent, P as PostCheckoutEvent, h as PostCherryPickEvent, i as PostCleanEvent, j as PostCloneEvent, k as PostCommitEvent, l as PostFetchEvent, m as PostMergeEvent, n as PostPullEvent, o as PostPushEvent, p as PostResetEvent, q as PostRevertEvent, r as PostRmEvent, s as PostStashEvent, t as PreCheckoutEvent, u as PreCherryPickEvent, v as PreCleanEvent, w as PreCloneEvent, x as PreCommitEvent, y as PreFetchEvent, z as PreMergeCommitEvent, D as PrePullEvent, J as PrePushEvent, K as PreRebaseEvent, L as PreResetEvent, Q as PreRevertEvent, S as PreRmEvent, T as PreStashEvent, U as RefDeleteEvent, V as RefEntry, W as RefUpdateEvent, X as Rejection, Y as composeGitHooks, Z as isRejection } from './hooks-4DvkF2xT.js';
3
3
 
4
4
  /** Options for subcommand execution (mirrors just-bash's CommandExecOptions). */
5
5
  interface CommandExecOptions {
@@ -22,7 +22,15 @@ interface CommandContext {
22
22
  exec?: (command: string, options: CommandExecOptions) => Promise<ExecResult>;
23
23
  signal?: AbortSignal;
24
24
  }
25
+ /** Git subcommand name. Used with {@link GitOptions.disabled} to block specific commands. */
25
26
  type GitCommandName = "init" | "clone" | "fetch" | "pull" | "push" | "add" | "blame" | "commit" | "status" | "log" | "branch" | "tag" | "checkout" | "diff" | "reset" | "merge" | "cherry-pick" | "revert" | "rebase" | "mv" | "rm" | "remote" | "config" | "show" | "stash" | "rev-parse" | "ls-files" | "clean" | "switch" | "restore" | "reflog" | "repack" | "gc" | "bisect";
27
+ /**
28
+ * Configuration for a {@link Git} instance.
29
+ *
30
+ * Controls hooks, identity, credentials, network access, command
31
+ * restrictions, and config overrides for all commands run through
32
+ * this instance.
33
+ */
26
34
  interface GitOptions {
27
35
  hooks?: GitHooks;
28
36
  credentials?: CredentialProvider;
@@ -48,20 +56,11 @@ interface GitOptions {
48
56
  * and go through this store instead (e.g. SQLite-backed).
49
57
  */
50
58
  refStore?: RefStore;
51
- }
52
- /**
53
- * Bundle of operator-level extensions threaded into command handlers
54
- * via closures and merged onto GitContext after discovery.
55
- */
56
- interface GitExtensions {
57
- hooks?: GitHooks;
58
- credentialProvider?: CredentialProvider;
59
- identityOverride?: IdentityOverride;
60
- fetchFn?: FetchFunction;
61
- networkPolicy?: NetworkPolicy | false;
62
- resolveRemote?: RemoteResolver;
63
- objectStore?: ObjectStore;
64
- refStore?: RefStore;
59
+ /**
60
+ * Config overrides. `locked` values always win over `.git/config`;
61
+ * `defaults` supply fallbacks when a key is absent from config.
62
+ */
63
+ config?: ConfigOverrides;
65
64
  }
66
65
  /** Simplified context for {@link Git.exec}. */
67
66
  interface ExecContext {
@@ -70,11 +69,26 @@ interface ExecContext {
70
69
  env?: Record<string, string>;
71
70
  stdin?: string;
72
71
  }
72
+ /**
73
+ * Git command handler. Runs git subcommands against a virtual filesystem.
74
+ *
75
+ * Create via {@link createGit}. Use as a standalone executor with
76
+ * {@link Git.exec}, or pass directly into just-bash's `customCommands`
77
+ * to make `git` available inside a virtual shell.
78
+ *
79
+ * ```ts
80
+ * const git = createGit();
81
+ * const fs = new MemoryFileSystem();
82
+ * await git.exec("init", { fs, cwd: "/repo" });
83
+ * ```
84
+ */
73
85
  declare class Git {
74
86
  readonly name = "git";
75
87
  private blocked;
76
88
  private hooks;
77
89
  private inner;
90
+ private locks;
91
+ private withLock;
78
92
  constructor(options?: GitOptions);
79
93
  /**
80
94
  * Run a git command from a string.
@@ -90,13 +104,40 @@ declare class Git {
90
104
  exec: (command: string, ctx: ExecContext) => Promise<ExecResult>;
91
105
  execute: (args: string[], ctx: CommandContext) => Promise<ExecResult>;
92
106
  }
107
+ /** Create a new {@link Git} command handler with the given options. */
108
+ declare function createGit(options?: GitOptions): Git;
109
+
93
110
  /**
94
- * Tokenize a command string with basic shell quoting.
95
- * Supports single quotes, double quotes (with backslash escapes),
96
- * and whitespace splitting. Strips a leading "git" token if present.
111
+ * Minimal in-memory filesystem implementing the just-git {@link FileSystem}
112
+ * interface. Supports files, directories, and symlinks.
113
+ *
114
+ * ```ts
115
+ * const fs = new MemoryFileSystem({ "/repo/README.md": "# Hello" });
116
+ * ```
97
117
  */
98
- declare function tokenizeCommand(input: string): string[];
99
- declare function createGit(options?: GitOptions): Git;
118
+ declare class MemoryFileSystem implements FileSystem {
119
+ private data;
120
+ constructor(initialFiles?: Record<string, string | Uint8Array>);
121
+ private ensureParents;
122
+ private resolve;
123
+ private resolveParent;
124
+ readFile(path: string): Promise<string>;
125
+ readFileBuffer(path: string): Promise<Uint8Array>;
126
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
127
+ exists(path: string): Promise<boolean>;
128
+ stat(path: string): Promise<FileStat>;
129
+ lstat(path: string): Promise<FileStat>;
130
+ mkdir(path: string, options?: {
131
+ recursive?: boolean;
132
+ }): Promise<void>;
133
+ readdir(path: string): Promise<string[]>;
134
+ rm(path: string, options?: {
135
+ recursive?: boolean;
136
+ force?: boolean;
137
+ }): Promise<void>;
138
+ readlink(path: string): Promise<string>;
139
+ symlink(target: string, linkPath: string): Promise<void>;
140
+ }
100
141
 
101
142
  /**
102
143
  * Walk up from `startPath` looking for a git repository.
@@ -106,4 +147,4 @@ declare function createGit(options?: GitOptions): Git;
106
147
  */
107
148
  declare function findRepo(fs: FileSystem, startPath: string): Promise<GitContext | null>;
108
149
 
109
- export { type CommandContext, type CommandExecOptions, CredentialProvider, type ExecContext, ExecResult, FetchFunction, FileSystem, Git, type GitCommandName, GitContext, type GitExtensions, GitHooks, type GitOptions, IdentityOverride, NetworkPolicy, ObjectStore, RefStore, RemoteResolver, createGit, findRepo, tokenizeCommand };
150
+ export { ConfigOverrides, CredentialProvider, type ExecContext, ExecResult, FileStat, FileSystem, Git, type GitCommandName, GitContext, GitHooks, type GitOptions, IdentityOverride, MemoryFileSystem, NetworkPolicy, ObjectStore, RefStore, RemoteResolver, createGit, findRepo };