git

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotGitRepo      = errors.New("not a git repository")
	ErrNoCommits       = errors.New("no commits found")
	ErrEmptyRepository = errors.New("repository has no commits")
	ErrBranchExists    = errors.New("branch already exists")
	ErrNothingToCommit = errors.New("nothing to commit")
	ErrNoRemote        = errors.New("no remote configured")
	ErrTagExists       = errors.New("tag already exists")
	ErrTagNotFound     = errors.New("tag not found")
)
View Source
var (
	ErrBranchNotFound = errors.New("branch not found")
	ErrFileNotFound   = errors.New("file not found on branch")
)
View Source
var ErrMergeConflict = errors.New("merge conflict")

ErrMergeConflict is returned when a merge has conflicts

Functions

func FindGitRoot

func FindGitRoot(startPath string) (string, error)

FindGitRoot finds the root directory of the Git repository

func IsGitRepository

func IsGitRepository(path string) bool

IsGitRepository checks if the given path is inside a Git repository

func ParseAuthor

func ParseAuthor(authorStr string) *object.Signature

ParseAuthor parses an author string in the format "Name <email>" or just "email"

Types

type CommitInfo

type CommitInfo struct {
	Hash      string
	Author    string
	Email     string
	Message   string
	Timestamp time.Time
}

GetCommitHistory returns commit history for a file

type CommitLog

type CommitLog struct {
	Hash    string
	Author  string
	Email   string
	Date    time.Time
	Message string
	Files   int
}

CommitLog represents a commit entry for display

type Repository

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

Repository wraps go-git repository operations

func OpenRepository

func OpenRepository(path string) (*Repository, error)

OpenRepository opens a Git repository at the given path

func (*Repository) AbortMerge

func (r *Repository) AbortMerge() error

AbortMerge aborts the current merge operation

func (*Repository) BranchExists added in v1.0.2

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

BranchExists checks if a branch exists locally

func (*Repository) CheckoutBranch

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

CheckoutBranch switches to the specified branch. Uses native git to avoid CRLF issues with go-git on Windows.

func (*Repository) Commit

func (r *Repository) Commit(message string, author *object.Signature) (string, error)

Commit creates a new commit with the given message

func (*Repository) CreateBranch

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

CreateBranch creates a new branch from the current HEAD

func (*Repository) CreateTag

func (r *Repository) CreateTag(name, message string) error

CreateTag creates an annotated tag at the current HEAD

func (*Repository) DeleteBranch

func (r *Repository) DeleteBranch(name string) error

DeleteBranch deletes the specified branch

func (*Repository) DeleteTag

func (r *Repository) DeleteTag(name string) error

DeleteTag removes a tag from the repository

func (*Repository) DiscardChanges added in v1.4.1

func (r *Repository) DiscardChanges(filePath string) error

DiscardChanges discards uncommitted changes to a specific file. Uses git checkout -- <file> to restore the file to its last committed state.

func (*Repository) GetAuthorsForFile

func (r *Repository) GetAuthorsForFile(filepath string) ([]string, error)

GetAuthorsForFile returns all unique authors who modified a file

func (*Repository) GetChangedFiles

func (r *Repository) GetChangedFiles() ([]string, error)

GetChangedFiles returns files that have been modified (uncommitted changes). Uses native git to properly handle core.autocrlf and other settings that go-git doesn't fully support, especially on Windows.

func (*Repository) GetCommitHistory

func (r *Repository) GetCommitHistory(filepath string, limit int) ([]CommitInfo, error)

func (*Repository) GetCurrentBranch

func (r *Repository) GetCurrentBranch() (string, error)

GetCurrentBranch returns the name of the current branch

func (*Repository) GetLog

func (r *Repository) GetLog(path string, author string, since *time.Time, limit int) ([]CommitLog, error)

GetLog returns filtered commit log path: optional file path to filter commits (relative to repo root, e.g., ".fogit/features/auth.yml") author: optional author name/email to filter since: optional start date to filter limit: maximum number of commits (0 = no limit)

