Documentation
¶
Overview ¶
Package git provides git repository operations using go-git. It handles reading staged changes and generating diffs using go-git, while commit creation uses the git CLI to support commit signing (GPG/SSH).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoStagedChanges is returned when attempting to get a diff but no files are staged. ErrNoStagedChanges = errors.New("no staged changes found") // ErrNotAGitRepo is returned when the path is not a valid git repository. ErrNotAGitRepo = errors.New("not a git repository") )
Sentinel errors for common git operations.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository wraps a go-git repository and provides high-level operations for reading staged changes and creating commits.
func Open ¶
func Open(path string) (*Repository, error)
Open opens the git repository at the given path. Returns ErrNotAGitRepo if the path is not a valid git repository.
func OpenCurrent ¶
func OpenCurrent() (*Repository, error)
OpenCurrent opens the git repository in the current working directory. This is a convenience wrapper around Open(".").
func (*Repository) Commit ¶
func (r *Repository) Commit(message string) (string, error)
Commit creates a new commit with the given message from staged changes. Returns the commit hash as a hex string on success. Uses the git command-line tool to support commit signing (GPG/SSH) based on user's git config.
func (*Repository) GetStagedDiff ¶
func (r *Repository) GetStagedDiff() (string, error)
GetStagedDiff returns a unified diff of all staged changes. Returns ErrNoStagedChanges if no files are staged. For new repositories without commits, returns the content of staged files as additions.
func (*Repository) GetStagedFiles ¶
func (r *Repository) GetStagedFiles() ([]string, error)
GetStagedFiles returns a list of file paths that have staged changes. The list includes added, modified, and deleted files.
func (*Repository) HasStagedChanges ¶
func (r *Repository) HasStagedChanges() (bool, error)
HasStagedChanges returns true if there are any staged changes in the repository. This is useful for validating before attempting to create a commit.
func (*Repository) Root ¶
func (r *Repository) Root() (string, error)
Root returns the absolute path to the repository root directory. This is the top-level directory containing the .git folder, which serves as the base for resolving relative file paths within the repository.