git

package
v1.47.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package git implements helpers for interacting with git

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHeadBranch is returned when a repository's HEAD (aka default) branch cannot
	// be determine.
	ErrNoHeadBranch = errors.New("failed to find a head branch, does one exist?")

	// ErrNoRemoteHeadBranch is returned when a repository's remote  default/HEAD branch
	// cannot be determined.
	ErrNoRemoteHeadBranch = errors.New("failed to get head branch from remote origin")

	// ErrNoOriginRemote is returned when a repository has no "origin" remote and its
	// default branch cannot be inferred from its local branches.
	ErrNoOriginRemote = errors.New(`the repository has no "origin" remote to determine the default branch from`)
)

This block contains errors and regexes.

Functions

func GetDefaultBranch

func GetDefaultBranch(ctx context.Context, path string) (string, error)

GetDefaultBranch determines the default/HEAD branch for a given git repository. It asks the "origin" remote. A repository without an "origin" remote, such as one that was just created, has no remote to ask, so its default branch is inferred from its local branches instead, see inferLocalDefaultBranch.

func GetDefaultBranchWithRetry

func GetDefaultBranchWithRetry(ctx context.Context, path string, opts ...retry.Option) (string, error)

GetDefaultBranchWithRetry is GetDefaultBranch, retried with backoff (3 attempts by default) because it asks the remote, which can fail transiently. It does not retry when asking again won't change the answer: there is no "origin" remote and the branch can't be inferred, or git ran fine but did not report a branch. opts are applied after the defaults.

Types

This section is empty.

Jump to

Keyboard shortcuts

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