initRepository
Create a new git repository on a @catmint-fs/core layer. This is equivalent to running git init.
Import
import { initRepository } from "@catmint-fs/git";
Signature
function initRepository(
layer: Layer,
options?: InitRepositoryOptions,
): Promise<Repository>;
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
layer | Layer | Yes | A @catmint-fs/core layer to store the repository |
options | InitRepositoryOptions | No | Configuration for the new repository |
InitRepositoryOptions
| Field | Type | Default | Description |
|---|---|---|---|
defaultBranch | string | "main" | Name of the initial branch |
bare | boolean | false | Create a bare repository (no working tree) |
Return Value
Returns a Promise<Repository> — a Repository instance with the full API for git operations.
The promise resolves after the .git directory structure has been written to the layer, including HEAD, refs/, objects/, and config.
Examples
Basic Initialization
import { createMemoryLayer } from "@catmint-fs/core";
import { initRepository } from "@catmint-fs/git";
const layer = createMemoryLayer();
const repo = await initRepository(layer);
console.log(await repo.currentBranch()); // "main"
Custom Default Branch
const repo = await initRepository(layer, { defaultBranch: "trunk" });
console.log(await repo.currentBranch()); // "trunk"
Bare Repository
const repo = await initRepository(layer, { bare: true });
With a Node.js Filesystem Layer
import { createNodeLayer } from "@catmint-fs/core";
import { initRepository } from "@catmint-fs/git";
const layer = createNodeLayer("/path/to/project");
const repo = await initRepository(layer);
With a SQLite Layer
import { createSqliteLayer } from "@catmint-fs/sqlite-adapter";
import { initRepository } from "@catmint-fs/git";
const layer = createSqliteLayer("repo.db");
const repo = await initRepository(layer);
