Documentation
¶
Index ¶
- Constants
- Variables
- func IsMergeConflict(err error) bool
- func IsNonFastForward(err error) bool
- func IsRebaseUnsafe(err error) bool
- type AddWorkTreeOptions
- type BareCloneOptions
- type BareRepo
- type ClientOptions
- type CloneOptions
- type CommitMetadata
- type CommitOptions
- type CommitSignatureInfo
- type FetchOptions
- type IntegrationOptions
- type ListCommitsOptions
- type LoadBareRepoOptions
- type LoadRepoOptions
- type LoadWorkTreeOptions
- type MockRepo
- func (m *MockRepo) AddAll() error
- func (m *MockRepo) AddAllAndCommit(message string, commitOpts *CommitOptions) error
- func (m *MockRepo) Checkout(branch string) error
- func (m *MockRepo) Clean() error
- func (m *MockRepo) Clear() error
- func (m *MockRepo) Close() error
- func (m *MockRepo) Commit(message string, opts *CommitOptions) error
- func (m *MockRepo) CommitMessage(id string) (string, error)
- func (m *MockRepo) CreateChildBranch(branch string) error
- func (m *MockRepo) CreateOrphanedBranch(branch string) error
- func (m *MockRepo) CreateTag(tag, msg string) error
- func (m *MockRepo) CurrentBranch() (string, error)
- func (m *MockRepo) DeleteBranch(branch string) error
- func (m *MockRepo) Dir() string
- func (m *MockRepo) Fetch(opts *FetchOptions) error
- func (m *MockRepo) GetCommitSignatureInfo(commitID string) (*CommitSignatureInfo, error)
- func (m *MockRepo) GetDiffPathsForCommitID(commitID string) ([]string, error)
- func (m *MockRepo) HasDiffs() (bool, error)
- func (m *MockRepo) HomeDir() string
- func (m *MockRepo) IntegrateRemoteChanges(opts *IntegrationOptions) error
- func (m *MockRepo) IsAncestor(parent string, child string) (bool, error)
- func (m *MockRepo) IsRebasing() (bool, error)
- func (m *MockRepo) LastCommitID() (string, error)
- func (m *MockRepo) ListCommits(opts *ListCommitsOptions) ([]CommitMetadata, error)
- func (m *MockRepo) ListTags() ([]TagMetadata, error)
- func (m *MockRepo) Pull(opts *PullOptions) error
- func (m *MockRepo) Push(opts *PushOptions) error
- func (m *MockRepo) RefsHaveDiffs(commit1 string, commit2 string) (bool, error)
- func (m *MockRepo) RemoteBranchExists(branch string) (bool, error)
- func (m *MockRepo) ResetHard() error
- func (m *MockRepo) URL() string
- func (m *MockRepo) UpdateSubmodules() error
- type PullOptions
- type PushIntegrationPolicy
- type PushOptions
- type Repo
- type RepoCredentials
- type SigningKeyType
- type TagMetadata
- type User
- type WorkTree
Constants ¶
const FilterBlobless = "blob:none"
FilterBlobless is a filter that excludes blobs from the clone. When using this filter, the initial Git clone will download all reachable commits and trees, and only download the blobs for commits when you do a Git checkout (including the first checkout during the clone).
When using a blobless clone, you can still explore the commits of the repository without downloading additional data. This means that you can perform commands like `git log`, or even `git log -- <path>` with the same performance as a full clone.
Commands like `git diff` or `git blame <path>` require the contents of the paths to compute diffs, so these will trigger blob downloads the first time they are run.
Variables ¶
var ErrMergeConflict = errors.New("merge conflict")
ErrMergeConflict is returned when a merge conflict occurs.
var ErrNonFastForward = errors.New("non-fast-forward")
ErrNonFastForward is returned when a push is rejected because it is not a fast-forward or needs to be fetched first.
var ErrRebaseUnsafe = errors.New(
"rebase is unsafe and policy prohibits merge fallback",
)
ErrRebaseUnsafe is returned when the PushIntegrationPolicyRebaseOrFail policy is in effect and the signature-trust decision matrix determines that rebasing is not safe.
Functions ¶
func IsMergeConflict ¶
IsMergeConflict returns true if the error is a merge conflict or wraps one and false otherwise.
func IsNonFastForward ¶
IsNonFastForward returns true if the error is a non-fast-forward or wraps one and false otherwise.
func IsRebaseUnsafe ¶
IsRebaseUnsafe returns true if the error is a rebase-unsafe error or wraps one and false otherwise.
Types ¶
type AddWorkTreeOptions ¶
type AddWorkTreeOptions struct {
// Orphan specifies whether the working tree should be created from a new,
// orphaned branch. If true, the Ref field will be ignored.
Orphan bool
// Ref specifies the branch or commit to check out in the working tree. Will
// be ignored if Orphan is true.
Ref string
// Sparse specifies directory patterns for sparse checkout using cone mode.
// When specified, only the listed directories (and their contents) will be
// checked out. Patterns should be directory paths relative to the repository
// root (e.g., "src/app", "configs/prod").
Sparse []string
}
AddWorkTreeOptions represents options for adding a working tree to a bare repository.
type BareCloneOptions ¶
type BareCloneOptions struct {
// BaseDir is an existing directory within which all other directories created
// and managed by the BareRepo implementation will be created. If not
// specified, the operating system's temporary directory will be used.
// Overriding that default is useful under certain circumstances.
BaseDir string
// InsecureSkipTLSVerify specifies whether certificate verification errors
// should be ignored when cloning the repository. The setting will be
// remembered for subsequent interactions with the remote repository.
InsecureSkipTLSVerify bool
// Filter specifies a partial clone filter (e.g., "blob:none"). When combined
// with sparse checkout, this avoids downloading blobs for directories that
// won't be checked out, significantly reducing clone time and disk usage for
// large repositories.
Filter string
}
BareCloneOptions represents options for cloning a Git repository without a working tree.
type BareRepo ¶
type BareRepo interface {
// AddWorkTree adds a working tree to the repository.
AddWorkTree(path string, opts *AddWorkTreeOptions) (WorkTree, error)
// Close cleans up file system resources used by this repository. This should
// always be called before a repository goes out of scope.
Close() error
// Dir returns an absolute path to the repository.
Dir() string
// HomeDir returns an absolute path to the home directory of the system user
// who has cloned this repo.
HomeDir() string
// RemoteBranchExists returns a bool indicating if the specified branch exists
// in the remote repository.
RemoteBranchExists(branch string) (bool, error)
// RemoveWorkTree removes a working tree from the repository. The working tree
// will be removed from the file system.
RemoveWorkTree(path string) error
// URL returns the remote URL of the repository.
URL() string
// WorkTrees returns a list of working trees associated with the repository.
WorkTrees() ([]WorkTree, error)
}
BareRepo is an interface for interacting with a bare Git repository.
func CloneBare ¶
func CloneBare( repoURL string, clientOpts *ClientOptions, cloneOpts *BareCloneOptions, ) (BareRepo, error)
CloneBare produces a local, bare clone of the remote Git repository at the specified URL and returns an implementation of the BareRepo interface that is stateful and NOT suitable for use across multiple goroutines. This function will also perform any setup that is required for successfully authenticating to the remote repository.
func LoadBareRepo ¶
func LoadBareRepo(path string, opts *LoadBareRepoOptions) (BareRepo, error)
type ClientOptions ¶
type ClientOptions struct {
// User represents the actor that performs operations against the git
// repository. This has no effect on authentication, see Credentials for
// specifying authentication configuration.
User *User
// Credentials represents the authentication information.
Credentials *RepoCredentials
// InsecureSkipTLSVerify indicates whether to ignore certificate verification
// errors when interacting with the remote repository.
InsecureSkipTLSVerify bool
}
ClientOptions represents options for a repository-specific Git client.
type CloneOptions ¶
type CloneOptions struct {
// BaseDir is an existing directory within which all other directories created
// and managed by the Repo implementation will be created. If not specified,
// the operating system's temporary directory will be used. Overriding that
// default is useful under certain circumstances.
BaseDir string
// Branch is the name of the branch to clone. If not specified, the default
// branch will be cloned. This option is ignored if Bare is true.
Branch string
// Depth is the number of commits to fetch from the remote repository. If
// zero, all commits will be fetched. This option is ignored if Bare is true.
Depth uint
// Filter allows for partially cloning the repository by specifying a
// filter. When a filter is specified, the server will only send a
// subset of reachable objects according to a given object filter.
//
// For more information, see:
// - https://git-scm.com/docs/git-clone#Documentation/git-clone.txt-code--filtercodeemltfilter-specgtem
// - https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---filterltfilter-specgt
// - https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/
// - https://docs.gitlab.com/ee/topics/git/partial_clone.html
Filter string
// SingleBranch indicates whether the clone should be a single-branch clone.
// This option is ignored if Bare is true.
SingleBranch bool
}
CloneOptions represents options for cloning a Git repository with a single working tree.
type CommitMetadata ¶
type CommitMetadata struct {
// CommitID is the ID (sha) of the commit.
ID string
// CommitDate is the date of the commit.
CommitDate time.Time
// Author is the author of the commit, in the format "Name <email>".
Author string
// Committer is the person who committed the commit, in the format
// "Name <email>".
Committer string
// Subject is the subject (first line) of the commit message.
Subject string
}
type CommitOptions ¶
type CommitOptions struct {
// AllowEmpty indicates whether an empty commit should be allowed.
AllowEmpty bool
// Author is the author of the commit. If nil, the default author already
// configured in the git repository will be used.
Author *User
}
CommitOptions represents options for committing changes to a git repository.
type CommitSignatureInfo ¶
type CommitSignatureInfo struct {
// Trusted indicates whether the commit is signed by a key with
// ultimate trust.
Trusted bool
// SignerName is the name from the signing key's UID. Empty if the
// commit is unsigned.
SignerName string
// SignerEmail is the email from the signing key's UID. Empty if the
// commit is unsigned.
SignerEmail string
}
CommitSignatureInfo holds signature details for a single commit.
type FetchOptions ¶
type FetchOptions struct {
// Branch optionally specifies a single branch to fetch. If empty, all
// branches are fetched.
Branch string
// Depth optionally limits fetching to the specified number of commits. A
// value of 0 (the default) indicates no depth limit.
Depth uint
}
FetchOptions represents options for fetching from a remote git repository.
type IntegrationOptions ¶
type IntegrationOptions struct {
// TargetBranch is the remote branch to integrate changes from. If empty, the
// current branch is used.
TargetBranch string
// IntegrationPolicy controls how remote changes are integrated. If empty or
// set to PushIntegrationPolicyNone, no integration is performed.
IntegrationPolicy PushIntegrationPolicy
}
IntegrationOptions represents options for integrating remote changes into the local branch before pushing.
type ListCommitsOptions ¶
type ListCommitsOptions struct {
// Limit is the maximum number of commits to return. 0 means no limit.
Limit uint
// Skip is the number of commits to skip before returning results.
Skip uint
// Since limits commits to those at or after this time.
Since *time.Time
}
ListCommitsOptions contains options for listing commits.
type LoadBareRepoOptions ¶
type LoadBareRepoOptions struct {
Credentials *RepoCredentials
}
type LoadRepoOptions ¶
type LoadRepoOptions struct {
Credentials *RepoCredentials
}
type LoadWorkTreeOptions ¶
type LoadWorkTreeOptions struct {
Credentials *RepoCredentials
}
type MockRepo ¶
type MockRepo struct {
AddAllFn func() error
AddAllAndCommitFn func(
message string,
commitOpts *CommitOptions,
) error
CleanFn func() error
ClearFn func() error
CloseFn func() error
CheckoutFn func(branch string) error
CommitFn func(message string, opts *CommitOptions) error
CreateChildBranchFn func(branch string) error
CreateOrphanedBranchFn func(branch string) error
CreateTagFn func(tag, msg string) error
CurrentBranchFn func() (string, error)
DeleteBranchFn func(branch string) error
DirFn func() string
FetchFn func(opts *FetchOptions) error
HasDiffsFn func() (bool, error)
HomeDirFn func() string
GetDiffPathsForCommitIDFn func(commitID string) ([]string, error)
IsAncestorFn func(parent string, child string) (bool, error)
IsRebasingFn func() (bool, error)
LastCommitIDFn func() (string, error)
ListTagsFn func() ([]TagMetadata, error)
ListCommitsFn func(opts *ListCommitsOptions) ([]CommitMetadata, error)
CommitMessageFn func(id string) (string, error)
GetCommitSignatureInfoFn func(string) (*CommitSignatureInfo, error)
IntegrateRemoteChangesFn func(*IntegrationOptions) error
PullFn func(*PullOptions) error
PushFn func(*PushOptions) error
RefsHaveDiffsFn func(commit1 string, commit2 string) (bool, error)
RemoteBranchExistsFn func(branch string) (bool, error)
ResetHardFn func() error
URLFn func() string
UpdateSubmodulesFn func() error
}
func (*MockRepo) AddAllAndCommit ¶
func (m *MockRepo) AddAllAndCommit( message string, commitOpts *CommitOptions, ) error
func (*MockRepo) CreateChildBranch ¶
func (*MockRepo) CreateOrphanedBranch ¶
func (*MockRepo) CurrentBranch ¶
func (*MockRepo) DeleteBranch ¶
func (*MockRepo) Fetch ¶
func (m *MockRepo) Fetch(opts *FetchOptions) error
func (*MockRepo) GetCommitSignatureInfo ¶
func (m *MockRepo) GetCommitSignatureInfo( commitID string, ) (*CommitSignatureInfo, error)
func (*MockRepo) GetDiffPathsForCommitID ¶
func (*MockRepo) IntegrateRemoteChanges ¶
func (m *MockRepo) IntegrateRemoteChanges( opts *IntegrationOptions, ) error
func (*MockRepo) IsAncestor ¶
func (*MockRepo) IsRebasing ¶
func (*MockRepo) LastCommitID ¶
func (*MockRepo) ListCommits ¶
func (m *MockRepo) ListCommits(opts *ListCommitsOptions) ([]CommitMetadata, error)
func (*MockRepo) ListTags ¶
func (m *MockRepo) ListTags() ([]TagMetadata, error)
func (*MockRepo) Pull ¶
func (m *MockRepo) Pull(opts *PullOptions) error
func (*MockRepo) Push ¶
func (m *MockRepo) Push(opts *PushOptions) error
func (*MockRepo) RefsHaveDiffs ¶
func (*MockRepo) RemoteBranchExists ¶
func (*MockRepo) UpdateSubmodules ¶ added in v1.8.8
type PullOptions ¶
type PullOptions struct {
// Branch is the remote branch to pull from. If not specified, the current
// branch will be pulled.
Branch string
// Force indicates whether the local branch should be reset to match
// the remote exactly, discarding any local state.
Force bool
}
PullOptions represents options for pulling changes from a remote branch.
type PushIntegrationPolicy ¶
type PushIntegrationPolicy string
PushIntegrationPolicy controls how remote changes are integrated into the local branch before pushing. The four options form a spectrum from least conservative (AlwaysRebase) to most conservative (AlwaysMerge).
const ( // PushIntegrationPolicyNone skips remote change integration entirely. This // is used internally when integration is not applicable (e.g. tag pushes // or force pushes). PushIntegrationPolicyNone PushIntegrationPolicy = "None" // PushIntegrationPolicyAlwaysRebase unconditionally uses pull --rebase to // integrate remote changes. This is the least secure option because it may // re-sign commits that Kargo did not author or strip existing signatures. PushIntegrationPolicyAlwaysRebase PushIntegrationPolicy = "AlwaysRebase" // PushIntegrationPolicyRebaseOrMerge uses pull --rebase when the // signature-trust decision matrix determines it is safe, and falls back to // a merge commit otherwise. This preserves linear history when possible // without undermining trust. PushIntegrationPolicyRebaseOrMerge PushIntegrationPolicy = "RebaseOrMerge" // PushIntegrationPolicyRebaseOrFail uses pull --rebase when the // signature-trust decision matrix determines it is safe, and fails the // push otherwise. This puts constraints on promotion process design and // treats the failure scenario as worthy of human investigation. PushIntegrationPolicyRebaseOrFail PushIntegrationPolicy = "RebaseOrFail" // PushIntegrationPolicyAlwaysMerge unconditionally uses a merge commit to // integrate remote changes. This is the most conservative option — it // never touches existing commits and always preserves original signatures. PushIntegrationPolicyAlwaysMerge PushIntegrationPolicy = "AlwaysMerge" )
type PushOptions ¶
type PushOptions struct {
// Force indicates whether the push should be forced.
Force bool
// TargetBranch specifies the branch to push to. If empty, the current branch
// TargetBranch specifies a remote branch to push to. If empty, the remote
// branch's name will be assumed to be the same as the branch checked out
// locally. Whether this field is empty or non-empty, if Tag is non-empty,
// it takes precedence and the tag will be pushed -- the branch will not.
TargetBranch string
// IntegrationPolicy controls how remote changes are integrated before
// pushing. If empty or set to PushIntegrationPolicyNone, no integration
// is performed.
IntegrationPolicy PushIntegrationPolicy
// Tag specifies a tag to push to the remote repository. If this field and
// TargetBranch are both non-empty, this field takes precedence and the tag
// will be pushed -- the branch will not.
Tag string
}
PushOptions represents options for pushing changes to a remote git repository.
type Repo ¶
type Repo interface {
// Close cleans up file system resources used by this repository. This should
// always be called before a repository goes out of scope.
Close() error
// Dir returns an absolute path to the repository.
Dir() string
// HomeDir returns an absolute path to the home directory of the system user
// who has cloned this repo.
HomeDir() string
// URL returns the remote URL of the repository as it was originally provided
// when the repository was cloned.
URL() string
WorkTree
}
Repo is an interface for interacting with a Git repository with a single working tree.
func Clone ¶
func Clone( repoURL string, clientOpts *ClientOptions, cloneOpts *CloneOptions, ) (Repo, error)
Clone produces a local clone of the remote git repository at the specified URL and returns an implementation of the Repo interface that is stateful and NOT suitable for use across multiple goroutines. This function will also perform any setup that is required for successfully authenticating to the remote repository.
type RepoCredentials ¶
type RepoCredentials struct {
// SSHPrivateKey is a private key that can be used for both reading from and
// writing to some remote repository.
//
// TODO(v1.13.0): Remove this field when SSH support is removed.
SSHPrivateKey string
// Username identifies a principal, which combined with the value of the
// Password field, can be used for both reading from and writing to some
// remote repository.
Username string
// Password, when combined with the principal identified by the Username
// field, can be used for both reading from and writing to some remote
// repository.
//
// #nosec G117 -- This struct is never marshaled.
Password string
}
RepoCredentials represents the credentials for connecting to a private git repository.
type TagMetadata ¶
type TagMetadata struct {
// Tag is the name of the tag.
Tag string
// CommitID is the ID (sha) of the commit associated with the tag.
CommitID string
// CreatorDate is the creation date of an annotated tag, or the commit date
// of a lightweight tag.
CreatorDate time.Time
// Author is the author of the commit message associated with the tag, in
// the format "Name <email>".
Author string
// Committer is the person who committed the commit associated with the tag,
// in the format "Name <email>".
Committer string
// Subject is the subject (first line) of the commit message associated
// with the tag.
Subject string
// Tagger is the person who created the tag, in the format "Name <email>".
// This field is only populated for annotated tags.
Tagger string
// Annotation is the annotation of the tag, if it is an annotated tag.
Annotation string
}
TagMetadata represents metadata associated with a Git tag.
type User ¶
type User struct {
// Name is the user's full name.
Name string
// Email is the user's email address.
Email string
// SigningKeyType indicates the type of signing key.
SigningKeyType SigningKeyType
// SigningKey is an optional string containing the raw signing key content.
// If provided, it takes precedence over SigningKeyPath.
SigningKey string
// SigningKeyPath is an optional path referencing a signing key for
// signing git objects. Ignored if SigningKey is provided.
SigningKeyPath string
}
User represents the user contributing to a git repository.
type WorkTree ¶
type WorkTree interface {
// AddAll stages pending changes for commit.
AddAll() error
// AddAllAndCommit is a convenience function that stages pending changes for
// commit to the current branch and then commits them using the provided
// commit message.
AddAllAndCommit(message string, commitOpts *CommitOptions) error
// Clean cleans the working tree.
Clean() error
// Clear executes `git rm -rf .` to remove all files from the working tree.
Clear() error
// Close cleans up file system resources used by this working tree. This
// should always be called before a WorkTree goes out of scope.
Close() error
// Checkout checks out the specified branch.
Checkout(branch string) error
// Commit commits staged changes to the current branch.
Commit(message string, opts *CommitOptions) error
// CreateChildBranch creates a new branch that is a child of the current
// branch.
CreateChildBranch(branch string) error
// CreateOrphanedBranch creates a new branch that shares no commit history
// with any other branch.
CreateOrphanedBranch(branch string) error
// CreateTag creates a new tag with the specified name.
CreateTag(name, msg string) error
// CurrentBranch returns the current branch
CurrentBranch() (string, error)
// DeleteBranch deletes the specified branch
DeleteBranch(branch string) error
// Dir returns an absolute path to the working tree.
Dir() string
// Fetch fetches updates from the remote repository.
Fetch(opts *FetchOptions) error
// HasDiffs returns a bool indicating whether the working tree currently
// contains any differences from what's already at the head of the current
// branch.
HasDiffs() (bool, error)
// HomeDir returns an absolute path to the home directory of the system user
// who cloned the repo associated with this working tree.
HomeDir() string
// GetDiffPathsForCommitID returns a string slice indicating the paths,
// relative to the root of the repository, of any files that are new or
// modified in the commit with the given ID.
GetDiffPathsForCommitID(commitID string) ([]string, error)
// IsAncestor returns true if parent branch is an ancestor of child
IsAncestor(parent string, child string) (bool, error)
// IsRebasing returns a bool indicating whether the working tree is currently
// in the middle of a rebase operation.
IsRebasing() (bool, error)
// LastCommitID returns the ID (sha) of the most recent commit to the current
// branch.
LastCommitID() (string, error)
// ListTags returns a slice of tags in the repository with metadata such as
// commit ID, creator date, and subject.
ListTags() ([]TagMetadata, error)
// ListCommits returns a slice of commits in the current branch with
// metadata such as commit ID, commit date, and subject.
ListCommits(opts *ListCommitsOptions) ([]CommitMetadata, error)
// CommitMessage returns the text of the most recent commit message associated
// with the specified commit ID.
CommitMessage(id string) (string, error)
// GetCommitSignatureInfo returns signature information for the specified
// commit, including whether it is signed by a trusted key and the
// identity of the signer. If opts provides a SigningKey, a temporary
// keyring is created with that key imported at ultimate trust and used
// for verification.
GetCommitSignatureInfo(commitID string) (*CommitSignatureInfo, error)
// IntegrateRemoteChanges integrates remote changes into the local branch
// before pushing. This fetches the target branch and applies the operator-
// configured integration policy (rebase, merge, or fail). It is a no-op
// if the remote branch does not exist or the policy is None.
IntegrateRemoteChanges(*IntegrationOptions) error
// Pull fetches and integrates changes from a remote branch
// into the current local branch.
Pull(*PullOptions) error
// Push pushes from the local repository to the remote repository.
Push(*PushOptions) error
// RefsHaveDiffs returns whether there is a diff between two commits/branches
RefsHaveDiffs(commit1 string, commit2 string) (bool, error)
// RemoteBranchExists returns a bool indicating if the specified branch exists
// in the remote repository.
RemoteBranchExists(branch string) (bool, error)
// ResetHard performs a hard reset on the working tree.
ResetHard() error
// URL returns the remote URL of the repository.
URL() string
// UpdateSubmodules updates the submodules in the working tree.
UpdateSubmodules() error
}
WorkTree is an interface for interacting with any working tree of a Git repository.
func LoadWorkTree ¶
func LoadWorkTree(path string, opts *LoadWorkTreeOptions) (WorkTree, error)