just-git 1.5.5 → 1.5.7

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,5 +1,5 @@
1
1
  import { g as GitRepo, Z as RefEntry, e as Commit, a3 as TreeEntry, i as ObjectId, h as Identity, a4 as TreeDiffEntry, d as GitContext, F as FileSystem } from '../hooks-CimfP56a.js';
2
- export { B as BuildCommitOptions, C as CommitAuthor, a as CommitIdentity, b as CommitOptions, c as CommitResult, d as CreateAnnotatedTagOptions, e as CreateCommitOptions, T as TreeEntryInput, f as TreeUpdate, g as buildCommit, h as commit, i as createAnnotatedTag, j as createCommit, u as updateTree, w as writeBlob, k as writeTree } from '../writing-IwfRRrts.js';
2
+ export { B as BuildCommitOptions, b as CommitAuthor, c as CommitIdentity, C as CommitOptions, a as CommitResult, d as CreateAnnotatedTagOptions, e as CreateCommitOptions, T as TreeEntryInput, f as TreeUpdate, g as buildCommit, h as commit, i as createAnnotatedTag, j as createCommit, u as updateTree, w as writeBlob, k as writeTree } from '../writing-CF-eYohc.js';
3
3
 
4
4
  /** Extract the short branch name from a full ref path like "refs/heads/main" → "main". */
5
5
  declare function branchNameFromRef(ref: string): string;
@@ -200,6 +200,15 @@ interface FileDiff {
200
200
  similarity?: number;
201
201
  hunks: DiffHunk[];
202
202
  }
203
+ /** Shared options for {@link diffCommits} and {@link formatDiff}. */
204
+ interface DiffOptions {
205
+ /** Only include files matching these paths (exact prefix match). */
206
+ paths?: string[];
207
+ /** Number of context lines around each change (default 3). */
208
+ contextLines?: number;
209
+ /** Enable rename detection (default true). */
210
+ renames?: boolean;
211
+ }
203
212
  /**
204
213
  * Produce structured, line-level diffs between two commits.
205
214
  *
@@ -217,14 +226,19 @@ interface FileDiff {
217
226
  * }
218
227
  * ```
219
228
  */
