git/port

Source: src/git/port.ts

The git port of a flow run: what a flow’s nodes may ask of git, and nothing more.

A flow commits, reads its tree’s diff, and gives the branches of a block a copy each whose patches come home. Each is one function below, built on the rest of this module, and the runner reaches git through this and nothing else. As in git.ts, what has no function here cannot happen: there is no push, no reset and no rebase.

gitPort

function

export function gitPort(): GitPort { /* … */ }

The {@link GitPort} of a real repository.

GitPort

type

export type GitPort = {
	/** Whether `cwd` is inside a git working tree. */
	isRepository(cwd: string): Promise<boolean>;
	/** `git diff HEAD` plus untracked files, truncated at 60 000 bytes. */
	diff(cwd: string): Promise<GitResult<string>>;
	/** The branch `HEAD` is on, `undefined` when detached. */
	currentBranch(cwd: string): Promise<string | undefined>;
	/** Whether the branch `name` exists. */
	hasBranch(cwd: string, name: string): Promise<boolean>;
	/**
	 * A branch of the run's own, `combo/<slug of request>`, suffixed `-2`, `-3`
	 * while the name is taken, created from `HEAD` and switched to.
	 */
	openBranch(cwd: string, request: string): Promise<GitResult<string>>;
	/** Stages everything and commits it: the short sha, or `undefined` on a clean tree. */
	commit(cwd: string, message: string): Promise<GitResult<string | undefined>>;
	/** A copy of the tree as it stands, uncommitted changes included, for one branch of a block. */
	copy(cwd: string, label: string): Promise<GitResult<Scratch>>;
	/** The copy a previous process made for `label` and left open, taken back when it is still there. */
	reopen(cwd: string, label: string, copy: Omit<Scratch, "release">): Promise<GitResult<Scratch>>;
	/** Applies patches one at a time onto a tree holding the run's own changes. */
	land(cwd: string, landings: readonly Landing[]): Promise<Landed>;
};

How a flow run reaches git. Injected, so the run stage and the runner never run git of their own.