Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package git reads and drives the checkout holding a project, and its origin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	SHA, Parent                 string
	AuthorEmail, CommitterEmail string
	Trailers                    map[string]string
}

Commit describes one commit.

type Credentials

type Credentials func(ctx context.Context) (username, password string, err error)

Credentials supply the username and password presented to an HTTP origin.

type Identity

type Identity struct {
	Name, Email string
}

Identity is the author and committer of every commit made here.

type Repository

type Repository struct {
	// Dir is the top-level directory of the checkout.
	Dir string
	// Remote is the origin URL as the checkout configures it, or "" without one.
	Remote string
	// Shallow reports a checkout cloned without its whole history.
	Shallow bool
	// Credentials authenticate fetches and pushes to an HTTP origin. An SSH
	// origin uses the SSH agent instead.
	Credentials Credentials
	// Identity signs the commits made in worktrees.
	Identity Identity
	// contains filtered or unexported fields
}

Repository is the checkout holding a project.

func Open

func Open(dir string) (*Repository, error)

Open locates the checkout containing dir.

func (*Repository) Branches

func (r *Repository) Branches(prefix string) ([]string, error)

Branches lists origin's branches under a prefix.

func (*Repository) ChangedPaths

func (r *Repository) ChangedPaths(ctx context.Context, commit string) ([]string, error)

ChangedPaths returns paths changed since commit, including working-tree edits.

func (*Repository) Commit

func (r *Repository) Commit(ref string) (Commit, error)

Commit describes the commit a SHA or ref points at.

func (*Repository) Count

func (r *Repository) Count(base, tip string) (int, error)

Count reports how many commits tip has beyond base: zero, one, or two for any larger number, which is all ownership needs to tell apart.

func (*Repository) DefaultBranch

func (r *Repository) DefaultBranch(ctx context.Context) (string, error)

DefaultBranch returns the branch origin's HEAD points at: the checkout's record of it, or the remote's answer when the checkout never recorded one.

func (*Repository) DeleteBranch

func (r *Repository) DeleteBranch(ctx context.Context, branch, expected string) error

DeleteBranch removes an origin branch while it still has the expected tip.

func (*Repository) Fetch

func (r *Repository) Fetch(ctx context.Context, refspecs ...string) error

Fetch updates origin's remote-tracking refs for the given refspecs and prunes the ones they no longer match.

func (*Repository) Files added in v0.11.0

func (r *Repository) Files(commit, dir string) (map[string][]byte, error)

Files returns the files below dir at a commit, keyed by their repository path. A commit without the directory has none.

func (*Repository) MergeBase

func (r *Repository) MergeBase(rev string) (_ string, err error)

MergeBase returns the commit where the histories of rev and HEAD meet, as git merge-base finds it.

func (*Repository) Show

func (r *Repository) Show(commit, path string) ([]byte, error)

Show reads a path from a commit; a missing path returns nil.

func (*Repository) Tip

func (r *Repository) Tip(ref string) (string, error)

Tip returns the commit a fully qualified ref points at, or "" when the ref does not exist.

func (*Repository) Worktree

func (r *Repository) Worktree(commit string) (*Worktree, error)

Worktree checks a commit out into a new temporary directory.

type Worktree

type Worktree struct {
	Dir string
	// contains filtered or unexported fields
}

Worktree is a detached checkout of one commit in a temporary directory. The commits it makes reach the checkout only through origin, on the next fetch. Callers remove it.

func (*Worktree) Commit

func (w *Worktree) Commit(message string, paths ...string) (string, error)

Commit records the given paths on top of the worktree's commit and returns the new commit, which the worktree then has checked out.

func (*Worktree) Push

func (w *Worktree) Push(ctx context.Context, branch, expected string) error

Push publishes the worktree's commit to an origin branch only while the branch still has the tip the caller observed; "" expects the branch to be absent.

func (*Worktree) Remove

func (w *Worktree) Remove() error

Remove deletes the worktree.

Jump to

Keyboard shortcuts

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