220
- declare function diffCommits(repo: GitRepo, base: string, head: string, options?: {
221
- /** Only include files matching these paths (exact prefix match). */
222
- paths?: string[];
223
- /** Number of context lines around each change (default 3). */
224
- contextLines?: number;
225
- /** Enable rename detection (default true). */
226
- renames?: boolean;
227
- }): Promise<FileDiff[]>;
229
+ declare function diffCommits(repo: GitRepo, base: string, head: string, options?: DiffOptions): Promise<FileDiff[]>;
230
+ /**
231
+ * Produce a unified diff (patch) string between two commits.
232
+ *
233
+ * Uses `formatUnifiedDiff` directly — the same formatter behind
234
+ * `git diff` so the output is byte-identical to CLI output
235
+ * and natively consumable by any unified-diff parser.
236
+ *
237
+ * ```ts
238
+ * const diff = await formatDiff(repo, "main~1", "main");
239
+ * ```
240
+ */
241
+ declare function formatDiff(repo: GitRepo, base: string, head: string, options?: DiffOptions): Promise<string>;
228
242
  /**
229
243
  * Walk the commit graph starting from one or more hashes, yielding
230
244
  * commits in reverse chronological order. Supports excluding commits
@@ -391,6 +405,141 @@ declare function createSandboxWorktree(repo: GitRepo, options?: {
391
405
  gitDir?: string;
392
406
  }): Promise<WorktreeResult>;
393
407
 
408
+ /** Minimal filesystem surface needed to write a materialized tree. */
409
+ interface MaterializeTarget {
410
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
411
+ mkdir(path: string, options?: {
412
+ recursive?: boolean;
413
+ }): Promise<void>;
414
+ symlink?(target: string, path: string): Promise<void>;
415
+ }
416
+
417
+ /**
418
+ * Lazy accessor for the worktree contents at a specific tree.
419
+ *
420
+ * Provides progressively richer access to files without requiring
421
+ * upfront materialization:
422
+ *
423
+ * - {@link readFile} / {@link readFileBytes} — read a single file (O(tree depth), no flatten)
424
+ * - {@link files} — list all tracked file paths (walks tree objects, no blob reads)
425
+ * - {@link fs} — get a full {@link FileSystem} view (lazy reads, in-memory writes)
426
+ * - {@link materialize} — write all tracked files onto a target filesystem
427
+ */
428
+ interface TreeAccessor {
429
+ /** The underlying git tree object hash. */
430
+ readonly treeHash: string;
431
+ /** Read a file's text content. Returns `null` if the file doesn't exist. */
432
+ readFile(path: string): Promise<string | null>;
433
+ /** Read a file's raw bytes. Returns `null` if the file doesn't exist. */
434
+ readFileBytes(path: string): Promise<Uint8Array | null>;
435
+ /** List all tracked file paths (no blob content is read). */
436
+ files(): Promise<string[]>;
437
+ /**
438
+ * Get a full `FileSystem` backed by this tree.
439
+ *
440
+ * Files are read lazily from the object store on demand.
441
+ * Writes go to an in-memory overlay and never touch the repo.
442
+ * Created once on first call, then cached for the lifetime of this accessor.
443
+ */
444
+ fs(root?: string): FileSystem;
445
+ /**
446
+ * Write all tracked files onto a filesystem.
447
+ *
448
+ * @param target — target filesystem (only needs `mkdir`, `writeFile`,
449
+ * and optionally `symlink`)
450
+ * @param targetDir — root directory on the target fs (default `"/"`)
451
+ * @returns the number of files written
452
+ */
453
+ materialize(target: MaterializeTarget, targetDir?: string): Promise<number>;
454
+ }
455
+ /**
456
+ * Create a lazy {@link TreeAccessor} for a git tree hash.
457
+ *
458
+ * Single-file reads use O(tree depth) traversal via {@link TreeBackedFs}.
459
+ * Full-tree operations (`files`, `materialize`) flatten on demand.
460
+ */
461
+ declare function createTreeAccessor(repo: GitRepo, treeHash: string): TreeAccessor;
462
+
463
+ /** Options for {@link bisect}. */
464
+ interface BisectOptions {
465
+ /** Known bad commit (hash, branch, tag, or any rev-parse expression). */
466
+ bad: string;
467
+ /** One or more known good commits. */
468
+ good: string | string[];
469
+ /**
470
+ * Test a candidate commit. Return:
471
+ * - `true` — commit is good (bug not present)
472
+ * - `false` — commit is bad (bug present)
473
+ * - `"skip"` — commit is untestable
474
+ *
475
+ * The `tree` parameter provides lazy access to the worktree contents
476
+ * at the candidate commit — read individual files, list paths, or
477
+ * get a full `FileSystem` for build/test scenarios.
478
+ */
479
+ test: (hash: string, tree: TreeAccessor) => boolean | "skip" | Promise<boolean | "skip">;
480
+ /** Follow only first parent at merge commits (default false). */
481
+ firstParent?: boolean;
482
+ /** Called after each step with progress info. */
483
+ onStep?: (info: BisectStepInfo) => void;
484
+ }
485
+ /** Progress info passed to {@link BisectOptions.onStep}. */
486
+ interface BisectStepInfo {
487
+ hash: string;
488
+ subject: string;
489
+ verdict: "good" | "bad" | "skip";
490
+ remaining: number;
491
+ estimatedSteps: number;
492
+ stepNumber: number;
493
+ }
494
+ /**
495
+ * Result of {@link bisect}.
496
+ *
497
+ * - `found: true` — the first bad commit was identified.
498
+ * - `found: false, reason: "all-skipped"` — only skipped commits remain;
499
+ * `candidates` lists them (plus the current bad).
500
+ * - `found: false, reason: "no-testable-commits"` — no commits exist
501
+ * between the good and bad boundaries.
502
+ */
503
+ type BisectSearchResult = {
504
+ found: true;
505
+ hash: string;
506
+ stepsTaken: number;
507
+ } | {
508
+ found: false;
509
+ reason: "all-skipped";
510
+ candidates: string[];
511
+ } | {
512
+ found: false;
513
+ reason: "no-testable-commits";
514
+ };
515
+ /**
516
+ * Binary-search the commit graph to find the first bad commit.
517
+ *
518
+ * Operates purely on the object store — no filesystem, index, working
519
+ * tree, or state files. The caller provides a `test` callback that
520
+ * inspects each candidate commit and returns whether it is good, bad,
521
+ * or should be skipped.
522
+ *
523
+ * Uses the same weighted-midpoint algorithm as `git bisect`: each step
524
+ * picks the commit that maximizes information gain (closest to
525
+ * eliminating half the remaining candidates).
526
+ *
527
+ * ```ts
528
+ * const result = await bisect(repo, {
529
+ * bad: "main",
530
+ * good: "v1.0.0",
531
+ * test: async (hash, tree) => {
532
+ * const content = await tree.readFile("src/config.ts");
533
+ * return content !== null && !content.includes("broken_call");
534
+ * },
535
+ * });
536
+ * if (result.found) {
537
+ * console.log(`First bad commit: ${result.hash}`);
538
+ * }
539
+ * ```
540
+ */
541
+ declare function bisect(repo: GitRepo, options: BisectOptions): Promise<BisectSearchResult>;
542
+
394
543
  /**
395
544
  * Wrap a `GitRepo` so all write operations throw.
396
545
  *
@@ -425,4 +574,4 @@ declare function readonlyRepo(repo: GitRepo): GitRepo;
425
574
  */
426
575
  declare function overlayRepo(repo: GitRepo): GitRepo;
427
576
 
428
- export { type BlameEntry, Commit, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, type HeadInfo, Identity, type MergeConflict, type MergeTreesResult, RefEntry, TreeDiffEntry, TreeEntry, type WorktreeResult, blame, branchNameFromRef, countAheadBehind, createSandboxWorktree, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readHead, readTree, readonlyRepo, resolveRef, tagNameFromRef, walkCommitHistory };
577
+ export { type BisectOptions, type BisectSearchResult, type BisectStepInfo, type BlameEntry, Commit, type CommitInfo, type CreateWorktreeOptions, type DiffHunk, type DiffOptions, type ExtractTreeResult, type FileDiff, type FlatTreeEntry, GitRepo, type GrepFileMatch, type GrepMatch, type GrepOptions, type HeadInfo, Identity, type MaterializeTarget, type MergeConflict, type MergeTreesResult, RefEntry, type TreeAccessor, TreeDiffEntry, TreeEntry, type WorktreeResult, bisect, blame, branchNameFromRef, countAheadBehind, createSandboxWorktree, createTreeAccessor, createWorktree, diffCommits, diffTrees, extractTree, findMergeBases, flattenTree, formatDiff, getChangedFiles, getNewCommits, grep, isAncestor, listBranches, listTags, mergeTrees, mergeTreesFromTreeHashes, overlayRepo, readBlob, readBlobText, readCommit, readFileAtCommit, readHead, readTree, readonlyRepo, resolveRef, tagNameFromRef, walkCommitHistory };