Documentation
¶
Overview ¶
Package git exposes the few git operations archdoc needs, behind an interface so that callers can be tested without a repository.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotARepository = errors.New("not inside a git repository")
ErrNotARepository reports that a directory is not inside a git repository. L11 skips itself rather than failing when it sees this.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository interface {
// FilesAt returns the contents of many paths as committed on branch, in one
// operation. A path absent from the branch is absent from the result rather
// than an error. Reading a document at a time cost a subprocess per
// document, which was the whole of lint's running time on a repository of
// any size.
FilesAt(branch string, paths []string) (map[string][]byte, error)
// Changed names which of paths differ between branch and the working tree,
// as git itself judges it.
//
// git is asked rather than the bytes compared, because git applies checkout
// filters between the blob it stores and the file it writes to disk. Under
// end-of-line normalisation, which is the default on Windows, every frozen
// document differed byte for byte while git reported the tree clean, so the
// rule this tool exists to enforce failed on every document there.
Changed(branch string, paths []string) (map[string]bool, error)
// HasCommits reports whether the repository holds any commit at all. A
// freshly initialised one holds none, so no document can be frozen yet and
// the configured branch being absent is expected rather than a fault.
HasCommits() (bool, error)
// BranchExists reports whether branch resolves to a commit. L11 needs this
// to tell a repository with no such branch from one where every document is
// new, which would otherwise pass silently.
BranchExists(branch string) (bool, error)
// ListFiles names every path committed on branch, sorted. L11 needs it to
// notice a frozen document deleted from the working tree, which discovery
// cannot see.
ListFiles(branch string) ([]string, error)
// CurrentBranch is the checked-out branch.
CurrentBranch() (string, error)
// RepoRoot is the absolute path of the repository's top level.
RepoRoot() (string, error)
// Prefix is the path from the repository root down to the directory this
// Repository was opened in, slash-separated, empty when they are the same.
//
// Asked of git rather than computed with filepath.Rel, because that
// compares two paths obtained by different means: git reports a name as it
// is written on disk and os.Getwd reports what the caller typed. On a
// case-insensitive filesystem the two spellings of one directory diverge,
// and Rel then walks out of the repository and back in. That produced a
// generated workflow naming a path no checkout could contain, so the job
// failed before archdoc ran.
Prefix() (string, error)
}
Repository is every git operation archdoc performs, and nothing else until something needs more.
func Open ¶
func Open(dir string) (Repository, error)
Open returns a Repository rooted at dir. It returns ErrNotARepository only when git itself reports that the directory is outside a repository. Any other failure, git missing from PATH above all, is returned as it is: a caller that treated those alike would skip every frozen-document check and still succeed.