gitutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gitutil provides small read-only helpers over the git CLI for repository metadata (root, current/default branch, cleanliness).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentBranch

func CurrentBranch(ctx context.Context, dir string) (string, error)

CurrentBranch returns the checked-out branch name (or "HEAD" when detached).

func DefaultBranch

func DefaultBranch(ctx context.Context, dir string) (string, error)

DefaultBranch resolves the repository's default branch, preferring origin/HEAD, then a local main/master, then the current branch.

func Exec

func Exec(ctx context.Context, dir string, args ...string) (string, error)

Exec runs an arbitrary git command in dir, returning combined output. Use for mutating operations (add/commit/push) where the caller wants the message.

func HasRemote

func HasRemote(ctx context.Context, dir, remote string) bool

HasRemote reports whether the named remote exists.

func IsClean

func IsClean(ctx context.Context, dir string) (bool, error)

IsClean reports whether the work tree at dir has no uncommitted changes.

func RemoteURL

func RemoteURL(ctx context.Context, dir, remote string) (string, error)

RemoteURL returns the URL of the named remote (e.g. "origin").

func RepoRoot

func RepoRoot(ctx context.Context, dir string) (string, error)

RepoRoot returns the absolute toplevel of the work tree containing dir (cwd if dir is ""). Returns ErrNotGitRepo when not inside a git work tree.

Types

This section is empty.

Jump to

Keyboard shortcuts

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