IF Commons GitHub

physical/worktree/mod

Written to: 5 requirements: 5 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-git-worktree FR-001, 0004-git-worktree FR-002, 0004-git-worktree FR-003, 0004-git-worktree FR-004, 0004-git-worktree FR-005

A Git working tree as a store: the files below one folder of it, held as the store in a folder holds them, with the folder of Git itself never a path of the store (it is not listed and cannot be named), links and folders never objects, and the commit an explicit operation of its own. A commit takes the paths asked for, or every changed path below the folder, and refuses to go on where something else in the repository has changed (the default), so that it never takes what a person has staged; it never runs a hook unless asked, and it is by the identity the program gives, never by the configuration of a computer.

import { gitWorktreeStore, parseIdentity } from "@intellectual-frontiers/anyfs-git";
const who = parseIdentity("collector", "collector@localhost");
// const opened = who.kind === "ok" && await gitWorktreeStore({ dir: "/srv/fleet", commit: { author: who.value } });
// opened.kind === "ok" && await opened.value.commit({ paths: [path] });

Source: commons/anyfs-git/src/physical/worktree/mod.ts

1 of 10 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Committedtypeno test imports it
type Committed = { readonly commit: string | undefined; readonly paths: readonly Path[] };

What a commit came to: the commit (none where nothing had changed) and the paths it took.

CommitRequesttypeno test imports it
type CommitRequest = {
  /** The paths to take; every changed path below the folder where none. */
  readonly paths?: readonly Path[];
  readonly dirty?: DirtyPolicy;
  /** Run the hooks of the repository (they are off unless asked). */
  readonly hooks?: boolean;
};

What a commit is asked.

DirtyPolicytypeno test imports it
type DirtyPolicy = "refuse" | "allow";

Whether a commit goes on when something it was not asked to take has changed: it is refused (the default) or the commit takes only what it was asked.

GIT_WORKTREE_CAPABILITIESconstno test imports it
const GIT_WORKTREE_CAPABILITIES: readonly ["read", "write", "list", "stat", "delete", "cas", "rename"]

The capabilities of the store of a working tree.

GitWorktreetypeno test imports it
type GitWorktree = { readonly store: GitWorktreeStore; /** The top of the working tree. */ readonly dir: string; … (431 characters)
type GitWorktree = {
  readonly store: GitWorktreeStore;
  /** The top of the working tree. */
  readonly dir: string;
  /** Every changed path of the repository: staged, not staged and not tracked. */
  status(): Promise<Result<readonly TreeChange[], WorktreeProblem>>;
  /** Commits the paths asked for, or every changed path below the folder. */
  commit(request?: CommitRequest): Promise<Result<Committed, WorktreeProblem>>;
};

A store of a working tree, with what Git adds.

GitWorktreeOptionstypeno test imports it
type GitWorktreeOptions = { /** The working tree (or any folder of it); an absolute path. */ readonly dir: string; … (496 characters)
type GitWorktreeOptions = {
  /** The working tree (or any folder of it); an absolute path. */
  readonly dir: string;
  /** The folder of the working tree the store is of (the top where none). */
  readonly prefix?: Prefix;
  /** Who a commit is by, and what it says. */
  readonly commit: CommitOptions;
  /** Refuse a path another file system could not hold (the default). */
  readonly portable?: boolean;
  /** The program that runs Git (`git` where none). */
  readonly program?: string;
};

What the store of a working tree is made with.

GitWorktreeStoretypeno test imports it
type GitWorktreeStore = Store<(typeof GIT_WORKTREE_CAPABILITIES)[number]>;

The type of the store of a working tree.

gitWorktreeStorefunction
function gitWorktreeStore(options: GitWorktreeOptions): Promise<Result<GitWorktree, string>>

The working tree as a store, or why there is none.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

TreeChangetypeno test imports it
type TreeChange = { readonly path: string; readonly status: string };

A change of the working tree: the path in the repository and what Git says of it.

WorktreeProblemtypeno test imports it
type WorktreeProblem =
  | { readonly kind: "dirty"; readonly paths: readonly string[] }
  | { readonly kind: "outside"; readonly path: string }
  | { readonly kind: "git"; readonly message: string };

Why a commit was not made: a closed union.

Titles, headings, exports, tables, columns and requirements. Esc closes.