git

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git provides best-effort discovery of git metadata for a project directory. Everything here is optional: if git is not installed or the directory is not a repository, the functions return an empty Info and no error, so callers can include git metadata when available without failing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether the git executable is on PATH.

func Clone

func Clone(remote, dir, commit string) error

Clone clones remote into dir and, when commit is non-empty, checks it out. It is only ever invoked when the user explicitly opts in (e.g. --clone), so it surfaces errors rather than swallowing them like Discover does.

func IsRepo

func IsRepo(dir string) bool

IsRepo reports whether dir is inside a git working tree. It is best-effort: a missing git binary or any failure yields false.

func Push

func Push(dir string) (remote, branch string, err error)

Push pushes the current branch of the repo at dir to its remote. It is only invoked when the user explicitly opts in (--git-push), so it surfaces errors rather than swallowing them. It is deliberately conservative: it never force-pushes, never pushes tags, and never creates a remote — it runs a plain `git push <remote> <branch>`, so a diverged remote is rejected as a non-fast-forward rather than overwritten. It returns the remote name and branch that were pushed.

Types

type Info

type Info struct {
	Branch    string `json:"branch,omitempty"`
	CommitSHA string `json:"commit_sha,omitempty"`
	RemoteURL string `json:"remote_url,omitempty"`
	// Dirty reports that the working tree had uncommitted changes when the
	// bundle was exported, so HEAD does not capture the exact state.
	Dirty bool `json:"dirty,omitempty"`
	// Unpushed reports that the HEAD commit is not reachable from any
	// remote-tracking branch, so the other machine cannot fetch it yet.
	Unpushed bool `json:"unpushed,omitempty"`
}

Info holds the git facts we record in a bundle manifest.

func Discover

func Discover(dir string) Info

Discover returns best-effort git metadata for dir. It never returns an error; missing git or a non-repository simply yields an empty Info.

func (Info) Empty

func (i Info) Empty() bool

Empty reports whether no git information was discovered.

Jump to

Keyboard shortcuts

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