just-git 1.2.12 → 1.3.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.
@@ -1,4 +1,4 @@
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, a as RefStore, a4 as Ref } from '../hooks-4DvkF2xT.js';
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';
2
2
 
3
3
  interface BlameEntry {
4
4
  hash: ObjectId;
@@ -18,6 +18,15 @@ interface BlameEntry {
18
18
  };
19
19
  }
20
20
 
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
+
21
30
  interface MergeConflict {
22
31
  path: string;
23
32
  reason: "content" | "delete-modify" | "add-add" | "rename-delete" | "rename-rename" | "directory-rename";
@@ -94,6 +103,50 @@ declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
94
103
  declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
95
104
  /** Diff two tree objects and return the list of added/deleted/modified entries. Pass null for an empty tree. */
96
105
  declare function diffTrees(repo: GitRepo, treeA: string | null, treeB: string | null): Promise<TreeDiffEntry[]>;
106
+ /** A single hunk in a file diff. */
107
+ interface DiffHunk {
108
+ oldStart: number;
109
+ oldCount: number;
110
+ newStart: number;
111
+ newCount: number;
112
+ /** Lines prefixed with ' ' (context), '+' (insert), or '-' (delete). */
113
+ lines: string[];
114
+ }
115
+ /** One file's diff between two commits. */
116
+ interface FileDiff {
117
+ path: string;
118
+ status: "added" | "modified" | "deleted" | "renamed";
119
+ /** Original path when status is "renamed". */
120
+ oldPath?: string;
121
+ /** Similarity percentage (0–100) for renames. */
122
+ similarity?: number;
123
+ hunks: DiffHunk[];
124
+ }
125
+ /**
126
+ * Produce structured, line-level diffs between two commits.
127
+ *
128
+ * Accepts commit hashes or ref names. Returns one `FileDiff` per
129
+ * changed file, each containing hunks with prefixed diff lines.
130
+ * Rename detection is enabled by default.
131
+ *
132
+ * ```ts
133
+ * const diffs = await diffCommits(repo, "main", "feature");
134
+ * for (const file of diffs) {
135
+ * console.log(`${file.status} ${file.path}`);
136
+ * for (const hunk of file.hunks) {
137
+ * for (const line of hunk.lines) console.log(line);
138
+ * }
139
+ * }
140
+ * ```
141
+ */
142
+ declare function diffCommits(repo: GitRepo, base: string, head: string, options?: {
143
+ /** Only include files matching these paths (exact prefix match). */
144
+ paths?: string[];
145
+ /** Number of context lines around each change (default 3). */
146
+ contextLines?: number;
147
+ /** Enable rename detection (default true). */
148
+ renames?: boolean;
149
+ }): Promise<FileDiff[]>;
97
150
  /** Find the merge base(s) of two commits. Returns one hash for most cases, multiple for criss-cross merges. */
98
151
  declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
99
152
  /** Result of a tree-level merge via {@link mergeTrees} or {@link mergeTreesFromTreeHashes}. */
@@ -184,8 +237,8 @@ declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
184
237
  * Returns null if the file doesn't exist at that commit.
185
238
  */
186
239
  declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
187
- /** Result of {@link checkoutTo}. */
188
- interface CheckoutToResult {
240
+ /** Result of {@link extractTree}. */
241
+ interface ExtractTreeResult {
189
242
  commitHash: string;
190
243
  treeHash: string;
191
244
  filesWritten: number;
@@ -200,7 +253,7 @@ interface CheckoutToResult {
200
253
  * Useful inside server hooks and platform callbacks to inspect, build,
201
254
  * or lint the code at a given commit without affecting the repo itself.
202
255
  */
203
- declare function checkoutTo(repo: GitRepo, refOrHash: string, fs: FileSystem, targetDir?: string): Promise<CheckoutToResult>;
256
+ declare function extractTree(repo: GitRepo, refOrHash: string, fs: FileSystem, targetDir?: string): Promise<ExtractTreeResult>;
204
257
  interface CreateWorktreeOptions {
205
258
  /** Ref name or commit hash to check out (default: "HEAD"). */
206
259
  ref?: string;
@@ -231,7 +284,7 @@ interface WorktreeResult {
231
284
  * command handlers use the shared stores instead of the VFS:
232
285
  *
233
286
  * ```ts
234
- * const repo = storage.repo("my-repo");
287
+ * const repo = await storage.createRepo("my-repo");
235
288
  * const fs = new InMemoryFs();
236
289
  * const { ctx } = await createWorktree(repo, fs);
237
290
  * const git = createGit({
@@ -263,12 +316,64 @@ declare function blame(repo: GitRepo, commitHash: string, path: string, opts?: {
263
316
  /**
264
317
  * Walk the commit graph starting from one or more hashes, yielding
265
318
  * commits in reverse chronological order. Supports excluding commits
266
- * reachable from specified hashes and following only first parents.
319
+ * reachable from specified hashes, following only first parents, and
320
+ * filtering to commits that touch specific paths.
321
+ *
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>`).
267
325
  */
268
326
  declare function walkCommitHistory(repo: GitRepo, startHash: string | string[], opts?: {
269
327
  exclude?: string[];
270
328
  firstParent?: boolean;
329
+ paths?: string[];
271
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.
362
+ *
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.
366
+ *
367
+ * ```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}`);
372
+ * }
373
+ * }
374
+ * ```
375
+ */
376
+ declare function grep(repo: GitRepo, commitHash: string, patterns: (string | RegExp)[], options?: GrepOptions): Promise<GrepFileMatch[]>;
272
377
  /**
273
378
  * Wrap a `GitRepo` so all write operations throw.
274
379
  *
@@ -290,6 +395,59 @@ declare function walkCommitHistory(repo: GitRepo, startHash: string | string[],
290
395
  * ```
291
396
  */
292
397
  declare function readonlyRepo(repo: GitRepo): GitRepo;
398
+ /**
399
+ * Wrap a `GitRepo` with copy-on-write overlay stores.
400
+ *
401
+ * Read operations pass through to the underlying stores.
402
+ * Write operations (write, writeRef, deleteRef, ingestPack,
403
+ * compareAndSwapRef) are captured in an in-memory overlay
404
+ * and never reach the inner repo.
405
+ *
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
+ * ```ts
411
+ * const ephemeral = overlayRepo(storage.repo("my-repo"));
412
+ * // writes succeed but only exist in memory
413
+ * await ephemeral.objectStore.write("blob", content);
414
+ * // original repo is untouched
415
+ * ```
416
+ */
417
+ 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>;
293
451
 
294
452
  /**
295
453
  * Git object storage: compressed loose objects for new writes, with
@@ -310,6 +468,7 @@ declare class PackedObjectStore implements ObjectStore {
310
468
  read(hash: ObjectId): Promise<RawObject>;
311
469
  exists(hash: ObjectId): Promise<boolean>;
312
470
  ingestPack(packData: Uint8Array): Promise<number>;
471
+ ingestPackStream(entries: AsyncIterable<PackObject>): Promise<number>;
313
472
  invalidatePacks(): void;
314
473
  findByPrefix(prefix: string): Promise<ObjectId[]>;
315
474
  /** Load the pack data for a slot on demand. */
@@ -340,4 +499,4 @@ declare class FileSystemRefStore implements RefStore {
340
499
  private walkRefs;
341
500
  }
342
501
 
343
- export { type BlameEntry, type CheckoutToResult, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, FileSystemRefStore, GitRepo, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, blame, checkoutTo, countAheadBehind, createCommit, createWorktree, diffTrees, findMergeBases, flattenTree, getChangedFiles, getNewCommits, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, readBlob, readBlobText, readCommit, readFileAtCommit, readonlyRepo, resolveRef, walkCommitHistory, writeBlob, writeTree };
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 };