git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package git provides Git repository operations and commit execution for gitcommit.

Index

Constants

View Source
const (
	// GitExitCodeNoCommits is the exit code returned by git log when there are no commits.
	GitExitCodeNoCommits = 128
)

Variables

View Source
var (
	// ErrNoCommits is returned when the repository has no commits.
	ErrNoCommits = errors.New("no commits in repository")
	// ErrNotGitRepository is returned when the directory is not a Git repository.
	ErrNotGitRepository = errors.New("not a git repository")
	// ErrGitDirNotFound is returned when the .git directory cannot be found.
	ErrGitDirNotFound = errors.New(".git directory not found")
)

Functions

func ExecuteCommit

func ExecuteCommit(gitFormattedDate, message string) error

ExecuteCommit executes a git commit with the provided date and message. It sets the GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables to the provided gitFormattedDate before executing the commit.

Parameters:

  • gitFormattedDate: Date in Git format (e.g., "Wed 5 Feb 2025 20:19:19 CEST")
  • message: The commit message

Returns an error if the git commit command fails.

func GetGitDirectory

func GetGitDirectory() (string, error)

GetGitDirectory returns the path to the .git directory.

func GetGitError

func GetGitError(output []byte) string

GetGitError extracts a user-friendly error message from git command output.

func GetLastCommitDate

func GetLastCommitDate() (time.Time, error)

GetLastCommitDate retrieves the date of the last commit in the repository. Returns an error if there are no commits or if not in a Git repository.

func GetRepositoryRoot

func GetRepositoryRoot() (string, error)

GetRepositoryRoot returns the root path of the Git repository. Returns an error if not in a Git repository.

func HasCommits

func HasCommits() bool

HasCommits checks if the repository has any commits.

func IsGitRepository

func IsGitRepository() bool

IsGitRepository checks if the current directory is inside a Git repository. It searches up the directory tree for a .git directory.

Types

type Repository

type Repository struct {
	// Path is the root path of the Git repository.
	Path string

	// IsValid indicates whether this is a valid Git repository.
	IsValid bool
}

Repository represents a Git repository and its properties.

func NewRepository

func NewRepository() *Repository

NewRepository creates a Repository instance for the current directory.

func ValidateRepository

func ValidateRepository() (*Repository, error)

ValidateRepository checks if the current directory is a valid Git repository. Returns a Repository instance and an error if validation fails.

Jump to

Keyboard shortcuts

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