UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

131 lines • 7.15 kB
import type { NOOPAccessor } from '../../../../accessor/base.ts'; import { PathSpec } from '../../../../types.ts'; import type { CommandFnResult, Context } from '../../../config.ts'; import { GitError } from './errors.ts'; import { type Repo } from './repo.ts'; import { Track, type HeadRef, type ReadOnlyRefusal, type RefContext, type RefField, type RefItem, type RefSortKey, type RefUpstream, type Upstream } from './types.ts'; /** * Refuse a start point two refs answer to, as git's branch creation does while * `core.warnAmbiguousRefs` is on, after warning that it is ambiguous. With no * start point git starts from the current branch by its short name, so that * name is the one checked. * * @param repo the opened repository * @param name the start point as typed, or the current branch's short name * @param warned whether reading it already put the warning on the list */ export declare function refuseAmbiguous(repo: Repo, name: string, warned: boolean): Promise<void>; /** * The one remote-tracking branch a missing branch name guesses at: * `checkout <name>` and `switch <name>` with no such branch create it from * `<remote>/<name>` when exactly one remote has one. */ export declare function remoteBranch(repo: Repo, name: string): Promise<string | null>; /** * `branch.autoSetupMerge` from the repository's config. * * The words are case-sensitive and anything else reads as a boolean, so * `never` or `Always` is a bad boolean. git reads the variable before any * command runs, so a verb that can create a branch reads it first and fails * with nothing written (pinned against git 2.50.1). */ export declare function trackMode(repo: Repo): Promise<Track>; /** * Record a new branch's upstream as `branch.autoSetupMerge` asks. * * A start point naming `<remote>/<branch>` of a configured remote writes * `branch.<new>.remote` and `.merge` unless the mode is `false`; `always` also * tracks a local branch through remote `.`, and no start point means the * branch HEAD was on. Returns the note git prints on stdout and any warning for * stderr (pinned against git 2.47.3 and 2.50.1). * * @param head HEAD before the branch was made, which a missing start point * stands for */ export declare function setUpTracking(repo: Repo, branch: string, start: string | null, mode: Track, head: HeadRef): Promise<[string, string]>; /** * The commit HEAD resolves to, null on an unborn branch. * * HEAD carries an object id only when detached; attached it names a ref, which * is unset until the first commit. */ export declare function headCommit(refs: ReadonlyMap<string, string>, head: HeadRef): string | null; /** * What `--forked` and `--delete-merged` patterns select, resolved: each * pattern, a glob or the full ref it names, and whether it is a glob. * * A pattern holding a glob character stays a glob, matched as a path (`*` * stops at a `/`) against an upstream's short name, case and `--ignore-case` * notwithstanding; any other names a branch by git's rev-parse rules, its * symbolic refs followed, so `origin` reads `refs/remotes/origin/HEAD` and * `HEAD` the current branch. Pinned against git 2.56.0. * * @throws GitError a pattern names no branch */ export declare function upstreamPatterns(table: ReadonlyMap<string, string>, known: ReadonlySet<string>, patterns: readonly string[]): [string, boolean][]; /** Whether resolved patterns select an upstream ref, given in full. */ export declare function selects(selected: readonly [string, boolean][], upstream: string): boolean; /** * Whether pushing a branch to its remote would move its upstream. * * The first of the remote's push refspecs naming the branch in full with a * destination decides where it lands, the branch's own name when the remote * has none, and nowhere when none matches; the fetch refspecs then map that to * a local ref (git 2.56.0). */ export declare function pushesUpstream(repo: Repo, branch: string, upstream: RefUpstream): Promise<boolean>; /** The order --delete-merged deletes the names in, given in turn. */ export declare function hashOrder(names: readonly string[]): string[]; /** * The fields `branch` rows read with `verbose` `-v`. * * @param verbose how many `-v` */ export declare function rowFields(verbose: number): RefField[]; /** * A branch listing as git prints it when the line gives no `--format`. * * Each row is two columns of marker, `*` for the branch HEAD is on (or a * detached HEAD) and `+` for one another worktree has out, then the name; a * symbolic ref adds ` -> ` and its target. `-v` pads every name to the widest, * by display width, and follows it with the abbreviated id, the upstream * bracket and the subject, so an empty subject leaves the id's space behind. A * remote-tracking symbolic ref keeps only its ` -> ` target there, while a * local one reads as the branch it names. `-vv` also names the upstream, and * puts `(<path>)` after the id of a branch another worktree has out. * * @param items the listed refs, in name order * @param ctx the listing's facts * @param keys the sort keys, null for `--no-sort` * @param verbose how many `-v` * @param prefix what a remote-tracking branch is labelled with, `remotes/` * unless only those are listed * @param icase `--ignore-case` */ export declare function branchRows(items: readonly RefItem[], ctx: RefContext, keys: readonly RefSortKey[] | null, verbose: number, prefix: string, icase: boolean): [string, GitError | null]; /** * List, create or delete branches. * * A name operand creates a branch, `-d` deletes one, and neither lists them with * the checked-out one marked. `-d` deletes only a branch HEAD already contains, * and `-D` deletes one regardless, which is git's own split and the reason both * are here: without `-D` there is nothing `-d` can refuse to do. `-r` lists * remote-tracking branches instead of local ones and `-a` lists both; local * names sort together and remotes follow. * * `-l` and the ref filters (`--contains`, `--merged`, `--points-at` and their * negations) make the line a listing whose operands are name patterns, so * `git branch --contains side topic` lists `topic` if it holds `side` rather * than creating anything, and a line that also deletes names two modes, which * git answers with its usage. `--forked` lists too, and `--delete-merged` is a * mode of its own whose operands narrow the branches it looks at; `--dry-run` * belongs to it alone. */ export declare function branch(_accessor: NOOPAccessor, paths: PathSpec[], texts: string[], ctx: Context): Promise<CommandFnResult>; /** A branch's upstream from `branch.<name>.remote` and `.merge`. */ export declare function upstreamOf(repo: Repo, branch: string, tip: string): Promise<Upstream | null>; /** The current branch's upstream, null when it has none or no commits. */ export declare function branchUpstream(repo: Repo, head: HeadRef, noCommits: boolean): Promise<Upstream | null>; /** branch's refusal by a read-only mount: the lock on the ref it creates or deletes. */ export declare const branchReadOnly: ReadOnlyRefusal; //# sourceMappingURL=branch.d.ts.map