Documentation
¶
Overview ¶
Package git provides functionality for working with Git repositories.
This package encapsulates Git operations used by the changie tool, including: - Version detection from Git tags - Checking for uncommitted changes - Managing commits and tags for changelog updates - Pushing changes to remote repositories
All functions in this package use the git command-line tool and require it to be installed and available in the PATH. Functions will return appropriate errors if Git operations fail.
Index ¶
- func CommitChangelog(file, version string) error
- func DeleteTag(tag string) error
- func GetCurrentBranch() (string, error)
- func GetRemoteURL() (string, error)
- func GetVersion() (string, error)
- func HasUncommittedChanges() (bool, error)
- func IsInstalled() bool
- func PushChanges() error
- func TagVersion(version string) error
- func UndoLastCommit() error
- type RepositoryInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitChangelog ¶
CommitChangelog commits changes to the changelog file.
This function: 1. Adds the specified changelog file to the staging area using "git add" 2. Commits the changes with a standardized message that includes the version
Parameters:
- file: Path to the changelog file to commit
- version: Version number to include in the commit message
Returns:
- error: Any error encountered during the git operations
func DeleteTag ¶ added in v1.2.0
DeleteTag deletes a local git tag. Used during rollback to undo a tag created by a failed bump.
func GetCurrentBranch ¶ added in v1.0.0
GetCurrentBranch returns the name of the current git branch.
This function uses "git rev-parse --abbrev-ref HEAD" to get the current branch name. This is a reliable way to get the branch name that works in all scenarios.
Returns:
- string: The name of the current branch
- error: Any error encountered during the git operation
func GetRemoteURL ¶ added in v1.0.0
GetRemoteURL returns the remote origin URL from git config.
This function uses "git config --get remote.origin.url" to retrieve the remote repository URL.
Returns:
- string: The remote origin URL
- error: Any error encountered during the git operation
func GetVersion ¶ added in v1.0.0
GetVersion returns the current version from git tags.
This function uses "git describe --tags --abbrev=0" to retrieve the most recent tag. If no tags exist in the repository, it returns an empty string, which the caller should interpret as version 0.0.0.
Returns:
- string: The version string (without 'v' prefix) or empty string if no tags exist
- error: Any error encountered during the git operation (except for "no tags" errors)
func HasUncommittedChanges ¶ added in v1.0.0
HasUncommittedChanges checks if there are any uncommitted changes in the repository.
This function uses "git status --porcelain" to determine if there are any staged or unstaged changes that haven't been committed. The porcelain format ensures machine-readable output that's stable across git versions.
Returns:
- bool: true if there are uncommitted changes, false otherwise
- error: Any error encountered during the git operation
func IsInstalled ¶
func IsInstalled() bool
IsInstalled checks if git is installed and available in the PATH.
This function attempts to run "git --version" and returns true only if the command executes successfully, indicating that Git is properly installed.
Returns:
- bool: true if git is installed and available, false otherwise
func PushChanges ¶ added in v0.7.0
func PushChanges() error
PushChanges pushes commits and tags to the remote repository.
This function performs two git operations: 1. "git push" to push commits to the remote repository 2. "git push --tags" to push tags to the remote repository
Returns:
- error: Any error encountered during the git operations
func TagVersion ¶
TagVersion creates a new git tag for the given version.
This function creates an annotated tag (-a) with a standardized message that includes the version number. It respects the user's configured preference for using 'v' prefix or not.
Parameters:
- version: Version number to tag (with or without "v" prefix)
Returns:
- error: Any error encountered during the git operation
func UndoLastCommit ¶ added in v1.2.0
func UndoLastCommit() error
UndoLastCommit resets the last commit, keeping changes in the working directory. Used during rollback to undo a commit created by a failed bump.
Types ¶
type RepositoryInfo ¶ added in v1.0.0
type RepositoryInfo struct {
Owner string // Repository owner/organization
Repo string // Repository name
Provider string // Provider name (github, bitbucket, gitlab, etc.)
BaseURL string // Base URL for the provider
}
RepositoryInfo holds parsed repository information
func GetRepositoryInfo ¶ added in v1.0.0
func GetRepositoryInfo() (*RepositoryInfo, error)
GetRepositoryInfo gets repository information from git remote configuration.
This is a convenience function that combines GetRemoteURL and ParseRepositoryURL.
Returns:
- *RepositoryInfo: Parsed repository information
- error: Any error encountered during the operation
func ParseRepositoryURL ¶ added in v1.0.0
func ParseRepositoryURL(remoteURL string) (*RepositoryInfo, error)
ParseRepositoryURL parses a git remote URL and extracts repository information.
This function handles both HTTPS and SSH URL formats:
- HTTPS: https://github.com/owner/repo.git
- SSH: git@github.com:owner/repo.git
Parameters:
- remoteURL: The git remote URL to parse
Returns:
- *RepositoryInfo: Parsed repository information
- error: Any error encountered during parsing