just-git 1.3.6 → 1.3.9

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.
package/README.md CHANGED
@@ -61,7 +61,17 @@ Both `fs` and `cwd` can be set once in `createGit` and overridden per-call. `cwd
61
61
 
62
62
  ### Server
63
63
 
64
- Stand up a git server with built-in storage (SQLite or PostgreSQL), branch protection, auth, and push hooks:
64
+ Stand up a git server in two lines. Storage defaults to in-memory; swap in SQLite, PostgreSQL, or your own backend for persistence:
65
+
66
+ ```ts
67
+ import { createServer } from "just-git/server";
68
+
69
+ const server = createServer({ autoCreate: true });
70
+ Bun.serve({ fetch: server.fetch });
71
+ // git push http://localhost:3000/my-repo main ← repo created on first push
72
+ ```
73
+
74
+ Add branch protection, auth, and push hooks as needed:
65
75
 
66
76
  ```ts
67
77
  import { createServer, BunSqliteStorage } from "just-git/server";
@@ -74,23 +84,22 @@ const server = createServer({
74
84
  policy: { protectedBranches: ["main"] },
75
85
  hooks: {
76
86
  preReceive: ({ session }) => {
77
- if (!session?.request?.headers.has("Authorization"))
87
+ if (!session.request?.headers.has("Authorization"))
78
88
  return { reject: true, message: "unauthorized" };
79
89
  },
80
- postReceive: async ({ repo, repoPath, updates }) => {
90
+ postReceive: async ({ repo, repoId, updates }) => {
81
91
  for (const u of updates) {
82
92
  const files = await getChangedFiles(repo, u.oldHash, u.newHash);
83
- console.log(`${repoPath}: ${u.ref} — ${files.length} files changed`);
93
+ console.log(`${repoId}: ${u.ref} — ${files.length} files changed`);
84
94
  }
85
95
  },
86
96
  },
87
97
  });
88
98
 
89
99
  Bun.serve({ fetch: server.fetch });
90
- // git clone http://localhost:3000/my-repo ← works with real git
91
100
  ```
92
101
 
93
- Uses web-standard `Request`/`Response`. Works with Bun, Hono, Cloudflare Workers, or any fetch-compatible runtime. For Node.js, use `server.nodeHandler` with `http.createServer` and `BetterSqlite3Storage` for `better-sqlite3`. SSH is supported via `server.handleSession`. See [SERVER.md](docs/SERVER.md) for the full API.
102
+ Uses web-standard `Request`/`Response`. Works with Bun, Hono, Cloudflare Workers, or any fetch-compatible runtime. For Node.js, use `server.nodeHandler` with `http.createServer` and `BetterSqlite3Storage` for `better-sqlite3`. SSH is supported via `server.handleSession`. The [`Storage` interface](docs/SERVER.md#custom-storage) is small enough to plug in any datastore. See [SERVER.md](docs/SERVER.md) for the full API.
94
103
 
95
104
  ## Repo module
96
105
 
@@ -389,7 +389,7 @@ interface PostCommitEvent {
389
389
  /** Fired before a three-way merge commit is written. Return a {@link Rejection} to block. */
390
390
  interface PreMergeCommitEvent {
391
391
  readonly repo: GitRepo;
392
- readonly mergeMessage: string;
392
+ readonly message: string;
393
393
  readonly treeHash: ObjectId;
394
394
  readonly headHash: ObjectId;
395
395
  readonly theirsHash: ObjectId;
@@ -435,7 +435,7 @@ interface PreRebaseEvent {
435
435
  interface PreCheckoutEvent {
436
436
  readonly repo: GitRepo;
437
437
  readonly target: string;
438
- readonly mode: "switch" | "detach" | "create-branch" | "paths";
438
+ readonly mode: "switch" | "detach" | "create-branch";
439
439
  }
440
440
  /** Fired before a fetch begins. Return a {@link Rejection} to block. */
441
441
  interface PreFetchEvent {
@@ -451,7 +451,7 @@ interface PostFetchEvent {
451
451
  readonly repo: GitRepo;
452
452
  readonly remote: string;
453
453
  readonly url: string;
454
- readonly refsUpdated: number;
454
+ readonly updatedRefCount: number;
455
455
  }
456
456
  /** Fired before a clone begins. Return a {@link Rejection} to block. */
457
457
  interface PreCloneEvent {
@@ -487,7 +487,7 @@ interface PostPullEvent {
487
487
  interface PreResetEvent {
488
488
  readonly repo: GitRepo;
489
489
  readonly mode: "soft" | "mixed" | "hard" | "paths";
490
- readonly target: string | null;
490
+ readonly targetRef: string | null;
491
491
  }
492
492
  /** Fired after a reset completes. */
493
493
  interface PostResetEvent {
@@ -495,72 +495,34 @@ interface PostResetEvent {
495
495
  readonly mode: "soft" | "mixed" | "hard" | "paths";
496
496
  readonly targetHash: ObjectId | null;
497
497
  }
498
- /** Fired before `git clean`. Return a {@link Rejection} to block. */
499
- interface PreCleanEvent {
500
- readonly repo: GitRepo;
501
- readonly dryRun: boolean;
502
- readonly force: boolean;
503
- readonly removeDirs: boolean;
504
- readonly removeIgnored: boolean;
505
- readonly onlyIgnored: boolean;
506
- }
507
- /** Fired after `git clean` completes. */
508
- interface PostCleanEvent {
498
+ /** Base type for pre-hooks that apply a commit (cherry-pick, revert). */
499
+ interface PreApplyEvent {
509
500
  readonly repo: GitRepo;
510
- readonly removed: readonly string[];
511
- readonly dryRun: boolean;
501
+ readonly mode: string;
502
+ readonly commitRef: string | null;
512
503
  }
513
- /** Fired before `git rm`. Return a {@link Rejection} to block. */
514
- interface PreRmEvent {
504
+ /** Base type for post-hooks that apply a commit (cherry-pick, revert). */
505
+ interface PostApplyEvent {
515
506
  readonly repo: GitRepo;
516
- readonly paths: readonly string[];
517
- readonly cached: boolean;
518
- readonly recursive: boolean;
519
- readonly force: boolean;
520
- }
521
- /** Fired after `git rm` completes. */
522
- interface PostRmEvent {
523
- readonly repo: GitRepo;
524
- readonly removedPaths: readonly string[];
525
- readonly cached: boolean;
507
+ readonly mode: string;
508
+ readonly commitHash: ObjectId | null;
509
+ readonly hadConflicts: boolean;
526
510
  }
527
511
  /** Fired before a cherry-pick. Return a {@link Rejection} to block. */
528
- interface PreCherryPickEvent {
529
- readonly repo: GitRepo;
512
+ interface PreCherryPickEvent extends PreApplyEvent {
530
513
  readonly mode: "pick" | "continue" | "abort";
531
- readonly commit: string | null;
532
514
  }
533
515
  /** Fired after a cherry-pick completes. */
534
- interface PostCherryPickEvent {
535
- readonly repo: GitRepo;
516
+ interface PostCherryPickEvent extends PostApplyEvent {
536
517
  readonly mode: "pick" | "continue" | "abort";
537
- readonly commitHash: ObjectId | null;
538
- readonly hadConflicts: boolean;
539
518
  }
540
519
  /** Fired before a revert. Return a {@link Rejection} to block. */
541
- interface PreRevertEvent {
542
- readonly repo: GitRepo;
520
+ interface PreRevertEvent extends PreApplyEvent {
543
521
  readonly mode: "revert" | "continue" | "abort";
544
- readonly commit: string | null;
545
522
  }
546
523
  /** Fired after a revert completes. */
547
- interface PostRevertEvent {
548
- readonly repo: GitRepo;
524
+ interface PostRevertEvent extends PostApplyEvent {
549
525
  readonly mode: "revert" | "continue" | "abort";
550
- readonly commitHash: ObjectId | null;
551
- readonly hadConflicts: boolean;
552
- }
553
- /** Fired before a stash operation. Return a {@link Rejection} to block. */
554
- interface PreStashEvent {
555
- readonly repo: GitRepo;
556
- readonly action: "push" | "pop" | "apply" | "list" | "drop" | "show" | "clear";
557
- readonly ref: string | null;
558
- }
559
- /** Fired after a stash operation completes. */
560
- interface PostStashEvent {
561
- readonly repo: GitRepo;
562
- readonly action: "push" | "pop" | "apply" | "list" | "drop" | "show" | "clear";
563
- readonly ok: boolean;
564
526
  }
565
527
  /** Fired whenever a ref is created or updated. */
566
528
  interface RefUpdateEvent {
@@ -620,11 +582,8 @@ interface GitHooks {
620
582
  prePull?: (event: PrePullEvent) => PreHookReturn;
621
583
  preRebase?: (event: PreRebaseEvent) => PreHookReturn;
622
584
  preReset?: (event: PreResetEvent) => PreHookReturn;
623
- preClean?: (event: PreCleanEvent) => PreHookReturn;
624
- preRm?: (event: PreRmEvent) => PreHookReturn;
625
585
  preCherryPick?: (event: PreCherryPickEvent) => PreHookReturn;
626
586
  preRevert?: (event: PreRevertEvent) => PreHookReturn;
627
- preStash?: (event: PreStashEvent) => PreHookReturn;
628
587
  postCommit?: (event: PostCommitEvent) => PostHookReturn;
629
588
  postMerge?: (event: PostMergeEvent) => PostHookReturn;
630
589
  postCheckout?: (event: PostCheckoutEvent) => PostHookReturn;
@@ -633,11 +592,8 @@ interface GitHooks {
633
592
  postClone?: (event: PostCloneEvent) => PostHookReturn;
634
593
  postPull?: (event: PostPullEvent) => PostHookReturn;
635
594
  postReset?: (event: PostResetEvent) => PostHookReturn;
636
- postClean?: (event: PostCleanEvent) => PostHookReturn;
637
- postRm?: (event: PostRmEvent) => PostHookReturn;
638
595
  postCherryPick?: (event: PostCherryPickEvent) => PostHookReturn;
639
596
  postRevert?: (event: PostRevertEvent) => PostHookReturn;
640
- postStash?: (event: PostStashEvent) => PostHookReturn;
641
597
  onRefUpdate?: (event: RefUpdateEvent) => void;
642
598
  onRefDelete?: (event: RefDeleteEvent) => void;
643
599
  onObjectWrite?: (event: ObjectWriteEvent) => void;
@@ -653,4 +609,4 @@ interface GitHooks {
653
609
  */
654
610
  declare function composeGitHooks(...hookSets: (GitHooks | undefined)[]): GitHooks;
655
611
 
656
- export { type Ref as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type DirectRef as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PreCleanEvent as J, type PreCloneEvent as K, type PreCommitEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PackObject as P, type PreFetchEvent as Q, type RemoteResolver as R, type PreMergeCommitEvent as S, type PrePullEvent as T, type PrePushEvent as U, type PreRebaseEvent as V, type PreResetEvent as W, type PreRevertEvent as X, type PreRmEvent as Y, type PreStashEvent as Z, type RawObject as _, type RefStore as a, type RefDeleteEvent as a0, type RefEntry as a1, type RefUpdateEvent as a2, type Rejection as a3, type SymbolicRef as a4, composeGitHooks as a5, isRejection as a6, type TreeEntry as a7, type TreeDiffEntry as a8, type ConfigOverrides as b, type FileStat as c, type GitContext as d, type Commit as e, type CommitMsgEvent as f, type GitRepo as g, type Identity as h, type ObjectId as i, type ObjectType as j, type ObjectWriteEvent as k, type PostCheckoutEvent as l, type PostCherryPickEvent as m, type PostCleanEvent as n, type PostCloneEvent as o, type PostCommitEvent as p, type PostFetchEvent as q, type PostMergeEvent as r, type PostPullEvent as s, type PostPushEvent as t, type PostResetEvent as u, type PostRevertEvent as v, type PostRmEvent as w, type PostStashEvent as x, type PreCheckoutEvent as y, type PreCherryPickEvent as z };
612
+ export { type Rejection as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type DirectRef as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PreCommitEvent as J, type PreFetchEvent as K, type PreMergeCommitEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PackObject as P, type PrePullEvent as Q, type RemoteResolver as R, type PrePushEvent as S, type PreRebaseEvent as T, type PreResetEvent as U, type PreRevertEvent as V, type RawObject as W, type Ref as X, type RefDeleteEvent as Y, type RefEntry as Z, type RefUpdateEvent as _, type RefStore as a, type SymbolicRef as a0, composeGitHooks as a1, isRejection as a2, type TreeEntry as a3, type TreeDiffEntry as a4, type ConfigOverrides as b, type FileStat as c, type GitContext as d, type Commit as e, type CommitMsgEvent as f, type GitRepo as g, type Identity as h, type ObjectId as i, type ObjectType as j, type ObjectWriteEvent as k, type PostApplyEvent as l, type PostCheckoutEvent as m, type PostCherryPickEvent as n, type PostCloneEvent as o, type PostCommitEvent as p, type PostFetchEvent as q, type PostMergeEvent as r, type PostPullEvent as s, type PostPushEvent as t, type PostResetEvent as u, type PostRevertEvent as v, type PreApplyEvent as w, type PreCheckoutEvent as x, type PreCherryPickEvent as y, type PreCloneEvent as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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-DNBNCTgb.js';
2
- export { A as AfterCommandEvent, B as BeforeCommandEvent, e as Commit, f as CommitMsgEvent, D as DirectRef, g as GitRepo, H as HttpAuth, h as Identity, M as MergeMsgEvent, i as ObjectId, j as ObjectType, k as ObjectWriteEvent, P as PackObject, l as PostCheckoutEvent, m as PostCherryPickEvent, n as PostCleanEvent, o as PostCloneEvent, p as PostCommitEvent, q as PostFetchEvent, r as PostMergeEvent, s as PostPullEvent, t as PostPushEvent, u as PostResetEvent, v as PostRevertEvent, w as PostRmEvent, x as PostStashEvent, y as PreCheckoutEvent, z as PreCherryPickEvent, J as PreCleanEvent, K as PreCloneEvent, L as PreCommitEvent, Q as PreFetchEvent, S as PreMergeCommitEvent, T as PrePullEvent, U as PrePushEvent, V as PreRebaseEvent, W as PreResetEvent, X as PreRevertEvent, Y as PreRmEvent, Z as PreStashEvent, _ as RawObject, $ as Ref, a0 as RefDeleteEvent, a1 as RefEntry, a2 as RefUpdateEvent, a3 as Rejection, a4 as SymbolicRef, a5 as composeGitHooks, a6 as isRejection } from './hooks-DNBNCTgb.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-C7c_BLqp.js';
2
+ export { A as AfterCommandEvent, B as BeforeCommandEvent, e as Commit, f as CommitMsgEvent, D as DirectRef, g as GitRepo, H as HttpAuth, h as Identity, M as MergeMsgEvent, i as ObjectId, j as ObjectType, k as ObjectWriteEvent, P as PackObject, l as PostApplyEvent, m as PostCheckoutEvent, n as PostCherryPickEvent, o as PostCloneEvent, p as PostCommitEvent, q as PostFetchEvent, r as PostMergeEvent, s as PostPullEvent, t as PostPushEvent, u as PostResetEvent, v as PostRevertEvent, w as PreApplyEvent, x as PreCheckoutEvent, y as PreCherryPickEvent, z as PreCloneEvent, J as PreCommitEvent, K as PreFetchEvent, L as PreMergeCommitEvent, Q as PrePullEvent, S as PrePushEvent, T as PreRebaseEvent, U as PreResetEvent, V as PreRevertEvent, W as RawObject, X as Ref, Y as RefDeleteEvent, Z as RefEntry, _ as RefUpdateEvent, $ as Rejection, a0 as SymbolicRef, a1 as composeGitHooks, a2 as isRejection } from './hooks-C7c_BLqp.js';
3
3
 
4
4
  /** Options for subcommand execution (mirrors just-bash's CommandExecOptions). */
5
5
  interface CommandExecOptions {