Documentation
¶
Overview ¶
Package git provides support for Git operations needed throughout the Terragrunt codebase.
The package primarily uses the `git` binary installed on the host system, but experimentally supports the `go-git` library for some operations. As of yet, the performance of the `go-git` library is not as good as the `git` binary, so we don't use it by default. If we can optimize usage of the `go-git` library so that the performance difference is negligible, we can choose to use it instead of the `git` binary for certain operations.
Even assuming the performance differences are negligible, we'll still prefer to use the `git` binary for certain operations. For example, operations related to remotes are likely easier to support with the `git` binary, as users might have git configurations for authentication that would be inconvenient to port over to configuration of the `go-git` library. This might change in the future.
We'll prefix usage of the `go-git` library with "Go" to make it clear when we're using it.
Index ¶
- Variables
- func ExtractRepoName(repo string) string
- type Diffs
- type Error
- type GitRunner
- func (g *GitRunner) CatFile(ctx context.Context, hash string, out io.Writer) error
- func (g *GitRunner) Clone(ctx context.Context, repo string, bare bool, depth int, branch string) error
- func (g *GitRunner) Config(ctx context.Context, name string) (string, error)
- func (g *GitRunner) CreateDetachedWorktree(ctx context.Context, dir, ref string) error
- func (g *GitRunner) CreateTempDir() (string, func() error, error)
- func (g *GitRunner) Diff(ctx context.Context, fromRef, toRef string) (*Diffs, error)
- func (g *GitRunner) GetRepoRoot(ctx context.Context) (string, error)
- func (g *GitRunner) GoAdd(paths ...string) error
- func (g *GitRunner) GoCheckout(opts *git.CheckoutOptions) error
- func (g *GitRunner) GoCloseStorage() error
- func (g *GitRunner) GoCommit(message string, opts *git.CommitOptions) error
- func (g *GitRunner) GoLsTreeRecursive(ref string) ([]TreeEntry, error)
- func (g *GitRunner) GoOpenGitDir() error
- func (g *GitRunner) GoOpenRepo() error
- func (g *GitRunner) GoOpenRepoCommitObject(hash plumbing.Hash) (*object.Commit, error)
- func (g *GitRunner) GoOpenRepoHead() (*plumbing.Reference, error)
- func (g *GitRunner) GoStatus() (git.Status, error)
- func (g *GitRunner) HasUncommittedChanges(ctx context.Context) bool
- func (g *GitRunner) Init(ctx context.Context) error
- func (g *GitRunner) LsRemote(ctx context.Context, repo, ref string) ([]LsRemoteResult, error)
- func (g *GitRunner) LsTreeRecursive(ctx context.Context, ref string) (*Tree, error)
- func (g *GitRunner) RemoveWorktree(ctx context.Context, path string) error
- func (g *GitRunner) RequiresGoRepo() error
- func (g *GitRunner) RequiresWorkDir() error
- func (g *GitRunner) WithWorkDir(workDir string) *GitRunner
- type LsRemoteResult
- type Tree
- type TreeEntry
- type WrappedError
Constants ¶
This section is empty.
Variables ¶
var ( ErrCommandSpawn = errors.New("failed to spawn git command") ErrNoMatchingReference = errors.New("no matching reference") ErrReadTree = errors.New("failed to read tree") ErrNoWorkDir = errors.New("working directory not set") ErrNoGoRepo = errors.New("go repository not set") )
Git operation errors
Functions ¶
func ExtractRepoName ¶
ExtractRepoName extracts the repository name from a git URL
Types ¶
type Error ¶
type Error string
Error types that can be returned by the cas package
const ( // ErrTempDir is returned when failing to create or close a temporary directory ErrTempDir Error = "failed to create or manage temporary directory" // ErrCreateDir is returned when failing to create a directory ErrCreateDir Error = "failed to create directory" // ErrReadFile is returned when failing to read a file ErrReadFile Error = "failed to read file" // ErrParseTree is returned when failing to parse git tree output ErrParseTree Error = "failed to parse git tree output" // ErrParseDiff is returned when failing to parse git diff output ErrParseDiff Error = "failed to parse git diff output" // ErrGitClone is returned when the git clone operation fails ErrGitClone Error = "failed to complete git clone" // ErrCreateTempDir is returned when failing to create a temporary directory ErrCreateTempDir Error = "failed to create temporary directory" // ErrCleanupTempDir is returned when failing to clean up a temporary directory ErrCleanupTempDir Error = "failed to clean up temporary directory" )
type GitRunner ¶
GitRunner handles git command execution
func NewGitRunner ¶
NewGitRunner creates a new GitRunner instance
func (*GitRunner) Clone ¶
func (g *GitRunner) Clone(ctx context.Context, repo string, bare bool, depth int, branch string) error
Clone performs a git clone operation
func (*GitRunner) CreateDetachedWorktree ¶
CreateDetachedWorktree creates a new detached worktree for a given reference as a given directory
func (*GitRunner) CreateTempDir ¶
CreateTempDir creates a new temporary directory for git operations
func (*GitRunner) GetRepoRoot ¶
GetRepoRoot returns the root directory of the git repository.
func (*GitRunner) GoCheckout ¶ added in v0.95.1
func (g *GitRunner) GoCheckout(opts *git.CheckoutOptions) error
GoCheckout checks out a branch in the Git repository.
func (*GitRunner) GoCloseStorage ¶
GoCloseStorage closes the storage for a Git repository.
func (*GitRunner) GoCommit ¶
func (g *GitRunner) GoCommit(message string, opts *git.CommitOptions) error
GoCommit commits changes to the Git repository.
func (*GitRunner) GoLsTreeRecursive ¶
GoLsTreeRecursive uses the `go-git` library to recursively list the contents of a git tree.
In testing, this is significantly slower than LsTreeRecursive, so we don't use it right now. We'll keep it here and benchmark it again later if we can optimize it.
func (*GitRunner) GoOpenGitDir ¶
GoOpenGitDir opens a Git repository using the `go-git` library, but chroots to the `.git` directory if present.
Use this for operations that don't need access to the rest of the repository for read-only access, etc.
Opening a Git repository leaves the storage open, so it's the responsibility of the caller to close the storage with `GoCloseStorage` when it is no longer needed.
func (*GitRunner) GoOpenRepo ¶
GoOpenRepo opens a Git repository using the `go-git` library.
func (*GitRunner) GoOpenRepoCommitObject ¶
GoOpenRepoCommitObject gets a commit object from the Git repository.
func (*GitRunner) GoOpenRepoHead ¶
GoOpenRepoHead gets the head of the Git repository.
func (*GitRunner) HasUncommittedChanges ¶ added in v0.95.1
HasUncommittedChanges checks if there are uncommitted changes in the working directory. Returns true if there are uncommitted changes, false otherwise (including if git command fails or not in a git repo).
func (*GitRunner) LsRemote ¶
LsRemote runs git ls-remote for a specific reference. If ref is empty, we check HEAD instead.
func (*GitRunner) LsTreeRecursive ¶
LsTreeRecursive runs git ls-tree -r and returns all blobs recursively This eliminates the need for multiple separate ls-tree calls on subtrees
func (*GitRunner) RemoveWorktree ¶
RemoveWorktree removes a Git worktree for a given path
func (*GitRunner) RequiresGoRepo ¶
RequiresGoRepo returns an error if no go repository is set
func (*GitRunner) RequiresWorkDir ¶
RequiresWorkDir returns an error if no working directory is set
func (*GitRunner) WithWorkDir ¶
WithWorkDir returns a new GitRunner with the specified working directory
type LsRemoteResult ¶
LsRemoteResult represents the output of git ls-remote
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a git tree object with its entries
type TreeEntry ¶
TreeEntry represents a single entry in a git tree
func ParseTreeEntry ¶
ParseTreeEntry parses a single line from git ls-tree output
type WrappedError ¶
type WrappedError struct {
Op string // Operation that failed
Path string // File path if applicable
Err error // Original error
Context string // Additional context
}
WrappedError provides additional context for errors
func (*WrappedError) Error ¶
func (e *WrappedError) Error() string
func (*WrappedError) Unwrap ¶
func (e *WrappedError) Unwrap() error