Documentation
¶
Overview ¶
Package git provides Git repository operations and commit execution for gitcommit.
Index ¶
- Constants
- Variables
- func ExecuteCommit(gitFormattedDate, message string) error
- func GetGitDirectory() (string, error)
- func GetGitError(output []byte) string
- func GetLastCommitDate() (time.Time, error)
- func GetRepositoryRoot() (string, error)
- func HasCommits() bool
- func IsGitRepository() bool
- type Repository
Constants ¶
const (
// GitExitCodeNoCommits is the exit code returned by git log when there are no commits.
GitExitCodeNoCommits = 128
)
Variables ¶
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 ¶
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 ¶
GetGitDirectory returns the path to the .git directory.
func GetGitError ¶
GetGitError extracts a user-friendly error message from git command output.
func GetLastCommitDate ¶
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 ¶
GetRepositoryRoot returns the root path of the Git repository. Returns an error if not in a Git repository.
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.