Documentation
¶
Overview ¶
Package git provides a set of utilities for working with Git repositories.
Index ¶
- func GetGitDiff() (string, error)
- func GetGitStats() (string, error)
- func GitAddAll() error
- func GitCommit(message string) error
- func GitFetchTags() error
- func GitGetLatestTags(count int) ([]string, error)
- func GitPush() error
- func GitPushTags() error
- func GitTag(tag string) error
- func HasStagedChanges() bool
- func IsCurrentDirectoryGitRepo() bool
- func IsDirty() bool
- func RunCommand(cmd *exec.Cmd) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGitDiff ¶
GetGitDiff retrieves the staged differences. This function runs 'git diff --staged --unified=0' to show zero lines of context around differences in the output. The diff is returned as a string.
func GetGitStats ¶
GetGitStats provides statistics of staged changes. It uses the command 'git diff --cached --stat' to show file statistics (insertions, deletions) for staged changes.
func GitAddAll ¶
func GitAddAll() error
GitAddAll stages all changes (including new, modified, and deleted files). It runs the command 'git add .' which adds all files in the current directory.
func GitCommit ¶
GitCommit commits staged changes with a provided commit message. Uses 'git commit -m <message>' to perform a commit.
func GitFetchTags ¶ added in v0.0.10
func GitFetchTags() error
GitFetchTags fetches tags from the remote repository. Runs 'git fetch --tags' to ensure local tags are up to date with remote.
func GitGetLatestTags ¶ added in v0.0.10
GitGetLatestTags retrieves the latest tags sorted by version (descending). Uses 'git tag --sort=-version:refname' and returns up to `count` tags.
func GitPush ¶
func GitPush() error
GitPush pushes commits to the remote repository. Runs 'git push' to push changes to the default push target.
func GitPushTags ¶
func GitPushTags() error
GitPushTags pushes tags to the remote repository. Executes 'git push --tags' to push all tags to the remote.
func GitTag ¶
GitTag creates a new tag on the latest commit with the specified tag name. Uses 'git tag <tag>' to attach a tag to the current commit.
func HasStagedChanges ¶
func HasStagedChanges() bool
HasStagedChanges checks if there are any staged but not yet committed changes. Uses 'git diff --staged --quiet', which returns error if there are changes.
func IsCurrentDirectoryGitRepo ¶
func IsCurrentDirectoryGitRepo() bool
IsCurrentDirectoryGitRepo determines if the current directory is a Git repository. It does this by attempting to run 'git rev-parse --is-inside-work-tree' which returns true if the directory is part of a Git repository work tree.
func IsDirty ¶
func IsDirty() bool
IsDirty checks if there are any uncommitted changes in the working directory. 'git diff --quiet' will return a non-zero exit code if there are changes, so this function returns true in that case.
func RunCommand ¶
RunCommand executes a given command and outputs its standard error content to os.Stderr if the command fails. This is a helper function to reduce repetition of error handling logic.
Types ¶
This section is empty.