openLegitFs
The main function to create and configure a LegitFs instance.
Signature
function openLegitFs({
storageFs,
gitRoot,
anonymousBranch,
showKeepFiles,
initialAuthor,
serverUrl,
publicKey,
}: {
storageFs: typeof nodeFs;
gitRoot: string;
anonymousBranch?: string;
showKeepFiles?: boolean;
initialAuthor?: LegitUser;
serverUrl?: string;
publicKey?: string;
}): Promise<LegitFs>;Parameters
- storageFs (required): The underlying filesystem (
typeof nodeFs) to use for storage - gitRoot (required): The root path of the Git repository
- anonymousBranch (optional, default:
'anonymous'): The name of the anonymous branch to use - showKeepFiles (optional, default:
false): Whether to show.keepfiles in the filesystem - initialAuthor (optional): Initial author information for Git commits
{ type: string; id: string; name: string; email: string; } - serverUrl (optional, default:
'https://hub.legitcontrol.com'): URL of the sync server - publicKey (optional): Public key for authentication
Returns
A Promise<LegitFs> that resolves to a LegitFs instance. The instance is a CompositeFs extended with:
auth: Authentication APIsync: Synchronization servicepush: Push branches to remoteshareCurrentBranch: Share the current branchsetCurrentBranch: Set the current branchgetCurrentBranch: Get the current branchpromises: File system operations API
Example
import * as nodeFs from 'node:fs';
import { openLegitFs } from '@legit-sdk/core';
const legitFs = await openLegitFs({
storageFs: nodeFs,
gitRoot: '/path/to/repo',
anonymousBranch: 'main',
showKeepFiles: false,
initialAuthor: {
type: 'local',
id: 'local',
name: 'Local User',
email: 'local@legitcontrol.com',
},
serverUrl: 'https://hub.legitcontrol.com',
});Last updated on