just-git 1.3.1 → 1.3.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,4 +1,77 @@
1
- import { _ as ObjectId, $ as Identity, d as GitContext, f as GitRepo, F as FileSystem, a0 as TreeDiffEntry, V as RefEntry, a1 as Commit, O as ObjectStore, a2 as ObjectType, a3 as RawObject, a4 as PackObject, a as RefStore, a5 as Ref } from '../hooks-BtbyLyYE.js';
1
+ import { g as GitRepo, a1 as RefEntry, e as Commit, i as ObjectId, h as Identity, a7 as TreeDiffEntry, d as GitContext, F as FileSystem } from '../hooks-t3k-y0u_.js';
2
+
3
+ /**
4
+ * Core grep matching logic shared by the `git grep` command and the
5
+ * repo-level `grep` helper.
6
+ */
7
+ interface GrepMatch {
8
+ lineNo: number;
9
+ line: string;
10
+ }
11
+
12
+ /** Resolve a ref name (e.g. "HEAD", "refs/heads/main") to a commit hash. Returns null if not found. */
13
+ declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>;
14
+ /** List all local branches (`refs/heads/*`). */
15
+ declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
16
+ /** List all tags (`refs/tags/*`). */
17
+ declare function listTags(repo: GitRepo): Promise<RefEntry[]>;
18
+ /** Read and parse a commit object by its hash. */
19
+ declare function readCommit(repo: GitRepo, hash: string): Promise<Commit>;
20
+ /** Read a blob's raw bytes by its hash. */
21
+ declare function readBlob(repo: GitRepo, hash: string): Promise<Uint8Array>;
22
+ /** Read a blob as a UTF-8 string by its hash. */
23
+ declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
24
+ /**
25
+ * Read a file's content at a specific commit.
26
+ * Returns null if the file doesn't exist at that commit.
27
+ */
28
+ declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
29
+ /** Options for {@link grep}. */
30
+ interface GrepOptions {
31
+ /** Treat patterns as fixed strings, not regexps. */
32
+ fixed?: boolean;
33
+ /** Case-insensitive matching. */
34
+ ignoreCase?: boolean;
35
+ /** Match whole words only. */
36
+ wordRegexp?: boolean;
37
+ /** Require ALL patterns to hit at least one line in a file (AND). Default is OR. */
38
+ allMatch?: boolean;
39
+ /** Invert the match — return non-matching lines. */
40
+ invert?: boolean;
41
+ /** Limit matches per file. */
42
+ maxCount?: number;
43
+ /** Max directory depth (0 = only root-level files). */
44
+ maxDepth?: number;
45
+ /** Only search files whose paths match these globs. Matched against the full repo-relative path. */
46
+ paths?: string[];
47
+ }
48
+ /** A single file's grep results from {@link grep}. */
49
+ interface GrepFileMatch {
50
+ /** Repo-relative file path. */
51
+ path: string;
52
+ /** Matching lines (empty for binary matches). */
53
+ matches: GrepMatch[];
54
+ /** True when the file is binary and a pattern matched its raw content. */
55
+ binary: boolean;
56
+ }
57
+
58
+ /**
59
+ * Search files at a commit for lines matching one or more patterns.
60
+ *
61
+ * Operates purely on the object store — no filesystem, index, or
62
+ * worktree needed. Takes a commit hash (not a ref name) and returns
63
+ * structured match results.
64
+ *
65
+ * ```ts
66
+ * const results = await grep(repo, commitHash, ["TODO", "FIXME"]);
67
+ * for (const file of results) {
68
+ * for (const m of file.matches) {
69
+ * console.log(`${file.path}:${m.lineNo}: ${m.line}`);
70
+ * }
71
+ * }
72
+ * ```
73
+ */
74
+ declare function grep(repo: GitRepo, commitHash: string, patterns: (string | RegExp)[], options?: GrepOptions): Promise<GrepFileMatch[]>;
2
75
 
3
76
  interface BlameEntry {
4
77
  hash: ObjectId;
@@ -18,39 +91,6 @@ interface BlameEntry {
18
91
  };
19
92
  }
