Documentation
¶
Overview ¶
Package git provides Git command execution utilities.
Index ¶
- Variables
- func Author() (name, email string)
- func CheckLuckyCommit() error
- func Commit(msg CommitMessage) error
- func CreateBranch(name string) (string, error)
- func CreateSOB() string
- func CreateTypedBranch(commitType, name string) (string, error)
- func CurrentBranch() (string, error)
- func GetHeadHash() (string, error)
- func GetLuckyPrefix() string
- func GetPreviousCommits(n int) ([]string, error)
- func GetStagedDiff(context int) (string, error)
- func HasStagedFiles() error
- func LuckyCommitCmd(prefix string) *exec.Cmd
- func ParseBranchType(branch string) string
- func Push() (string, error)
- func RepoCheck() error
- func Run(args ...string) (string, error)
- func ValidateLuckyPrefix(prefix string) (string, error)
- type CommitMessage
- type FileDiff
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoStagedFiles is returned when there are no staged files. ErrNoStagedFiles = errors.New("there is no file to commit, please execute the `git add` command to add the commit file") // ErrNotGitRepo is returned when the current directory is not a git repository. ErrNotGitRepo = errors.New("not a git repository") )
Common errors.
var ( ErrLuckyPrefixEmpty = errors.New("invalid lucky commit prefix: cannot be empty") ErrLuckyPrefixTooLong = fmt.Errorf("invalid lucky commit prefix: maximum length is %d characters", consts.LuckyCommitMaxLen) ErrLuckyPrefixInvalid = errors.New("invalid lucky commit prefix: must contain only hex characters [0-9a-f]") ErrLuckyCommitNotFound = fmt.Errorf("%s not found in PATH, install it from: %s", consts.LuckyCommitBinary, consts.LuckyCommitURL) )
Lucky commit errors.
Functions ¶
func Author ¶
func Author() (name, email string)
Author returns the git user name and email. Returns empty strings if not configured.
func CheckLuckyCommit ¶
func CheckLuckyCommit() error
CheckLuckyCommit checks if lucky_commit executable exists in PATH. Returns nil if found, error with download instructions if not.
func Commit ¶
func Commit(msg CommitMessage) error
Commit creates a new commit with the given message.
func CreateBranch ¶
CreateBranch creates a new branch with the given name.
func CreateTypedBranch ¶
CreateTypedBranch creates a new branch with type prefix (e.g., feat/name).
func CurrentBranch ¶
CurrentBranch returns the current branch name.
func GetHeadHash ¶
GetHeadHash returns the current HEAD commit hash.
func GetLuckyPrefix ¶
func GetLuckyPrefix() string
GetLuckyPrefix returns the lucky commit prefix from gitconfig. Returns empty string if not set.
func GetPreviousCommits ¶
GetPreviousCommits returns the last n commit messages. If on a feature branch, returns commits since diverging from main.
func GetStagedDiff ¶
GetStagedDiff returns the staged diff with specified context lines.
func HasStagedFiles ¶
func HasStagedFiles() error
HasStagedFiles checks if there are any staged files.
func LuckyCommitCmd ¶
LuckyCommitCmd creates an exec.Cmd for running lucky_commit with the given prefix.
func ParseBranchType ¶ added in v3.0.2
ParseBranchType extracts the commit type from a branch name. Supports formats: type/name, type-name, type_name Returns empty string if no match found.
func RepoCheck ¶
func RepoCheck() error
RepoCheck checks if the current directory is a git repository.
func ValidateLuckyPrefix ¶
ValidateLuckyPrefix validates and normalizes the prefix. Returns lowercase prefix or error if invalid.