git

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchSanitize

func BranchSanitize(branch string) string

BranchSanitize transforms a branch name into a git-safe identifier: 1. Replace '/' with '-' 2. Remove chars not in [a-zA-Z0-9_.-] 3. Collapse consecutive '-' into single '-' 4. Trim leading/trailing '-'

func CopyEnvFiles

func CopyEnvFiles(src, dst string) error

CopyEnvFiles copies .env* files from src to dst recursively. Skips .git, node_modules, and other common non-project directories.

func CurrentBranch

func CurrentBranch(r *Runner) (string, error)

CurrentBranch returns the name of the current git branch.

func GetLocalIdentity

func GetLocalIdentity(r *Runner, dir string) (name, email string, err error)

GetLocalIdentity reads user.name and user.email from the git config in dir.

func GitOnlyStatus

func GitOnlyStatus(path string) string

func IsGitRepo

func IsGitRepo(path string) bool

IsGitRepo returns true if path is inside a git repository.

func IsInsideWorktree

func IsInsideWorktree(r *Runner, path string) bool

IsInsideWorktree returns true if path is a linked worktree (not the main worktree).

func MainWorktreePath

func MainWorktreePath(r *Runner) (string, error)

MainWorktreePath returns the path of the main worktree by parsing `git worktree list --porcelain`.

func RepoName

func RepoName(r *Runner) (string, error)

RepoName returns the base name of the repository root directory.

func SetLocalIdentity

func SetLocalIdentity(r *Runner, dir, name, email string) error

SetLocalIdentity sets user.name and user.email in the local git config of dir.

func ShortStatus

func ShortStatus(path string) string

ShortStatus returns a compact status string for the given repo path.

Types

type Runner

type Runner struct {
	Dir string // working directory; empty = inherit process CWD
}

Runner executes git commands via the system git binary.

func (*Runner) Run

func (r *Runner) Run(args ...string) (string, error)

Run executes git with the given arguments in r.Dir. Returns trimmed combined stdout+stderr output.

func (*Runner) RunInDir

func (r *Runner) RunInDir(dir string, args ...string) (string, error)

RunInDir executes git with the given arguments, overriding Dir for this call only.

type Worktree

type Worktree struct {
	Path   string
	Branch string
	IsMain bool
}

Worktree represents a git worktree entry.

func ListWorktrees

func ListWorktrees(r *Runner) ([]Worktree, error)

ListWorktrees parses `git worktree list --porcelain` and returns all worktrees.

Jump to

Keyboard shortcuts

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