func (*Repository) GetRemotes

func (r *Repository) GetRemotes() ([]string, error)

GetRemotes returns the list of configured remotes

func (*Repository) GetRepositoryName

func (r *Repository) GetRepositoryName() string

GetRepositoryName returns the repository name from the remote URL

func (*Repository) GetStatus

func (r *Repository) GetStatus() (map[string]git.StatusCode, error)

GetStatus returns the status of the working tree. NOTE: This uses go-git's Status() which has known issues with core.autocrlf on Windows. For checking if there are uncommitted changes, use GetChangedFiles() instead which uses native git.

func (*Repository) GetTag

func (r *Repository) GetTag(name string) (*TagInfo, error)

GetTag returns information about a specific tag

func (*Repository) GetTrunkBranch added in v1.0.2

func (r *Repository) GetTrunkBranch() (string, error)

GetTrunkBranch returns the main/master branch name. Uses Git's native methods via common.DetectTrunkBranch for consistent detection.

func (*Repository) GetUserConfig

func (r *Repository) GetUserConfig() (name, email string, err error)

GetUserConfig returns the Git user name and email from config

func (*Repository) HasConflicts

func (r *Repository) HasConflicts() (bool, error)

HasConflicts checks if the working tree has unresolved merge conflicts

func (*Repository) IsMerging

func (r *Repository) IsMerging() bool

IsMerging checks if Git is currently in a merge state

func (*Repository) ListBranches added in v1.0.2

func (r *Repository) ListBranches() ([]string, error)

ListBranches returns all local branch names

func (*Repository) ListFilesOnBranch added in v1.0.2

func (r *Repository) ListFilesOnBranch(branch, path string) ([]string, error)

ListFilesOnBranch lists files in a path on a specific branch without checkout. Uses: git ls-tree -r --name-only <branch> -- <path> Returns relative paths of files found under the given path.

func (*Repository) ListRemoteBranches added in v1.0.2

func (r *Repository) ListRemoteBranches() ([]string, error)

ListRemoteBranches returns all remote tracking branch names Returns branch names in format "origin/branch-name"

func (*Repository) ListTags

func (r *Repository) ListTags() ([]TagInfo, error)

ListTags returns all tags in the repository

func (*Repository) MergeBranch

func (r *Repository) MergeBranch(branchName string) error

MergeBranch merges the specified branch into the current branch using native git. This uses the git CLI because go-git doesn't have robust merge support. Returns ErrMergeConflict if there are conflicts, nil on success.

func (*Repository) MergeBranchSquash

func (r *Repository) MergeBranchSquash(branchName string) error

MergeBranchSquash merges the specified branch with squash into the current branch. Returns ErrMergeConflict if there are conflicts, nil on success.

func (*Repository) Path added in v1.4.1

func (r *Repository) Path() string

Path returns the filesystem path to the repository

func (*Repository) Push

func (r *Repository) Push(remoteName string) error

Push pushes the current branch to the remote

func (*Repository) ReadFileOnBranch added in v1.0.2

func (r *Repository) ReadFileOnBranch(branch, path string) ([]byte, error)

ReadFileOnBranch reads a file from a specific branch without checkout. Uses: git show <branch>:<path>

func (*Repository) RemoteBranchExists added in v1.0.2

func (r *Repository) RemoteBranchExists(remoteBranch string) bool

RemoteBranchExists checks if a remote branch exists

func (*Repository) UpdateFileOnBranch added in v1.0.7

func (r *Repository) UpdateFileOnBranch(targetBranch, filePath string, content []byte, commitMsg string) error

UpdateFileOnBranch updates a file on a specific branch without checking out. This is used for cross-branch operations like creating inverse relationships. It temporarily checks out the branch, updates the file, commits, and returns to original branch.

type TagInfo

type TagInfo struct {
	Name    string
	Hash    string
	Message string
	Tagger  string
	Date    time.Time
	IsLight bool // true if lightweight tag (no message/tagger)
}

TagInfo represents a Git tag

Jump to

Keyboard shortcuts

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