git

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(branch string) bool

func CheckInRepo

func CheckInRepo() error

func CheckedOutBranches added in v0.10.0

func CheckedOutBranches() (map[string]bool, error)

func GetBranchTrackingRemote

func GetBranchTrackingRemote(branch string) (string, error)

func GetBranchUpstream

func GetBranchUpstream(branch string) (string, string, error)

func GetCommitHash

func GetCommitHash(ref string) (string, error)

func GetCurrentBranch

func GetCurrentBranch() (string, error)

func GetCurrentBranchUpstream

func GetCurrentBranchUpstream() (string, error)

func GetLocalBranches

func GetLocalBranches() ([]string, error)

func GetRemoteBranches

func GetRemoteBranches(remote string) ([]string, error)

func GetRemotes

func GetRemotes() ([]string, error)

func IsBranchAheadOfRemote

func IsBranchAheadOfRemote(local, remote string) (bool, error)

func IsDirty

func IsDirty() (bool, error)

func RemoteBranchExists

func RemoteBranchExists(remote, branch string) (bool, error)

Types

type FileStatus

type FileStatus int

FileStatus represents the status of a file in git.

const (
	FileUntracked FileStatus = iota
	FileModified
	FileStaged
	FileDeleted
	FileUnknown
)

func GetFileStatus

func GetFileStatus(file string) (FileStatus, error)

type Repo

type Repo struct {
	Dir string
}

Repo is a git repository identified by an absolute path. The zero value addresses the current working directory, matching the CLI's natural binding. Tests should construct Repo{Dir: tmpdir} and use the methods so they can run in parallel without sharing process cwd.

func CWD

func CWD() Repo

CWD returns a Repo bound to the process's current working directory.

func (Repo) BranchExists

func (r Repo) BranchExists(branch string) bool

BranchExists checks if a local branch exists.

func (Repo) CheckInRepo

func (r Repo) CheckInRepo() error

CheckInRepo verifies we're inside a git repository.

func (Repo) CheckedOutBranches added in v0.10.0

func (r Repo) CheckedOutBranches() (map[string]bool, error)

CheckedOutBranches returns the set of branch names currently checked out in any worktree (including the main worktree). Callers use the map for O(1) lookups rather than running a separate subprocess per branch.

func (Repo) GetBranchTrackingRemote

func (r Repo) GetBranchTrackingRemote(branch string) (string, error)

GetBranchTrackingRemote returns the remote that a local branch tracks, or "" if none.

func (Repo) GetBranchUpstream

func (r Repo) GetBranchUpstream(branch string) (remote string, remoteBranch string, err error)

GetBranchUpstream returns the remote and branch name of the upstream for a local branch. Returns ("", "", nil) if the branch has no upstream configured.

func (Repo) GetCommitHash

func (r Repo) GetCommitHash(ref string) (string, error)

GetCommitHash returns the commit hash for a ref.

func (Repo) GetCurrentBranch

func (r Repo) GetCurrentBranch() (string, error)

GetCurrentBranch returns the name of the current branch.

func (Repo) GetCurrentBranchUpstream

func (r Repo) GetCurrentBranchUpstream() (string, error)

GetCurrentBranchUpstream returns the upstream tracking branch for the current branch. Returns ("", nil) if the current branch has no upstream configured.

func (Repo) GetFileStatus

func (r Repo) GetFileStatus(file string) (FileStatus, error)

GetFileStatus returns the status of a file in git.

func (Repo) GetLocalBranches

func (r Repo) GetLocalBranches() ([]string, error)

GetLocalBranches returns a list of local git branches.

func (Repo) GetRemoteBranches

func (r Repo) GetRemoteBranches(remote string) ([]string, error)

GetRemoteBranches returns branches for a specific remote.

func (Repo) GetRemotes

func (r Repo) GetRemotes() ([]string, error)

GetRemotes returns a list of git remotes.

func (Repo) IsBranchAheadOfRemote

func (r Repo) IsBranchAheadOfRemote(localBranch, remoteBranch string) (bool, error)

IsBranchAheadOfRemote reports whether localBranch has commits not in remoteBranch.

func (Repo) IsDirty

func (r Repo) IsDirty() (bool, error)

IsDirty reports whether the repo has tracked changes (ignoring untracked files).

func (Repo) RemoteBranchExists

func (r Repo) RemoteBranchExists(remote, branch string) (bool, error)

RemoteBranchExists checks if a branch exists on a remote.

Jump to

Keyboard shortcuts

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