just-git 1.2.13 → 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;
@@ -103,6 +103,50 @@ declare function readBlobText(repo: GitRepo, hash: string): Promise<string>;
103
103
  declare function flattenTree(repo: GitRepo, treeHash: string): Promise<FlatTreeEntry[]>;
104
104
  /** Diff two tree objects and return the list of added/deleted/modified entries. Pass null for an empty tree. */
105
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[]>;
106
150
  /** Find the merge base(s) of two commits. Returns one hash for most cases, multiple for criss-cross merges. */
107
151
  declare function findMergeBases(repo: GitRepo, commitA: string, commitB: string): Promise<string[]>;
108
152
  /** Result of a tree-level merge via {@link mergeTrees} or {@link mergeTreesFromTreeHashes}. */
@@ -193,8 +237,8 @@ declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
193
237
  * Returns null if the file doesn't exist at that commit.
194
238
  */
195
239
  declare function readFileAtCommit(repo: GitRepo, commitHash: string, filePath: string): Promise<string | null>;
196
- /** Result of {@link checkoutTo}. */
197
- interface CheckoutToResult {
240
+ /** Result of {@link extractTree}. */
241
+ interface ExtractTreeResult {
198
242
  commitHash: string;
199
243
  treeHash: string;
200
244
  filesWritten: number;
@@ -209,7 +253,7 @@ interface CheckoutToResult {
209
253
  * Useful inside server hooks and platform callbacks to inspect, build,
210
254
  * or lint the code at a given commit without affecting the repo itself.
211
255
  */
212
- 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>;
213
257
  interface CreateWorktreeOptions {
214
258
  /** Ref name or commit hash to check out (default: "HEAD"). */
215
259
  ref?: string;
@@ -240,7 +284,7 @@ interface WorktreeResult {
240
284
  * command handlers use the shared stores instead of the VFS:
241
285
  *
242
286
  * ```ts
243
- * const repo = storage.repo("my-repo");
287
+ * const repo = await storage.createRepo("my-repo");
244
288
  * const fs = new InMemoryFs();
245
289
  * const { ctx } = await createWorktree(repo, fs);
246
290
  * const git = createGit({
@@ -272,11 +316,17 @@ declare function blame(repo: GitRepo, commitHash: string, path: string, opts?: {
272
316
  /**
273
317
  * Walk the commit graph starting from one or more hashes, yielding
274
318
  * commits in reverse chronological order. Supports excluding commits
275
- * 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>`).
276
325
  */
277
326
  declare function walkCommitHistory(repo: GitRepo, startHash: string | string[], opts?: {
278
327
  exclude?: string[];
279
328
  firstParent?: boolean;
329
+ paths?: string[];
280
330
  }): AsyncGenerator<CommitInfo>;
281
331
  /** Options for {@link grep}. */
282
332
  interface GrepOptions {
@@ -345,6 +395,59 @@ declare function grep(repo: GitRepo, commitHash: string, patterns: (string | Reg
345
395
  * ```
346
396
  */
347
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>;
348
451
 
349
452
  /**
350
453
  * Git object storage: compressed loose objects for new writes, with
@@ -365,6 +468,7 @@ declare class PackedObjectStore implements ObjectStore {
365
468
  read(hash: ObjectId): Promise<RawObject>;
366
469
  exists(hash: ObjectId): Promise<boolean>;
367
470
  ingestPack(packData: Uint8Array): Promise<number>;
471
+ ingestPackStream(entries: AsyncIterable<PackObject>): Promise<number>;
368
472
  invalidatePacks(): void;
369
473
  findByPrefix(prefix: string): Promise<ObjectId[]>;
370
474
  /** Load the pack data for a slot on demand. */
@@ -395,4 +499,4 @@ declare class FileSystemRefStore implements RefStore {
395
499
  private walkRefs;
396
500
  }
397
501
 
398
- export { type BlameEntry, type CheckoutToResult, type CommitInfo, type CreateCommitOptions, type CreateWorktreeOptions, FileSystemRefStore, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, Identity, type MergeConflict, type MergeTreesResult, PackedObjectStore, type TreeEntryInput, type WorktreeResult, blame, checkoutTo, countAheadBehind, createCommit, createWorktree, diffTrees, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, 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 };