infrastructure

package
v4.2.11 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 19 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultGitTag               = "0.1.0"
	MaxAcceptableInitialCommits = 5
)

Variables

View Source
var (
	ErrNoAuthMethodFound  = errors.New("no authentication method found")
	ErrAuthNotImplemented = errors.New("authentication method not implemented")
	ErrNoRemoteURL        = errors.New("no remote URL found for repository")
	ErrNoTagsFound        = errors.New("no tags found in Git history")
)

Functions

func CheckBranchExists

func CheckBranchExists(repo *git.Repository, branchName string) (bool, error)

CheckBranchExists checks if a given Git branch exists (local or remote). Exported for use by autobump (github.com/rios0rios0/autobump).

func CheckoutBranch

func CheckoutBranch(w *git.Worktree, branchName string) error

CheckoutBranch switches to the given branch. Exported for use by autobump (github.com/rios0rios0/autobump).

func CommitChanges

func CommitChanges(
	repo *git.Repository,
	workTree *git.Worktree,
	commitMessage string,
	signer globalEntities.CommitSigner,
	name string,
	email string,
) (plumbing.Hash, error)

CommitChanges commits the changes in the given worktree with optional signing. The repo parameter is required when using a CommitSigner that produces post-commit signatures (e.g. SSH). Exported for use by autobump (github.com/rios0rios0/autobump).

func CreateAndSwitchBranch

func CreateAndSwitchBranch(
	repo *git.Repository,
	workTree *git.Worktree,
	branchName string,
	hash plumbing.Hash,
) error

CreateAndSwitchBranch creates a new branch and switches to it. Exported for use by autobump (github.com/rios0rios0/autobump).

func DeleteLocalBranch

func DeleteLocalBranch(repo *git.Repository, branchName string) error

DeleteLocalBranch removes the local refs/heads/<branchName> reference when it exists.

This is the necessary companion to DeleteRemoteBranch: deleting a branch on the remote leaves the local branch untouched, and CheckBranchExists reports a branch as existing when it finds either one. A caller that deletes a branch remotely and then asks whether it exists would still be told "yes", and so would never recreate it.

A branch that is absent is not an error. The currently checked-out branch is never removed, because dropping HEAD's reference leaves the repository unusable.

Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

func DeleteRemoteBranch

func DeleteRemoteBranch(
	repo *git.Repository,
	branchName string,
	authMethods []transport.AuthMethod,
) error

DeleteRemoteBranch deletes the given branch on the origin remote by pushing an empty source to its ref. go-git drops the matching remote-tracking reference as part of that push, so only the remote side is handled here; a local branch of the same name survives and must be removed with DeleteLocalBranch.

Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

func GetAmountCommits

func GetAmountCommits(repo *git.Repository) (int, error)

GetAmountCommits returns the number of commits in the repository.

func GetLatestTag

func GetLatestTag(repo *git.Repository) (*globalEntities.LatestTag, error)

GetLatestTag finds the latest tag in the Git history. Exported for use by autobump (github.com/rios0rios0/autobump).

func GetRemoteRepoURL

func GetRemoteRepoURL(repo *git.Repository) (string, error)

GetRemoteRepoURL returns the URL of the remote repository. Exported for use by autobump (github.com/rios0rios0/autobump).

func ListRemoteBranches

func ListRemoteBranches(repo *git.Repository, authMethods []transport.AuthMethod) ([]string, error)

ListRemoteBranches returns the short names of every branch present on the origin remote. It queries the remote directly rather than reading remote-tracking references, so the result reflects the current server state even when the local clone is stale.

Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

func OpenRepo

func OpenRepo(projectPath string) (*git.Repository, error)

OpenRepo opens a git repository at the given path. Exported for use by autobump (github.com/rios0rios0/autobump).

func PushChangesSSH

func PushChangesSSH(repo *git.Repository, refSpec config.RefSpec, authMethods []transport.AuthMethod) error

PushChangesSSH pushes the changes to the remote repository over SSH. If authMethods is non-empty, each method is tried in order until one succeeds. If all explicit methods fail or authMethods is empty, it falls back to go-git's default SSH agent behaviour (SSH_AUTH_SOCK).

func PushWithTransportDetection

func PushWithTransportDetection(
	repo *git.Repository,
	refSpec config.RefSpec,
	authMethods []transport.AuthMethod,
) error

