gitnamespacenamespace gitA Git repository read by running git (commons 0007-grc FR-021): the commit at HEAD, whether the working tree is clean, the paths changed between two revisions, and a file's bytes as it is at a revision. Each runs git -C REPO ... by its argument vector, never through a shell, with no pager, no terminal prompt, no optional locks and messages in English; paths are read NUL-separated (-z), so spaces, quotes and non-ASCII names come back as they are. Every failure is an Err naming what went wrong, a repository that is not there and a git that is not installed included; nothing here throws.
import { changedPaths, head } from "./git.ts";
const h = await head(".");
if (h.kind === "ok") console.log(h.value);
const changed = await changedPaths(".", "HEAD~1", "HEAD"); // { kind: "ok", value: ["src/a.ts", ...] }gitnamespacenamespace gitgit.CommitIdtypeno test imports ittype CommitId = Brand<string, "CommitId">;A commit's object id: 40 (SHA-1) or 64 (SHA-256) lower-case hexadecimal digits, made only by commitIdOf.
git.commitIdOffunctionno test imports itfunction commitIdOf(text: string): CommitId | undefinedText as a commit id, or undefined where it is not 40 or 64 lower-case hexadecimal digits.
git.GitErrortypeno test imports ittype GitError =
| { readonly kind: "git-missing"; readonly program: string }
| { readonly kind: "not-a-repository"; … (480 characters)type GitError =
| { readonly kind: "git-missing"; readonly program: string }
| { readonly kind: "not-a-repository"; readonly repo: string; readonly message: string }
| { readonly kind: "bad-revision"; readonly rev: string; readonly message: string }
| { readonly kind: "no-such-path"; readonly rev: string; readonly path: string; readonly message: string }
| { readonly kind: "failed"; readonly args: readonly string[]; readonly code: number; readonly message: string };Why a repository could not be read.
git.formatGitErrorfunctionno test imports itfunction formatGitError(e: GitError): stringA Git error as one sentence.
git.GitOptionstypeno test imports ittype GitOptions = { readonly program?: string };How git is run: the program (git on PATH by default).
git.headfunctionno test imports itfunction head(repo: string, options?: GitOptions): Promise<Result<CommitId, GitError>>The commit HEAD points to; bad-revision in a repository with no commit yet.
git.isCleanfunctionno test imports itfunction isClean(repo: string, options?: GitOptions): Promise<Result<boolean, GitError>>Whether the working tree and the index match HEAD, with no untracked file that is not ignored.
git.changedPathsfunctionno test imports itfunction changedPaths(repo: string, from: string, to: string, options?: GitOptions): Promise<Result<readonly string[], GitError>>The paths (relative to the repository's top, /-separated) whose content differs between two revisions, in Git's order, each once; a rename gives both its old and its new path.
git.fileAtfunctionno test imports itfunction fileAt(repo: string, rev: string, path: string, options?: GitOptions): Promise<Result<Uint8Array<ArrayBufferLike>, GitError>>A file's bytes as it is at a revision, its path relative to the repository's top (/-separated); no-such-path where it is not there.
CommitIdtypeno test imports ittype CommitId = Brand<string, "CommitId">;A commit's object id: 40 (SHA-1) or 64 (SHA-256) lower-case hexadecimal digits, made only by commitIdOf.
commitIdOffunctionfunction commitIdOf(text: string): CommitId | undefinedText as a commit id, or undefined where it is not 40 or 64 lower-case hexadecimal digits.
GitErrortypeno test imports ittype GitError =
| { readonly kind: "git-missing"; readonly program: string }
| { readonly kind: "not-a-repository"; … (480 characters)type GitError =
| { readonly kind: "git-missing"; readonly program: string }
| { readonly kind: "not-a-repository"; readonly repo: string; readonly message: string }
| { readonly kind: "bad-revision"; readonly rev: string; readonly message: string }
| { readonly kind: "no-such-path"; readonly rev: string; readonly path: string; readonly message: string }
| { readonly kind: "failed"; readonly args: readonly string[]; readonly code: number; readonly message: string };Why a repository could not be read.
formatGitErrorfunctionfunction formatGitError(e: GitError): stringA Git error as one sentence.
GitOptionstypeno test imports ittype GitOptions = { readonly program?: string };How git is run: the program (git on PATH by default).
headfunctionfunction head(repo: string, options?: GitOptions): Promise<Result<CommitId, GitError>>The commit HEAD points to; bad-revision in a repository with no commit yet.
isCleanfunctionfunction isClean(repo: string, options?: GitOptions): Promise<Result<boolean, GitError>>Whether the working tree and the index match HEAD, with no untracked file that is not ignored.
changedPathsfunctionfunction changedPaths(repo: string, from: string, to: string, options?: GitOptions): Promise<Result<readonly string[], GitError>>The paths (relative to the repository's top, /-separated) whose content differs between two revisions, in Git's order, each once; a rename gives both its old and its new path.
fileAtfunctionfunction fileAt(repo: string, rev: string, path: string, options?: GitOptions): Promise<Result<Uint8Array<ArrayBufferLike>, GitError>>A file's bytes as it is at a revision, its path relative to the repository's top (/-separated); no-such-path where it is not there.