git

package
v0.0.0-...-227e906 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git provides Git repository utilities and worktree management.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInGitRepo = fmt.Errorf("not in a git repository")

ErrNotInGitRepo is returned when a git repository cannot be found.

Functions

func AddWorktree

func AddWorktree(repoRoot, path, branch string, createBranch bool, baseBranch string) error

AddWorktree creates a new worktree. If createBranch is true, creates a new branch from baseBranch (or HEAD if baseBranch is empty). If createBranch is false, checks out the existing branch.

func BranchExists

func BranchExists(repoRoot, branchName string) (bool, error)

BranchExists checks if a branch exists locally or remotely.

func GetCurrentBranch

func GetCurrentBranch(path string) (string, error)

GetCurrentBranch returns the name of the current branch. Returns empty string if in detached HEAD state. Correctly handles worktrees by using git rev-parse --abbrev-ref HEAD.

func GetRepoName

func GetRepoName() (string, error)

GetRepoName returns the name of the current git repository.

func GetRepoRoot

func GetRepoRoot() (string, error)

GetRepoRoot returns the root directory of the current git repository. Correctly handles worktrees by finding the actual repository root instead of the worktree directory.

func GetRepoRootFromPath

func GetRepoRootFromPath(path string) (string, error)

GetRepoRootFromPath returns the root directory of the git repository containing the given path. Uses git rev-parse --show-toplevel.

func GetStatusSummary

func GetStatusSummary(repoRoot string) (string, error)

GetStatusSummary returns a brief git status summary.

func GetWorktreePath

func GetWorktreePath(repoRoot, path string) (string, error)

GetWorktreePath returns the absolute path of a worktree.

func IsWorktreeClean

func IsWorktreeClean(worktreePath string) (bool, string)

IsWorktreeClean checks if a worktree has uncommitted changes. Returns (isClean, statusMessage).

func RemoveWorktree

func RemoveWorktree(repoRoot, path string, force bool) error

RemoveWorktree removes a worktree.

func RunGit

func RunGit(repoPath string, args ...string) (string, error)

RunGit executes a git command in the specified repository path. Uses git -C flag to change directory before running the command. Returns the stdout output as a string, or an error if the command fails.

func RunGitLines

func RunGitLines(repoPath string, args ...string) ([]string, error)

RunGitLines executes a git command and returns the output as a slice of lines. Empty lines are filtered out.

Types

type Worktree

type Worktree struct {
	Path   string
	Branch string
	Commit string
}

Worktree represents a git worktree.

func ListWorktrees

func ListWorktrees(repoRoot string) ([]Worktree, error)

ListWorktrees returns all worktrees for a repository.

Jump to

Keyboard shortcuts

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