PushWithTransportDetection pushes the given refSpec to the origin remote, auto-detecting the transport (SSH or HTTPS) from the remote URL.

For SSH remotes (git@ or ssh://), authMethods are tried in order; if all fail or none are provided, it falls back to go-git's default SSH agent.

For HTTPS/HTTP remotes, authMethods are tried in order until one succeeds. An empty authMethods slice returns an error for HTTPS remotes.

Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

func StageAll

func StageAll(workTree *git.Worktree) error

StageAll adds all changes in the working tree to the index, equivalent to `git add -A`. It stages new, modified, and deleted files. Exported for use by autoupdate (github.com/rios0rios0/autoupdate).

func WorktreeIsClean

func WorktreeIsClean(workTree *git.Worktree) (bool, error)

WorktreeIsClean returns true when the working tree has no uncommitted changes (staged or unstaged). This is the go-git equivalent of `git status --porcelain` returning empty output. Exported for use by autoupdate (github.com/rios0rios0/autoupdate).

Types

type GitOperations

type GitOperations struct {
	// contains filtered or unexported fields
}

GitOperations encapsulates git operations with an adapter finder for service type resolution.

func NewGitOperations

func NewGitOperations(finder gitEntities.AdapterFinder) *GitOperations

NewGitOperations creates a new GitOperations with the given adapter finder.

func (*GitOperations) CloneRepo

func (o *GitOperations) CloneRepo(
	url, dir string,
	authMethods []transport.AuthMethod,
) (*git.Repository, error)

CloneRepo clones a remote repository into the given directory. It prepares the clone URL via the adapter finder (if one matches the URL) and tries each provided authentication method until one succeeds.

func (*GitOperations) GetAuthMethods

func (o *GitOperations) GetAuthMethods(
	service globalEntities.ServiceType,
	username string,
) ([]transport.AuthMethod, error)

GetAuthMethods returns the authentication methods for the given service type. It delegates to the appropriate adapter based on the service type. Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) GetRemoteServiceType

func (o *GitOperations) GetRemoteServiceType(repo *git.Repository) (globalEntities.ServiceType, error)

GetRemoteServiceType returns the type of the remote service (e.g. GitHub, GitLab). Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) GetServiceTypeByURL

func (o *GitOperations) GetServiceTypeByURL(remoteURL string) globalEntities.ServiceType

GetServiceTypeByURL returns the type of the remote service by URL. Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) PushChangesHTTPS

func (o *GitOperations) PushChangesHTTPS(
	repo *git.Repository,
	username string,
	refSpec config.RefSpec,
) error

PushChangesHTTPS pushes the changes to the remote repository over HTTPS. It tries each authentication method returned by the adapter until one succeeds.

type PullRequestURLInfo

type PullRequestURLInfo struct {
	ServiceType  globalEntities.ServiceType
	Organization string
	Project      string // Azure DevOps only; empty for GitHub/GitLab
	RepoName     string
	PRID         int
}

PullRequestURLInfo holds the parsed components of a pull request URL.

func ParsePullRequestURL

func ParsePullRequestURL(rawURL string) (*PullRequestURLInfo, error)

ParsePullRequestURL extracts provider, organization, project, repository, and PR ID from a PR URL. Supported formats:

type RemoteURLInfo

type RemoteURLInfo struct {
	ServiceType  globalEntities.ServiceType
	Organization string
	Project      string // Azure DevOps only; empty for GitHub/GitLab
	RepoName     string
}

RemoteURLInfo holds the parsed components of a Git remote URL.

func ParseRemoteURL

func ParseRemoteURL(rawURL string) (*RemoteURLInfo, error)

ParseRemoteURL extracts provider, organization, project, and repository name from a Git remote URL. Supported formats:

type UserConfig

type UserConfig struct {
	Name          string
	Email         string
	SigningKey    string
	SigningFormat string
	SSHProgram    string // gpg.ssh.program — custom signing binary (e.g. op-ssh-sign-wsl)
}

UserConfig holds user-specific git configuration values read from local and global git config. Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate) as the canonical way to read user identity and signing settings before committing.

func ReadUserConfig

func ReadUserConfig(repo *git.Repository) (*UserConfig, error)

ReadUserConfig reads user name, email, signing key, and signing format from the repository's local config, falling back to the global ~/.gitconfig. Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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