This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
git-essentials is a TypeScript library providing essential Git commands for both Node.js and browser environments with zero native dependencies. It works by directly modifying .git directory contents, aiming for 100% interoperability with canonical git. Based on isomorphic-git.
npm run check # TypeScript type checking (tsc --noEmit)
npm run build # Compile TypeScript to ESM (outputs to dist/)
npm test # Run Jest tests with coverage
npm run test:browser # Run Karma browser tests (dev mode, needs browsers)
npm run test:browsers # Run Karma headless (Chrome, Firefox, WebKit)Run a single test file:
npx jest tests/clone.test.tsRun a specific test by name:
npx jest -t "test name pattern"The codebase follows a strict layered architecture:
-
API layer (
src/api/) — Public functions. Each validates parameters viaassertParameter, wrapsFsClientin aFileSystemabstraction, delegates to the command layer, and tags errors witherr.caller. -
Command layer (
src/commands/) — Internal implementations prefixed with underscore (e.g.,_clone). Contains the actual git logic. -
Manager layer (
src/managers/) — Stateful git resource management: config, index, refs, remotes, ignores, shallow commits. -
Model layer (
src/models/) — Data structures:GitCommit,GitTree,GitIndex,GitPackIndex,GitObject, walker types. Re-exported fromsrc/index.ts. -
Storage layer (
src/storage/) — Git object database: reading/writing loose and packed objects. -
Wire layer (
src/wire/) — Git smart HTTP protocol: parsing and writing upload-pack/receive-pack messages.
The library uses an adapter pattern for environment portability:
- Filesystem clients (
src/clients/fs/):InMemoryFsClient,IndexedDbFsClient,FileSystemAccessApiFsClient. All implement theFsClientinterface. - HTTP clients (
src/clients/http/):NodeHttpClient,WebHttpClient. Both implementHttpClient. - Consumers pass
fsandhttpimplementations into every API call — the library never imports environment-specific code directly.
Custom error hierarchy in src/errors/ with 30+ specific types extending BaseError. All API functions catch errors and attach a caller property (e.g., git.clone).
Tests use Jest with ts-jest and run against in-memory fixtures (no real filesystem or network):
makeFsFixture()— creates anInMemoryFsClientwith optional pre-populated directory tree from JSON fixture datamakeHttpFixture()— creates a mockHttpClientthat matches requests against fixture data (JSON files with base64-encoded request/response pairs)- Fixture data is generated by scripts in
scripts/(gen-fs-fixture.js,gen-http-fixture.js)
Module aliases in tests: git-essentials maps to src/, and src/* paths are supported via Jest's moduleNameMapper.
The package is ESM-only ("type": "module") with tree-shakeable sub-path exports:
git-essentials— all API functions + modelsgit-essentials/api/*— individual API functionsgit-essentials/errors— error typesgit-essentials/models/*— data modelsgit-essentials/clients/*— fs/http client implementations