facts

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package facts exposes git repository facts (current branch, origin remote, owner) and a forward-only check, all through an injected Runner so the logic is testable without invoking the real git binary.

Index

Constants

View Source
const (
	// ErrDetachedHead is returned when HEAD is not on a branch (a branch tip is required).
	ErrDetachedHead errs.Const = "git: HEAD is detached; not on a branch tip"
	// ErrNoOrigin is returned when remote.origin.url is not configured.
	ErrNoOrigin errs.Const = "git: no origin remote configured"
)

Variables

This section is empty.

Functions

func EnsureForwardOnly

func EnsureForwardOnly(r Runner) error

EnsureForwardOnly verifies the working tree satisfies the forward-only invariant: HEAD is on a branch tip rather than a detached commit.

Types

type Arg

type Arg string

Arg is a single git command-line argument.

type BranchName

type BranchName string

BranchName is a git branch name.

func Branch

func Branch(r Runner) (BranchName, error)

Branch returns the current branch name, or ErrDetachedHead when HEAD is detached.

type CommandOutput

type CommandOutput string

CommandOutput is the raw stdout of a git invocation.

type ExecRunner

type ExecRunner struct{}

ExecRunner is a Runner backed by the real git binary.

func NewExecRunner

func NewExecRunner() ExecRunner

NewExecRunner returns a Runner that invokes git.

func (ExecRunner) Run

func (ExecRunner) Run(args ...Arg) (CommandOutput, error)

Run invokes git with the given arguments and returns its standard output.

type OriginURL

type OriginURL string

OriginURL is the URL of the origin remote.

func Origin

func Origin(r Runner) (OriginURL, error)

Origin returns the origin remote URL, or ErrNoOrigin when it is not configured.

type Owner

type Owner string

Owner is the account/org that owns a repository (e.g. "nicerobot").

func OwnerOf

func OwnerOf(r Runner) (Owner, error)

OwnerOf returns the owner parsed from the upstream remote, falling back to origin. ErrNoOrigin is returned when neither remote is configured.

type Runner

type Runner interface {
	Run(args ...Arg) (CommandOutput, error)
}

Runner runs a git subcommand and returns its standard output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL