git

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package git provides git repository operations using go-git library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

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

Repo provides git operations using go-git.

func Open

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

Open opens a git repository at the given path. Supports both regular repositories and git worktrees.

func (*Repo) Add

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

Add stages a file for commit. Path can be absolute or relative to the repository root.

func (*Repo) BranchExists

func (r *Repo) BranchExists(name string) bool

BranchExists checks if a branch with the given name exists.

func (*Repo) CheckoutBranch

func (r *Repo) CheckoutBranch(name string) error

CheckoutBranch switches to an existing branch.

func (*Repo) Commit

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

Commit creates a commit with the given message. Returns error if no changes are staged.

func (*Repo) CreateBranch

func (r *Repo) CreateBranch(name string) error

CreateBranch creates a new branch and switches to it. Returns error if branch already exists to prevent data loss.

func (*Repo) CurrentBranch

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

CurrentBranch returns the name of the current branch, or empty string for detached HEAD state.

func (*Repo) FileHasChanges added in v0.4.0

func (r *Repo) FileHasChanges(filePath string) (bool, error)

FileHasChanges returns true if the given file has uncommitted changes. this includes untracked, modified, deleted, or staged states.

func (*Repo) HasChangesOtherThan added in v0.4.0

func (r *Repo) HasChangesOtherThan(filePath string) (bool, error)

HasChangesOtherThan returns true if there are uncommitted changes to files other than the given file. this includes modified/deleted tracked files, staged changes, and untracked files.

func (*Repo) HasCommits added in v0.4.0

func (r *Repo) HasCommits() (bool, error)

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

func (*Repo) IsDirty added in v0.2.1

func (r *Repo) IsDirty() (bool, error)

IsDirty returns true if the worktree has uncommitted changes (staged or modified tracked files).

func (*Repo) IsIgnored

func (r *Repo) IsIgnored(path string) (bool, error)

IsIgnored checks if a path is ignored by gitignore rules. Returns false, nil if no .gitignore exists or cannot be read.

func (*Repo) MoveFile

func (r *Repo) MoveFile(src, dst string) error

MoveFile moves a file using git (equivalent to git mv). Paths can be absolute or relative to the repository root. The destination directory must already exist.

func (*Repo) Root

func (r *Repo) Root() string

Root returns the absolute path to the repository root.

Jump to

Keyboard shortcuts

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