git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Hash    string
	Short   string
	Author  string
	Date    string
	Subject string
}

Commit represents a git commit entry.

type FileChange

type FileChange struct {
	Path    string
	OldPath string // non-empty for renames
	Status  FileStatus
	Staged  bool
}

FileChange represents a changed file in the working tree or index.

type FileStatus

type FileStatus rune

FileStatus represents the type of change for a file.

const (
	StatusModified  FileStatus = 'M'
	StatusAdded     FileStatus = 'A'
	StatusDeleted   FileStatus = 'D'
	StatusRenamed   FileStatus = 'R'
	StatusCopied    FileStatus = 'C'
	StatusUntracked FileStatus = '?'
)

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo wraps git operations for a repository.

func NewRepo

func NewRepo(path string) (*Repo, error)

NewRepo validates the path is inside a git repo and returns a Repo.

func (*Repo) BranchName

func (r *Repo) BranchName() string

BranchName returns the current branch name, or short hash if detached.

func (*Repo) ChangedFiles

func (r *Repo) ChangedFiles(staged bool, ref string) ([]FileChange, error)

ChangedFiles returns files changed in the working tree or index. If staged is true, only returns staged changes. If ref is non-empty, compares against that ref.

func (*Repo) Commit

func (r *Repo) Commit(msg string) error

Commit creates a commit with the given message.

func (*Repo) CommitDiff

func (r *Repo) CommitDiff(hash string) (string, error)

CommitDiff returns the full diff for a commit. For the root commit (no parent), uses diff-tree against empty tree.

func (*Repo) CommitDiffFiles

func (r *Repo) CommitDiffFiles(hash string) ([]FileChange, error)

CommitDiffFiles returns files changed in a commit.

func (*Repo) DiffFile

func (r *Repo) DiffFile(path string, staged bool, ref string) (string, error)

DiffFile returns the raw diff for a single file.

func (*Repo) Dir

func (r *Repo) Dir() string

Dir returns the repository root directory.

func (*Repo) HasCommits

func (r *Repo) HasCommits() bool

HasCommits returns true if the repo has at least one commit.

func (*Repo) Log

func (r *Repo) Log(n int) ([]Commit, error)

Log returns the n most recent commits.

func (*Repo) ReadFileContent

func (r *Repo) ReadFileContent(path string) (string, error)

ReadFileContent reads a file from the working tree.

func (*Repo) StageAll

func (r *Repo) StageAll() error

StageAll stages all changes.

func (*Repo) StageFile

func (r *Repo) StageFile(path string) error

StageFile stages a file.

func (*Repo) StagedDiff

func (r *Repo) StagedDiff() (string, error)

StagedDiff returns the full diff of staged changes.

func (*Repo) UnstageFile

func (r *Repo) UnstageFile(path string) error

UnstageFile unstages a file.

func (*Repo) UntrackedFiles

func (r *Repo) UntrackedFiles() ([]string, error)

UntrackedFiles returns paths of untracked files.

Jump to

Keyboard shortcuts

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