Documentation
¶
Index ¶
- Constants
- Variables
- func CheckoutRepository(repo *git.Repository, ref string) error
- func CloneRepository(path, url, ref string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, ...) (*git.Repository, error)
- func ConvertSSHUrl(url string) string
- func FetchRepository(repo *git.Repository, url string, skipTLSVerify bool, ...) error
- func GetAuthMethod(url, privateKey, keyPassphrase, token string) (transport.AuthMethod, error)
- func GetLatestCommit(repo *git.Repository, ref string) (string, error)
- func GetRepoName(cloneURL string) string
- func GetShortestUniqueCommitSHA(repo *git.Repository, commitSHA string, minLength int) (string, error)
- func HasChangesInSubdir(changedFiles []ChangedFile, workingDir, subdir string) (bool, error)
- func HttpTokenAuth(token string) transport.AuthMethod
- func IsSSH(url string) bool
- func OpenRepository(path string) (*git.Repository, error)
- func ResetTrackedFiles(repo *git.Repository) error
- func SSHAuth(privateKey, keyPassphrase string) (transport.AuthMethod, error)
- func UpdateRepository(path, url, ref string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, ...) (*git.Repository, error)
- type ChangedFile
- type RefSet
Constants ¶
const ( ZeroSHA = "0000000000000000000000000000000000000000" // ZeroSHA represents a non-existent commit DefaultShortSHALength = 7 // Default length for shortened commit SHAs RemoteName = "origin" TagPrefix = "refs/tags/" BranchPrefix = "refs/heads/" MainBranch = "refs/heads/main" SwarmModeBranch = "refs/heads/swarm-mode" )
Variables ¶
var ( ErrCheckoutFailed = errors.New("failed to checkout repository") ErrFetchFailed = errors.New("failed to fetch repository") ErrPullFailed = errors.New("failed to pull repository") ErrRepositoryAlreadyExists = git.ErrRepositoryAlreadyExists ErrInvalidReference = git.ErrInvalidReference ErrSSHKeyRequired = errors.New("ssh URL requires SSH_PRIVATE_KEY to be set") ErrPossibleAuthMethodMismatch = errors.New("there might be a mismatch between the authentication method and the repository or submodule remote URL") )
Functions ¶
func CheckoutRepository ¶ added in v0.13.0
func CheckoutRepository(repo *git.Repository, ref string) error
CheckoutRepository checks out the specified reference in the repository, keeping untracked files intact.
func CloneRepository ¶
func CloneRepository(path, url, ref string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, auth transport.AuthMethod, cloneSubmodules bool) (*git.Repository, error)
CloneRepository clones a repository with HTTP or SSH auth.
func ConvertSSHUrl ¶ added in v0.65.0
ConvertSSHUrl converts SSH URLs to the ssh:// format. e.g. convert git@github.com:user/repo.git to ssh://git@github.com/user/repo.git
func FetchRepository ¶ added in v0.66.0
func FetchRepository(repo *git.Repository, url string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, auth transport.AuthMethod) error
FetchRepository fetches updates from the remote repository, including all branches and tags, and prunes deleted references.
func GetAuthMethod ¶ added in v0.65.0
func GetAuthMethod(url, privateKey, keyPassphrase, token string) (transport.AuthMethod, error)
GetAuthMethod determines the appropriate authentication method based on the URL and provided credentials.
func GetLatestCommit ¶ added in v0.22.0
func GetLatestCommit(repo *git.Repository, ref string) (string, error)
GetLatestCommit retrieves the last commit hash for a given reference in a repository.
func GetRepoName ¶ added in v0.65.0
GetRepoName returns the repository name in the form "<host>/<owner>/<repo>" from the given clone URL. Supports:
- https://github.com/owner/repo(.git)
- http://github.com/owner/repo(.git)
- ssh://github.com/owner/repo(.git)
- git@github.com:owner/repo(.git)
- token-injected https like https://oauth2:TOKEN@github.com/owner/repo(.git)
func GetShortestUniqueCommitSHA ¶ added in v0.55.0
func GetShortestUniqueCommitSHA(repo *git.Repository, commitSHA string, minLength int) (string, error)
GetShortestUniqueCommitSHA returns the shortest unique prefix of a commit SHA in the repository. Similar to the git command `git rev-parse --short=<length> <commitSHA>`.
func HasChangesInSubdir ¶ added in v0.29.0
func HasChangesInSubdir(changedFiles []ChangedFile, workingDir, subdir string) (bool, error)
HasChangesInSubdir checks if any of the changed files are in a specified subdirectory.
func HttpTokenAuth ¶ added in v0.58.0
func HttpTokenAuth(token string) transport.AuthMethod
HttpTokenAuth returns an AuthMethod for HTTP Basic Auth using a token.
func OpenRepository ¶ added in v0.64.0
func OpenRepository(path string) (*git.Repository, error)
OpenRepository opens an existing git repository at the specified path. This is a lightweight operation that doesn't fetch or update the repository.
func ResetTrackedFiles ¶ added in v0.26.1
func ResetTrackedFiles(repo *git.Repository) error
ResetTrackedFiles resets all tracked files in the worktree To their last committed state while leaving untracked files intact.
func SSHAuth ¶ added in v0.58.0
func SSHAuth(privateKey, keyPassphrase string) (transport.AuthMethod, error)
SSHAuth creates an SSH authentication method using the provided private key.
func UpdateRepository ¶ added in v0.16.0
func UpdateRepository(path, url, ref string, skipTLSVerify bool, proxyOpts transport.ProxyOptions, auth transport.AuthMethod, cloneSubmodules bool) (*git.Repository, error)
UpdateRepository fetches and checks out the requested ref.
Types ¶
type ChangedFile ¶ added in v0.29.0
type ChangedFile struct {
// From represents the file state before the change.
From diff.File
// To represents the file state after the change.
To diff.File
}
ChangedFile represents a file that has changed between two commits.
func GetChangedFilesBetweenCommits ¶ added in v0.29.0
func GetChangedFilesBetweenCommits(repo *git.Repository, commitHash1, commitHash2 plumbing.Hash) ([]ChangedFile, error)
GetChangedFilesBetweenCommits retrieves a list of changed files between two commits in a repository.
type RefSet ¶ added in v0.22.0
type RefSet struct {
LocalRef plumbing.ReferenceName
RemoteRef plumbing.ReferenceName
}
func GetReferenceSet ¶ added in v0.22.0
func GetReferenceSet(repo *git.Repository, ref string) (RefSet, error)
GetReferenceSet retrieves a RefSet of local and remote references for a given reference name.