go-git

module
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

README

go-git

Git repository facts for Go, behind an injected runner so callers stay testable without shelling out to the real git binary.

The facts package reads the few facts tools commonly need — the current branch, the origin remote URL, and the repository owner — and offers a forward-only check (HEAD is on a branch tip, not detached). Every operation goes through a small Runner interface; ExecRunner is the real-git implementation, and tests inject a fake.

Install

go get github.com/gomatic/go-git/facts

Requires Go 1.26+.

Usage

package main

import (
	"fmt"

	"github.com/gomatic/go-git/facts"
)

func main() {
	r := facts.NewExecRunner()

	branch, err := facts.Branch(r) // ErrDetachedHead when HEAD is detached
	if err != nil {
		panic(err)
	}

	owner, err := facts.OwnerOf(r) // upstream remote, falling back to origin
	if err != nil {
		panic(err)
	}

	fmt.Printf("on %s, owned by %s\n", branch, owner)
}

Branch, Origin, OwnerOf, and EnsureForwardOnly each take a Runner, so a caller can drive them against a fake in tests:

type fakeRunner struct {
	fn func(args ...facts.Arg) (facts.CommandOutput, error)
}

func (f fakeRunner) Run(args ...facts.Arg) (facts.CommandOutput, error) { return f.fn(args...) }

Errors are gomatic/go-error sentinels (facts.ErrDetachedHead, facts.ErrNoOrigin), matchable with errors.Is.

Directories

Path Synopsis
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.
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.

Jump to

Keyboard shortcuts

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