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.
package/README.md CHANGED
@@ -64,31 +64,33 @@ Both `fs` and `cwd` can be set once in `createGit` and overridden per-call. `cwd
64
64
  Stand up a git server with built-in storage (SQLite or PostgreSQL), branch protection, auth, and push hooks:
65
65
 
66
66
  ```ts
67
- import { createGitServer, createStandardHooks, BunSqliteStorage } from "just-git/server";
67
+ import { createServer, BunSqliteStorage } from "just-git/server";
68
68
  import { getChangedFiles } from "just-git/repo";
69
69
  import { Database } from "bun:sqlite";
70
70
 
71
- const storage = new BunSqliteStorage(new Database("repos.sqlite"));
72
-
73
- const server = createGitServer({
74
- resolveRepo: (path) => storage.repo(path),
75
- hooks: createStandardHooks({
76
- protectedBranches: ["main"],
77
- authorizePush: (request) => request.headers.has("Authorization"),
78
- onPush: async ({ repo, repoPath, updates }) => {
71
+ const server = createServer({
72
+ storage: new BunSqliteStorage(new Database("repos.sqlite")),
73
+ autoCreate: true,
74
+ policy: { protectedBranches: ["main"] },
75
+ hooks: {
76
+ preReceive: ({ session }) => {
77
+ if (!session?.request?.headers.has("Authorization"))
78
+ return { reject: true, message: "unauthorized" };
79
+ },
80
+ postReceive: async ({ repo, repoPath, updates }) => {
79
81
  for (const u of updates) {
80
82
  const files = await getChangedFiles(repo, u.oldHash, u.newHash);
81
83
  console.log(`${repoPath}: ${u.ref} — ${files.length} files changed`);
82
84
  }
83
85
  },
84
- }),
86
+ },
85
87
  });
86
88
 
87
89
  Bun.serve({ fetch: server.fetch });
88
90
  // git clone http://localhost:3000/my-repo ← works with real git
89
91
  ```
90
92
 
91
- Uses web-standard `Request`/`Response`. Works with Bun, Hono, Cloudflare Workers, or any fetch-compatible runtime. For Node.js, use `toNodeHandler(server)` with `http.createServer` and `BetterSqlite3Storage` for `better-sqlite3`. Use `withAuth` to gate clone and fetch access as well. See [SERVER.md](docs/SERVER.md) for the full API.
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.
92
94
 
93
95
  ## Repo module
94
96
 
@@ -115,6 +117,7 @@ See [REPO.md](docs/REPO.md) for the full API, the `GitRepo` interface, and the h
115
117
  - **Local paths**: direct filesystem transfer between repositories.
116
118
  - **Cross-VFS**: clone, fetch, and push between isolated in-memory filesystems via `resolveRemote`. See [CLIENT.md](docs/CLIENT.md#multi-agent-collaboration).
117
119
  - **Smart HTTP**: clone, fetch, and push against real Git servers (e.g. GitHub) via Git Smart HTTP protocol. Auth via `credentials` option or `GIT_HTTP_BEARER_TOKEN` / `GIT_HTTP_USER` + `GIT_HTTP_PASSWORD` env vars.
120
+ - **In-process server**: connect a git client to a `GitServer` without any network stack via `server.asNetwork()`. All server hooks, sessions, and policy enforcement work identically to real HTTP. See [CLIENT.md](docs/CLIENT.md#in-process-server).
118
121
 
119
122
  ### Internals
120
123
 
@@ -89,6 +89,13 @@ interface FileSystem {
89
89
  symlink?(target: string, path: string): Promise<void>;
90
90
  }
91
91
 
92
+ /** A fully resolved (non-delta) object from a packfile. */
93
+ interface PackObject {
94
+ type: ObjectType;
95
+ content: Uint8Array;
96
+ hash: ObjectId;
97
+ }
98
+
92
99
  /** 40-character lowercase hex SHA-1 hash. */
93
100
  type ObjectId = string;
94
101
  /** The four Git object types. */
@@ -196,6 +203,12 @@ interface ObjectStore {
196
203
  write(type: ObjectType, content: Uint8Array): Promise<ObjectId>;
197
204
  exists(hash: ObjectId): Promise<boolean>;
198
205
  ingestPack(packData: Uint8Array): Promise<number>;
206
+ /**
207
+ * Ingest pre-resolved objects from a streaming source.
208
+ * Accepts the output of `readPackStreaming` — each yielded
209
+ * `PackObject` has type, content, and hash already computed.
210
+ */
211
+ ingestPackStream(entries: AsyncIterable<PackObject>): Promise<number>;
199
212
  /** Return all object hashes matching a hex prefix (for short hash resolution). */
200
213
  findByPrefix(prefix: string): Promise<ObjectId[]>;
201
214
  /**
@@ -634,4 +647,4 @@ interface GitHooks {
634
647
  */
635
648
  declare function composeGitHooks(...hookSets: (GitHooks | undefined)[]): GitHooks;
636
649
 
637
- export { type Identity as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type PrePullEvent as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PrePushEvent as J, type PreRebaseEvent as K, type PreResetEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PostCheckoutEvent as P, type PreRevertEvent as Q, type RemoteResolver as R, type PreRmEvent as S, type PreStashEvent as T, type RefDeleteEvent as U, type RefEntry as V, type RefUpdateEvent as W, type Rejection as X, composeGitHooks as Y, isRejection as Z, type ObjectId as _, type RefStore as a, type TreeDiffEntry as a0, type Commit as a1, type ObjectType as a2, type RawObject as a3, type Ref as a4, type ConfigOverrides as b, type FileStat as c, type GitContext as d, type CommitMsgEvent as e, type GitRepo as f, type ObjectWriteEvent as g, type PostCherryPickEvent as h, type PostCleanEvent as i, type PostCloneEvent as j, type PostCommitEvent as k, type PostFetchEvent as l, type PostMergeEvent as m, type PostPullEvent as n, type PostPushEvent as o, type PostResetEvent as p, type PostRevertEvent as q, type PostRmEvent as r, type PostStashEvent as s, type PreCheckoutEvent as t, type PreCherryPickEvent as u, type PreCleanEvent as v, type PreCloneEvent as w, type PreCommitEvent as x, type PreFetchEvent as y, type PreMergeCommitEvent as z };
650
+ export { type Identity as $, type AfterCommandEvent as A, type BeforeCommandEvent as B, type CredentialProvider as C, type PrePullEvent as D, type ExecResult as E, type FileSystem as F, type GitHooks as G, type HttpAuth as H, type IdentityOverride as I, type PrePushEvent as J, type PreRebaseEvent as K, type PreResetEvent as L, type MergeMsgEvent as M, type NetworkPolicy as N, type ObjectStore as O, type PostCheckoutEvent as P, type PreRevertEvent as Q, type RemoteResolver as R, type PreRmEvent as S, type PreStashEvent as T, type RefDeleteEvent as U, type RefEntry as V, type RefUpdateEvent as W, type Rejection as X, composeGitHooks as Y, isRejection as Z, type ObjectId as _, type RefStore as a, type TreeDiffEntry as a0, type Commit as a1, type ObjectType as a2, type RawObject as a3, type PackObject as a4, type Ref as a5, type ConfigOverrides as b, type FileStat as c, type GitContext as d, type CommitMsgEvent as e, type GitRepo as f, type ObjectWriteEvent as g, type PostCherryPickEvent as h, type PostCleanEvent as i, type PostCloneEvent as j, type PostCommitEvent as k, type PostFetchEvent as l, type PostMergeEvent as m, type PostPullEvent as n, type PostPushEvent as o, type PostResetEvent as p, type PostRevertEvent as q, type PostRmEvent as r, type PostStashEvent as s, type PreCheckoutEvent as t, type PreCherryPickEvent as u, type PreCleanEvent as v, type PreCloneEvent as w, type PreCommitEvent as x, type PreFetchEvent as y, type PreMergeCommitEvent 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-4DvkF2xT.js';
2
- export { A as AfterCommandEvent, B as BeforeCommandEvent, e as CommitMsgEvent, f as GitRepo, H as HttpAuth, M as MergeMsgEvent, g as ObjectWriteEvent, P as PostCheckoutEvent, h as PostCherryPickEvent, i as PostCleanEvent, j as PostCloneEvent, k as PostCommitEvent, l as PostFetchEvent, m as PostMergeEvent, n as PostPullEvent, o as PostPushEvent, p as PostResetEvent, q as PostRevertEvent, r as PostRmEvent, s as PostStashEvent, t as PreCheckoutEvent, u as PreCherryPickEvent, v as PreCleanEvent, w as PreCloneEvent, x as PreCommitEvent, y as PreFetchEvent, z as PreMergeCommitEvent, D as PrePullEvent, J as PrePushEvent, K as PreRebaseEvent, L as PreResetEvent, Q as PreRevertEvent, S as PreRmEvent, T as PreStashEvent, U as RefDeleteEvent, V as RefEntry, W as RefUpdateEvent, X as Rejection, Y as composeGitHooks, Z as isRejection } from './hooks-4DvkF2xT.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-BtbyLyYE.js';
2
+ export { A as AfterCommandEvent, B as BeforeCommandEvent, e as CommitMsgEvent, f as GitRepo, H as HttpAuth, M as MergeMsgEvent, g as ObjectWriteEvent, P as PostCheckoutEvent, h as PostCherryPickEvent, i as PostCleanEvent, j as PostCloneEvent, k as PostCommitEvent, l as PostFetchEvent, m as PostMergeEvent, n as PostPullEvent, o as PostPushEvent, p as PostResetEvent, q as PostRevertEvent, r as PostRmEvent, s as PostStashEvent, t as PreCheckoutEvent, u as PreCherryPickEvent, v as PreCleanEvent, w as PreCloneEvent, x as PreCommitEvent, y as PreFetchEvent, z as PreMergeCommitEvent, D as PrePullEvent, J as PrePushEvent, K as PreRebaseEvent, L as PreResetEvent, Q as PreRevertEvent, S as PreRmEvent, T as PreStashEvent, U as RefDeleteEvent, V as RefEntry, W as RefUpdateEvent, X as Rejection, Y as composeGitHooks, Z as isRejection } from './hooks-BtbyLyYE.js';
3
3
 
4
4
  /** Options for subcommand execution (mirrors just-bash's CommandExecOptions). */
5
5
  interface CommandExecOptions {
@@ -23,7 +23,7 @@ interface CommandContext {
23
23
  signal?: AbortSignal;
24
24
  }
25
25
  /** Git subcommand name. Used with {@link GitOptions.disabled} to block specific commands. */
26
- type GitCommandName = "init" | "clone" | "fetch" | "pull" | "push" | "add" | "blame" | "commit" | "status" | "log" | "branch" | "tag" | "checkout" | "diff" | "reset" | "merge" | "cherry-pick" | "revert" | "rebase" | "mv" | "rm" | "remote" | "config" | "show" | "stash" | "rev-parse" | "ls-files" | "clean" | "switch" | "restore" | "reflog" | "repack" | "gc" | "bisect" | "grep";
26
+ type GitCommandName = "init" | "clone" | "fetch" | "pull" | "push" | "add" | "blame" | "commit" | "status" | "log" | "branch" | "tag" | "checkout" | "describe" | "diff" | "reset" | "merge" | "cherry-pick" | "revert" | "rebase" | "mv" | "rm" | "remote" | "config" | "show" | "stash" | "rev-parse" | "ls-files" | "clean" | "switch" | "restore" | "reflog" | "repack" | "gc" | "bisect" | "grep";
27
27
  /**
28
28
  * Configuration for a {@link Git} instance.
29
29
  *
@@ -57,17 +57,24 @@ interface GitOptions {
57
57
  */
58
58
  resolveRemote?: RemoteResolver;
59
59
  /**
60
- * Override the object store discovered by `findRepo`.
61
- * When set, all object reads/writes bypass the VFS `.git/objects/`
62
- * and go through this store instead (e.g. SQLite-backed).
60
+ * Object store to use instead of filesystem-backed `.git/objects/`.
61
+ * When both `objectStore` and `refStore` are set, `findRepo` is
62
+ * skipped entirely no `.git` directory needs to exist on the VFS.
63
63
  */
64
64
  objectStore?: ObjectStore;
65
65
  /**
66
- * Override the ref store discovered by `findRepo`.
67
- * When set, all ref reads/writes bypass the VFS `.git/refs/`
68
- * and go through this store instead (e.g. SQLite-backed).
66
+ * Ref store to use instead of filesystem-backed `.git/refs/`.
67
+ * When both `objectStore` and `refStore` are set, `findRepo` is
68
+ * skipped entirely no `.git` directory needs to exist on the VFS.
69
69
  */
70
70
  refStore?: RefStore;
71
+ /**
72
+ * Explicit `.git` directory path. When set together with
73
+ * `objectStore` and `refStore`, `findRepo` is skipped entirely —
74
+ * no `.git` directory needs to exist on the VFS. Index, config,
75
+ * reflog, and operation state files are stored under this path.
76
+ */
77
+ gitDir?: string;
71
78
  /**
72
79
  * Config overrides. `locked` values always win over `.git/config`;
73
80
  * `defaults` supply fallbacks when a key is absent from config.