cloneRepository

Clone a remote git repository into a @catmint-fs/core layer. This is equivalent to git clone.

Import

import { cloneRepository } from "@catmint-fs/git";

Signature

function cloneRepository(
  layer: Layer,
  options: CloneRepositoryOptions,
): Promise<Repository>;

Parameters

ParameterTypeRequiredDescription
layerLayerYesA @catmint-fs/core layer to store the cloned repository
optionsCloneRepositoryOptionsYesClone configuration

CloneRepositoryOptions

FieldTypeDefaultDescription
urlstringRequired. URL of the remote repository
branchstringRemote HEADBranch to check out after cloning
depthnumberundefinedLimit history depth (shallow clone)
barebooleanfalseClone as a bare repository
transportGitTransportTransport implementation for network operations

Return Value

Returns a Promise<Repository> — a Repository instance with the remote configured as origin.

Examples

Basic Clone

import { createMemoryLayer } from "@catmint-fs/core";
import { cloneRepository, httpTransport } from "@catmint-fs/git";

const layer = createMemoryLayer();
const repo = await cloneRepository(layer, {
  url: "https://github.com/user/repo.git",
  transport: httpTransport(),
});

const commits = await repo.log();
console.log(`Cloned with ${commits.length} commits`);

Clone a Specific Branch

const repo = await cloneRepository(layer, {
  url: "https://github.com/user/repo.git",
  branch: "develop",
  transport: httpTransport(),
});

console.log(await repo.currentBranch()); // "develop"

Shallow Clone

const repo = await cloneRepository(layer, {
  url: "https://github.com/user/repo.git",
  depth: 1,
  transport: httpTransport(),
});

const commits = await repo.log();
console.log(commits.length); // 1

Bare Clone

const repo = await cloneRepository(layer, {
  url: "https://github.com/user/repo.git",
  bare: true,
  transport: httpTransport(),
});

Authenticated Clone

const transport = httpTransport({
  headers: {
    Authorization: "Bearer ghp_xxxxxxxxxxxx",
  },
});

const repo = await cloneRepository(layer, {
  url: "https://github.com/user/private-repo.git",
  transport,
});

Clone to Persistent Storage

import { createSqliteLayer } from "@catmint-fs/sqlite-adapter";
import { cloneRepository, httpTransport } from "@catmint-fs/git";

const layer = createSqliteLayer("local-repo.db");
const repo = await cloneRepository(layer, {
  url: "https://github.com/user/repo.git",
  transport: httpTransport(),
});

See Also