20
93
 
21
- /**
22
- * Core grep matching logic shared by the `git grep` command and the
23
- * repo-level `grep` helper.
24
- */
25
- interface GrepMatch {
26
- lineNo: number;
27
- line: string;
28
- }
29
-
30
- interface MergeConflict {
31
- path: string;
32
- reason: "content" | "delete-modify" | "add-add" | "rename-delete" | "rename-rename" | "directory-rename";
33
- /** For delete-modify / rename-delete: which side deleted the file. */
34
- deletedBy?: "ours" | "theirs";
35
- /** For rename conflicts: the old (base) path. */
36
- oldPath?: string;
37
- /** For rename/rename: the path ours renamed to. */
38
- oursPath?: string;
39
- /** For rename/rename: the path theirs renamed to. */
40
- theirsPath?: string;
41
- /**
42
- * For content conflicts arising from renames: the path where ours' version
43
- * was before the merge. If different from `path`, indicates ours had the
44
- * file at a different location.
45
- */
46
- oursOrigPath?: string;
47
- /**
48
- * For content conflicts arising from renames: the path where theirs'
49
- * version was before the merge.
50
- */
51
- theirsOrigPath?: string;
52
- }
53
-
54
94
  /** A flattened file entry from walking a tree recursively. */
55
95
  interface FlatTreeEntry {
56
96
  path: string;
@@ -58,14 +98,7 @@ interface FlatTreeEntry {
58
98
  hash: ObjectId;
59
99
  }
60
100
 
61
- /**
62
- * Standalone helper functions for working with GitRepo.
63
- *
64
- * Thin wrappers over lib/ primitives. Useful inside server hooks
65
- * and equally useful outside the server for direct repo inspection.
66
- */
67
-
68
- /** Commit metadata returned by {@link getNewCommits}. */
101
+ /** Commit metadata returned by {@link getNewCommits} and {@link walkCommitHistory}. */
69
102
  interface CommitInfo {
70
103
  hash: string;
71
104
  message: string;
@@ -74,35 +107,40 @@ interface CommitInfo {
74
107
  author: Identity;
75
108
  committer: Identity;
76
109
  }
77
- /**
78
- * Walk commits introduced by a ref update (newHash excluding oldHash).
79
- * If oldHash is null (new ref), walks all ancestors of newHash.
80
- */
81
- declare function getNewCommits(repo: GitRepo, oldHash: string | null, newHash: string): AsyncGenerator<CommitInfo>;
110
+ /** Recursively walk a tree object and return all file entries with their full paths. */
111
+ declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
112
+ /** Diff two tree objects and return the list of added/deleted/modified entries. Pass null for an empty tree. */
113
+ declare function diffTrees(repo: GitRepo, treeA: string | null, treeB: string | null): Promise<TreeDiffEntry[]>;
82
114
  /**
83
115
  * Get the files changed between two commits.
84
- * Reads the tree hash from each commit and diffs them.
85
116
  * If oldHash is null (new ref), diffs against an empty tree.
86
117
  */
87
118
  declare function getChangedFiles(repo: GitRepo, oldHash: string | null, newHash: string): Promise<TreeDiffEntry[]>;
119
+ /**
120
+ * Walk commits introduced by a ref update (newHash excluding oldHash).
121
+ * If oldHash is null (new ref), walks all ancestors of newHash.
122
+ */
123
+ declare function getNewCommits(repo: GitRepo, oldHash: string | null, newHash: string): AsyncGenerator<CommitInfo>;
88
124
  /** Check whether `candidate` is an ancestor of `descendant` in the commit graph. */
89
125
  declare function isAncestor(repo: GitRepo, candidate: string, descendant: string): Promise<boolean>;
90
- /** Resolve a ref name (e.g. "HEAD", "refs/heads/main") to a commit hash. Returns null if not found. */
91
- declare function resolveRef(repo: GitRepo, name: string): Promise<string | null>;
92
- /** List all local branches (`refs/heads/*`). */
93
- declare function listBranches(repo: GitRepo): Promise<RefEntry[]>;
94
- /** List all tags (`refs/tags/*`). */
95
- declare function listTags(repo: GitRepo): Promise<RefEntry[]>;
96
- /** Read and parse a commit object by its hash. */
97
- declare function readCommit(repo: GitRepo, hash: string): Promise<Commit>;
98
- /** Read a blob's raw bytes by its hash. */
99
- declare function readBlob(repo: GitRepo, hash: string): Promise<Uint8Array>;
100
- /** Read a blob as a UTF-8 string by its hash. */
101
- declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
102
- /** Recursively walk a tree object and return all file entries with their full paths. */
103
- declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
104
- /** Diff two tree objects and return the list of added/deleted/modified entries. Pass null for an empty tree. */
105
- declare function diffTrees(repo: GitRepo, treeA: string | null, treeB: string | null): Promise<TreeDiffEntry[]>;
126
+ /** Find the merge base(s) of two commits. Returns one hash for most cases, multiple for criss-cross merges. */
127
+ declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
128
+ /**
129
+ * Count how many commits `localHash` is ahead of and behind `upstreamHash`.
130
+ */
131
+ declare function countAheadBehind(repo: GitRepo, localHash: string, upstreamHash: string): Promise<{
132
+ ahead: number;
133
+ behind: number;
134
+ }>;
135
+ /**
136
+ * Compute line-by-line blame for a file at a given commit.
137
+ * Returns one entry per line with the originating commit, author, and content.
138
+ * Optionally restrict to a line range with `startLine` / `endLine` (1-based).
139
+ */
140
+ declare function blame(repo: GitRepo, commitHash: string, path: string, opts?: {
141
+ startLine?: number;
142
+ endLine?: number;
143
+ }): Promise<BlameEntry[]>;
106
144
  /** A single hunk in a file diff. */
107
145
  interface DiffHunk {
108
146
  oldStart: number;
@@ -147,43 +185,22 @@ declare function diffCommits(repo: GitRepo, base: string, head: string, options?
147
185
  /** Enable rename detection (default true). */
148
186
  renames?: boolean;
149
187
  }): Promise<FileDiff[]>;
150
- /** Find the merge base(s) of two commits. Returns one hash for most cases, multiple for criss-cross merges. */
151
- declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
152
- /** Result of a tree-level merge via {@link mergeTrees} or {@link mergeTreesFromTreeHashes}. */
153
- interface MergeTreesResult {
154
- /** Hash of the result tree (may contain conflict-marker blobs). */
155
- treeHash: string;
156
- /** True if the merge completed without conflicts. */
157
- clean: boolean;
158
- /** Details of each conflict, if any. */
159
- conflicts: MergeConflict[];
160
- /** Informational messages from the merge engine. */
161
- messages: string[];
162
- }
163
188
  /**
164
- * Three-way tree merge using merge-ort. Operates purely on the object
165
- * store no filesystem or worktree needed.
166
- *
167
- * Takes two commit hashes, finds their merge base(s) automatically
168
- * (handling criss-cross merges via recursive base merging), and produces
169
- * a result tree with conflict-marker blobs embedded for any conflicts.
189
+ * Walk the commit graph starting from one or more hashes, yielding
190
+ * commits in reverse chronological order. Supports excluding commits
191
+ * reachable from specified hashes, following only first parents, and
192
+ * filtering to commits that touch specific paths.
170
193
  *
171
- * Use `mergeTreesFromTreeHashes` if you already have tree hashes and a
172
- * known base tree.
173
- */
174
- declare function mergeTrees(repo: GitRepo, oursCommit: string, theirsCommit: string, labels?: {
175
- ours?: string;
176
- theirs?: string;
177
- }): Promise<MergeTreesResult>;
178
- /**
179
- * Three-way tree merge from raw tree hashes. Useful when you already
180
- * have the base/ours/theirs trees and don't want automatic merge-base
181
- * computation.
194
+ * When `paths` is provided, history simplification is applied: at
195
+ * merge points, only TREESAME parents are followed (matching git's
196
+ * default simplification for `git log -- <path>`).
182
197
  */
183
- declare function mergeTreesFromTreeHashes(repo: GitRepo, baseTree: string | null, oursTree: string, theirsTree: string, labels?: {
184
- ours?: string;
185
- theirs?: string;
186
- }): Promise<MergeTreesResult>;
198
+ declare function walkCommitHistory(repo: GitRepo, startHash: string | string[], opts?: {
199
+ exclude?: string[];
200
+ firstParent?: boolean;
201
+ paths?: string[];
202
+ }): AsyncGenerator<CommitInfo>;
203
+
187
204
  /** Options for {@link createCommit}. */
188
205
  interface CreateCommitOptions {
189
206
  /** Hash of the tree object for this commit. */
@@ -222,9 +239,6 @@ interface TreeEntryInput {
222
239
  * Build a tree object from a flat list of entries and write it to the
223
240
  * object store. When `mode` is omitted, the object store is consulted:
224
241
  * tree objects get "040000", everything else gets "100644".
225
- *
226
- * For creating blobs to reference in the tree, write content directly
227
- * via `repo.objectStore.write("blob", content)`.
228
242
  */
229
243
  declare function writeTree(repo: GitRepo, entries: TreeEntryInput[]): Promise<string>;
230
244
  /**
@@ -232,11 +246,67 @@ declare function writeTree(repo: GitRepo, entries: TreeEntryInput[]): Promise<st
232
246
  * Returns the blob's hash.
233
247
  */
234
248
  declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
249
+
250
+ interface MergeConflict {
251
+ path: string;
252
+ reason: "content" | "delete-modify" | "add-add" | "rename-delete" | "rename-rename" | "directory-rename";
253
+ /** For delete-modify / rename-delete: which side deleted the file. */
254
+ deletedBy?: "ours" | "theirs";
255
+ /** For rename conflicts: the old (base) path. */
256
+ oldPath?: string;
257
+ /** For rename/rename: the path ours renamed to. */
258
+ oursPath?: string;
259
+ /** For rename/rename: the path theirs renamed to. */
260
+ theirsPath?: string;
261
+ /**
262
+ * For content conflicts arising from renames: the path where ours' version
263
+ * was before the merge. If different from `path`, indicates ours had the
264
+ * file at a different location.
265
+ */
266
+ oursOrigPath?: string;
267
+ /**
268
+ * For content conflicts arising from renames: the path where theirs'
269
+ * version was before the merge.
270
+ */
271
+ theirsOrigPath?: string;
272
+ }
273
+
274
+ /** Result of a tree-level merge via {@link mergeTrees} or {@link mergeTreesFromTreeHashes}. */
275
+ interface MergeTreesResult {
276
+ /** Hash of the result tree (may contain conflict-marker blobs). */
277
+ treeHash: string;
278
+ /** True if the merge completed without conflicts. */
279
+ clean: boolean;
280
+ /** Details of each conflict, if any. */
281
+ conflicts: MergeConflict[];
282
+ /** Informational messages from the merge engine. */
283
+ messages: string[];
284
+ }
235
285
  /**
236
- * Read a file's content at a specific commit.
237
- * Returns null if the file doesn't exist at that commit.
286
+ * Three-way tree merge using merge-ort. Operates purely on the object
287
+ * store no filesystem or worktree needed.
288
+ *
289
+ * Takes two commit hashes, finds their merge base(s) automatically
290
+ * (handling criss-cross merges via recursive base merging), and produces
291
+ * a result tree with conflict-marker blobs embedded for any conflicts.
292
+ *
293
+ * Use `mergeTreesFromTreeHashes` if you already have tree hashes and a
294
+ * known base tree.
238
295
  */
239
- declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
296
+ declare function mergeTrees(repo: GitRepo, oursCommit: string, theirsCommit: string, labels?: {
297
+ ours?: string;
298
+ theirs?: string;
299
+ }): Promise<MergeTreesResult>;
300
+ /**
301
+ * Three-way tree merge from raw tree hashes. Useful when you already
302
+ * have the base/ours/theirs trees and don't want automatic merge-base
303
+ * computation.
304
+ */
305
+ declare function mergeTreesFromTreeHashes(repo: GitRepo, baseTree: string | null, oursTree: string, theirsTree: string, labels?: {
306
+ ours?: string;
307
+ theirs?: string;
308
+ }): Promise<MergeTreesResult>;
309
+
240
310
  /** Result of {@link extractTree}. */
241
311
  interface ExtractTreeResult {
242
312
  commitHash: string;
@@ -249,9 +319,6 @@ interface ExtractTreeResult {
249
319
  * Accepts a ref name ("HEAD", "refs/heads/main") or a raw commit hash.
250
320
  * Writes all tracked files under `targetDir` (default "/"). No `.git`
251
321
  * directory is created — just the working tree.
252
- *
253
- * Useful inside server hooks and platform callbacks to inspect, build,
254
- * or lint the code at a given commit without affecting the repo itself.
255
322
  */
256
323
  declare function extractTree(repo: GitRepo, refOrHash: string, fs: FileSystem, targetDir?: string): Promise<ExtractTreeResult>;
257
324
  interface CreateWorktreeOptions {
@@ -262,7 +329,7 @@ interface CreateWorktreeOptions {
262
329
  /** Path to the `.git` directory on the VFS (default: `<workTree>/.git`). */
263
330
  gitDir?: string;
264
331
  }
265
- /** Result of {@link createWorktree}. */
332
+ /** Result of {@link createWorktree} and {@link createSandboxWorktree}. */
266
333
  interface WorktreeResult {
267
334
  /** The fully-wired GitContext, ready for use with lib/ functions. */
268
335
  ctx: GitContext;
@@ -296,84 +363,38 @@ interface WorktreeResult {
296
363
  */
297
364
  declare function createWorktree(repo: GitRepo, fs: FileSystem, options?: CreateWorktreeOptions): Promise<WorktreeResult>;
298
365
  /**
299
- * Count how many commits `localHash` is ahead of and behind `upstreamHash`.
300
- * Useful for tracking info display and branch comparison.
301
- */
302
- declare function countAheadBehind(repo: GitRepo, localHash: string, upstreamHash: string): Promise<{
303
- ahead: number;
304
- behind: number;
305
- }>;
306
-
307
- /**
308
- * Compute line-by-line blame for a file at a given commit.
309
- * Returns one entry per line with the originating commit, author, and content.
310
- * Optionally restrict to a line range with `startLine` / `endLine` (1-based).
311
- */
312
- declare function blame(repo: GitRepo, commitHash: string, path: string, opts?: {
313
- startLine?: number;
314
- endLine?: number;
315
- }): Promise<BlameEntry[]>;
316
- /**
317
- * Walk the commit graph starting from one or more hashes, yielding
318
- * commits in reverse chronological order. Supports excluding commits
319
- * reachable from specified hashes, following only first parents, and
320
- * filtering to commits that touch specific paths.
366
+ * Create an ephemeral worktree backed by overlay stores and a lazy filesystem.
321
367
  *
322
- * When `paths` is provided, history simplification is applied: at
323
- * merge points, only TREESAME parents are followed (matching git's
324
- * default simplification for `git log -- <path>`).
325
- */
326
- declare function walkCommitHistory(repo: GitRepo, startHash: string | string[], opts?: {
327
- exclude?: string[];
328
- firstParent?: boolean;
329
- paths?: string[];
330
- }): AsyncGenerator<CommitInfo>;
331
- /** Options for {@link grep}. */
332
- interface GrepOptions {
333
- /** Treat patterns as fixed strings, not regexps. */
334
- fixed?: boolean;
335
- /** Case-insensitive matching. */
336
- ignoreCase?: boolean;
337
- /** Match whole words only. */
338
- wordRegexp?: boolean;
339
- /** Require ALL patterns to hit at least one line in a file (AND). Default is OR. */
340
- allMatch?: boolean;
341
- /** Invert the match — return non-matching lines. */
342
- invert?: boolean;
343
- /** Limit matches per file. */
344
- maxCount?: number;
345
- /** Max directory depth (0 = only root-level files). */
346
- maxDepth?: number;
347
- /** Only search files whose paths match these globs. Matched against the full repo-relative path. */
348
- paths?: string[];
349
- }
350
- /** A single file's grep results from {@link grep}. */
351
- interface GrepFileMatch {
352
- /** Repo-relative file path. */
353
- path: string;
354
- /** Matching lines (empty for binary matches). */
355
- matches: GrepMatch[];
356
- /** True when the file is binary and a pattern matched its raw content. */
357
- binary: boolean;
358
- }
359
-
360
- /**
361
- * Search files at a commit for lines matching one or more patterns.
368
+ * - Object/ref writes go to an in-memory overlay (real repo untouched)
369
+ * - Worktree files are read lazily from the object store on demand
370
+ * - All state is discarded when the returned context goes out of scope
362
371
  *
363
- * Operates purely on the object store no filesystem, index, or
364
- * worktree needed. Takes a commit hash (not a ref name) and returns
365
- * structured match results.
372
+ * Designed for server hooks that need to run tools against pushed code
373
+ * without paying the cost of materializing the entire tree and without
374
+ * risking mutation of the real repository.
366
375
  *
367
376
  * ```ts
368
- * const results = await grep(repo, commitHash, ["TODO", "FIXME"]);
369
- * for (const file of results) {
370
- * for (const m of file.matches) {
371
- * console.log(`${file.path}:${m.lineNo}: ${m.line}`);
377
+ * hooks: {
378
+ * async preReceive({ repo, updates }) {
379
+ * const { ctx } = await createSandboxWorktree(repo, {
380
+ * ref: updates[0].newHash,
381
+ * });
382
+ * const git = createGit({
383
+ * objectStore: ctx.objectStore,
384
+ * refStore: ctx.refStore,
385
+ * });
386
+ * const bash = new Bash({ fs: ctx.fs, cwd: ctx.workTree! });
387
+ * const result = await bash.exec("cat package.json");
372
388
  * }
373
389
  * }
374
390
  * ```
375
391
  */
376
- declare function grep(repo: GitRepo, commitHash: string, patterns: (string | RegExp)[], options?: GrepOptions): Promise<GrepFileMatch[]>;
392
+ declare function createSandboxWorktree(repo: GitRepo, options?: {
393
+ ref?: string;
394
+ workTree?: string;
395
+ gitDir?: string;
396
+ }): Promise<WorktreeResult>;
397
+
377
398
  /**
378
399
  * Wrap a `GitRepo` so all write operations throw.
379
400
  *
@@ -382,9 +403,6 @@ declare function grep(repo: GitRepo, commitHash: string, patterns: (string | Reg
382
403
  * writeRef, deleteRef, ingestPack, compareAndSwapRef) throw with
383
404
  * a descriptive error.
384
405
  *
385
- * Use with `createWorktree` and/or `GitOptions.objectStore` /
386
- * `GitOptions.refStore` to enforce read-only access:
387
- *
388
406
  * ```ts
389
407
  * const ro = readonlyRepo(storage.repo("my-repo"));
390
408
  * const { ctx } = await createWorktree(ro, fs, { workTree: "/repo" });
@@ -403,100 +421,12 @@ declare function readonlyRepo(repo: GitRepo): GitRepo;
403
421
  * compareAndSwapRef) are captured in an in-memory overlay
404
422
  * and never reach the inner repo.
405
423
  *
406
- * Use for ephemeral operations (CI, previews, dry-run merges)
407
- * where you need full read-write semantics but must not
408
- * mutate the real repository.
409
- *
410
424
  * ```ts
411
425
  * const ephemeral = overlayRepo(storage.repo("my-repo"));
412
- * // writes succeed but only exist in memory
413
426
  * await ephemeral.objectStore.write("blob", content);
414
427
  * // original repo is untouched
415
428
  * ```
416
429
  */
417
430
  declare function overlayRepo(repo: GitRepo): GitRepo;
418
- /**
419
- * Create an ephemeral worktree backed by overlay stores and a lazy filesystem.
420
- *
421
- * - Object/ref writes go to an in-memory overlay (real repo untouched)
422
- * - Worktree files are read lazily from the object store on demand
423
- * - All state is discarded when the returned context goes out of scope
424
- *
425
- * Designed for server hooks that need to run tools against pushed code
426
- * without paying the cost of materializing the entire tree and without
427
- * risking mutation of the real repository.
428
- *
429
- * ```ts
430
- * hooks: {
431
- * async preReceive({ repo, updates }) {
432
- * const { ctx } = await createSandboxWorktree(repo, {
433
- * ref: updates[0].newHash,
434
- * });
435
- * const git = createGit({
436
- * objectStore: ctx.objectStore,
437
- * refStore: ctx.refStore,
438
- * });
439
- * const bash = new Bash({ fs: ctx.fs, cwd: ctx.workTree! });
440
- * const result = await bash.exec("cat package.json");
441
- * // reads lazily from object store — only touched files are loaded
442
- * }
443
- * }
444
- * ```
445
- */
446
- declare function createSandboxWorktree(repo: GitRepo, options?: {
447
- ref?: string;
448
- workTree?: string;
449
- gitDir?: string;
450
- }): Promise<WorktreeResult>;
451
-
452
- /**
453
- * Git object storage: compressed loose objects for new writes, with
454
- * retained packfiles from fetch/clone. Pack indices are loaded eagerly
455
- * during discovery for fast hash lookups; pack data is loaded lazily
456
- * on first read from each pack.
457
- */
458
- declare class PackedObjectStore implements ObjectStore {
459
- private fs;
460
- private gitDir;
461
- private packs;
462
- private loadedPackNames;
463
- private discoverPromise;
464
- private cache;
465
- private packDir;
466
- constructor(fs: FileSystem, gitDir: string, cacheMaxBytes?: number);
467
- write(type: ObjectType, content: Uint8Array): Promise<ObjectId>;
468
- read(hash: ObjectId): Promise<RawObject>;
469
- exists(hash: ObjectId): Promise<boolean>;
470
- ingestPack(packData: Uint8Array): Promise<number>;
471
- ingestPackStream(entries: AsyncIterable<PackObject>): Promise<number>;
472
- invalidatePacks(): void;
473
- findByPrefix(prefix: string): Promise<ObjectId[]>;
474
- /** Load the pack data for a slot on demand. */
475
- private ensureReader;
476
- /** Scan `.git/objects/pack/` for existing pack/idx pairs. */
477
- private discover;
478
- private doDiscover;
479
- }
480
-
481
- /**
482
- * Default filesystem-backed ref storage. Reads/writes loose ref files
483
- * under `.git/`, with `packed-refs` as fallback for reads and listings.
484
- */
485
- declare class FileSystemRefStore implements RefStore {
486
- private fs;
487
- private gitDir;
488
- private casLocks;
489
- constructor(fs: FileSystem, gitDir: string);
490
- readRef(name: string): Promise<Ref | null>;
491
- writeRef(name: string, refOrHash: Ref | string): Promise<void>;
492
- deleteRef(name: string): Promise<void>;
493
- listRefs(prefix?: string): Promise<RefEntry[]>;
494
- compareAndSwapRef(name: string, expectedOldHash: string | null, newRef: Ref | null): Promise<boolean>;
495
- private compareAndSwapUnsafe;
496
- private resolveRefInternal;
497
- private readPackedRefs;
498
- private removePackedRef;
499
- private walkRefs;
500
- }
501
431
 
502
- export { type BlameEntry, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, type DiffHunk, type ExtractTreeResult, type FileDiff, FileSystemRefStore, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, blame, countAheadBehind, createCommit, createSandboxWorktree, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, walkCommitHistory, writeBlob, writeTree };
432
+ export { type BlameEntry, Commit, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, type DiffHunk, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, Identity, type MergeConflict, type MergeTreesResult, RefEntry, TreeDiffEntry, type TreeEntryInput, type WorktreeResult, blame, countAheadBehind, createCommit, createSandboxWorktree, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, walkCommitHistory, writeBlob, writeTree };