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

git

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 18, 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(dir, branch string) bool

BranchExists checks if a branch exists locally or as a remote tracking branch.

func CommitsSince

func CommitsSince(dir, ref string) (int, error)

CommitsSince returns the number of commits since a given ref.

func CurrentBranch

func CurrentBranch(dir string) (string, error)

CurrentBranch returns the current branch name.

func DefaultBranch

func DefaultBranch(dir string) (string, error)

DefaultBranch returns the default branch name (main, master, etc.).

func DeleteBranch

func DeleteBranch(repoDir, branch string) error

DeleteBranch deletes a local branch.

func Diff

func Diff(dir, spec string) (string, error)

Diff returns the diff between two refs (e.g., "main...feature/auth").

func DiffStat

func DiffStat(dir, spec string) (string, error)

DiffStat returns a stat summary of the diff between two refs.

func DirDiskUsage

func DirDiskUsage(path string) int64

DirDiskUsage returns the total disk usage of a directory in bytes. Returns 0 if the directory does not exist or cannot be measured.

func Fetch

func Fetch(dir string) error

Fetch fetches from origin.

func FetchWithRetry

func FetchWithRetry(dir string, maxAttempts int, onRetry func(attempt, max int, err error)) error

FetchWithRetry fetches from origin with retries on transient network errors. Calls onRetry before each retry attempt (can be nil).

func FormatBytes

func FormatBytes(b int64) string

FormatBytes formats a byte count as a human-readable string (KB, MB, GB).

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError returns true if the error looks like a transient network/SSH issue.

func IsRepo

func IsRepo(dir string) bool

IsRepo checks if the directory is inside a git repository.

func ParseGitHubRemote

func ParseGitHubRemote(url string) (owner, repo string)

ParseGitHubRemote extracts owner/repo from a GitHub remote URL. Handles HTTPS (https://github.com/owner/repo.git) and SSH (git@github.com:owner/repo.git).

func RemoteURL

func RemoteURL(dir string) string

RemoteURL returns the origin remote URL, or empty string if none.

func RepoName

func RepoName(dir string) (string, error)

RepoName returns the basename of the git repo root.

func TopLevel

func TopLevel(dir string) (string, error)

TopLevel returns the root of the git repository.

func WorktreeAdd

func WorktreeAdd(repoDir, worktreePath, branch string, startPoint ...string) error

WorktreeAdd creates a new git worktree at the given path on a new branch. If startPoint is non-empty, the branch is created from that ref instead of HEAD.

func WorktreeAddExisting

func WorktreeAddExisting(repoDir, worktreePath, branch string) error

WorktreeAddExisting creates a new git worktree at the given path from an existing branch. Unlike WorktreeAdd, this does not create a new branch (-b).

func WorktreePrune

func WorktreePrune(repoDir string) error

WorktreePrune runs git worktree prune to clean up stale bookkeeping entries.

func WorktreeRemove

func WorktreeRemove(repoDir, worktreePath string) error

WorktreeRemove removes a git worktree.

func WorktreeRemoveByBranch

func WorktreeRemoveByBranch(repoDir, branch string) error

WorktreeRemoveByBranch finds and removes any worktree that has the given branch checked out.

Types

type BranchInfo

type BranchInfo struct {
	Name      string
	IsRemote  bool
	IsCurrent bool
}

BranchInfo represents a git branch.

func Branches

func Branches(dir string) ([]BranchInfo, error)

Branches returns all branches (local and remote).

type LogEntry

type LogEntry struct {
	Hash    string
	Subject string
	Author  string
	Date    time.Time
}

LogEntry represents a single git log entry.

func Log

func Log(dir string, n int) ([]LogEntry, error)

Log returns the most recent n log entries.

func LogGrep

func LogGrep(dir string, pattern string) ([]LogEntry, error)

LogGrep returns recent log entries whose subject matches a pattern (e.g., "#42"). Searches the last 200 commits to keep it bounded.

func LogSince

func LogSince(dir string, since time.Time) ([]LogEntry, error)

LogSince returns log entries since the given time.

type WorktreeEntry

type WorktreeEntry struct {
	Path   string
	Branch string
	IsMain bool
}

WorktreeEntry represents a git worktree.

func Worktrees

func Worktrees(dir string) ([]WorktreeEntry, error)

Worktrees returns all git worktrees for the repo.

Jump to

Keyboard shortcuts

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