Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.0.83 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package git provides Git repository operations for colony2.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRepository      = errors.New("not a git repository")
	ErrNotFound           = errors.New("not found")
	ErrNotFastForward     = errors.New("not a fast-forward")
	ErrConflict           = errors.New("merge conflict")
	ErrAuthFailed         = errors.New("authentication failed")
	ErrUncommittedChanges = errors.New("uncommitted changes")
	ErrNetworkFailure     = errors.New("network failure")
)

Standard error variables.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Type          AuthType
	SSHKeyPath    string // Path to SSH private key
	SSHPassword   string // SSH key passphrase
	HTTPSUsername string // HTTPS username
	HTTPSPassword string // HTTPS password/token
}

AuthConfig configures authentication for remote operations.

type AuthType

type AuthType int

AuthType represents the type of authentication to use.

const (
	// AuthTypeNone indicates no authentication.
	AuthTypeNone AuthType = iota
	// AuthTypeSSH indicates SSH key authentication.
	AuthTypeSSH
	// AuthTypeHTTPS indicates HTTPS authentication.
	AuthTypeHTTPS
)

type CheckoutOptions

type CheckoutOptions struct {
	CreateBranch string // Create new branch at ref (empty = no creation)
	Force        bool   // Discard local changes
	Detach       bool   // Detach HEAD (create detached HEAD state)
}

CheckoutOptions configures checkout operations.

type CloneOptions

type CloneOptions struct {
	Branch         string                 // Specific branch to clone (empty = default branch)
	Depth          *int                   // Shallow clone depth (nil = full clone)
	SingleBranch   bool                   // Clone only the specified branch
	Bare           bool                   // Create a bare repository
	SparseCheckout *SparseCheckoutOptions // Sparse checkout config (nil = full checkout)
}

CloneOptions configures repository clone operations.

type Commit

type Commit struct {
	Hash      string    `json:"hash"`
	Author    string    `json:"author"`
	Date      time.Time `json:"date"`
	Message   string    `json:"message"`
	ShortHash string    `json:"shortHash"`
}

Commit represents a Git commit.

type Config

type Config struct {
	// DefaultAuthor is used when no Git user is configured.
	DefaultAuthor string

	// DefaultEmail is used when no Git email is configured.
	DefaultEmail string

	// Auth configures authentication for remote operations.
	Auth *AuthConfig
}

Config defines configuration for Git operations.

type FetchOptions

type FetchOptions struct {
	Remote string // Remote name (default: "origin")
	Branch string // Specific branch to fetch (empty = all branches)
	Prune  bool   // Remove remote-tracking references that no longer exist
	Tags   bool   // Fetch tags
}

FetchOptions configures fetch operations.

type FileInfo

type FileInfo struct {
	Path  string
	IsDir bool
	Size  int64
}

FileInfo represents information about a file in a repository.

type GitError

type GitError struct {
	Op     string // Operation that failed (e.g., "clone", "push")
	Path   string // Repository path
	Err    error  // Underlying error
	Stderr string // Git command stderr output (if applicable)
}

GitError wraps git operation errors with additional context.

func (*GitError) Error

func (e *GitError) Error() string

func (*GitError) Unwrap

func (e *GitError) Unwrap() error

type InitOptions

type InitOptions struct {
	Bare          bool   // Create bare repository
	DefaultBranch string // Name of default branch (empty = "main")
}

InitOptions configures repository initialization.

type PullOptions

type PullOptions struct {
	Remote      string // Remote name (default: "origin")
	Branch      string // Remote branch (empty = tracking branch)
	FastForward bool   // Only allow fast-forward merges
	Rebase      bool   // Rebase instead of merge
}

PullOptions configures pull operations.

type PullResult

type PullResult struct {
	Updated       bool     // Whether local branch was updated
	OldCommit     string   // Commit hash before pull
	NewCommit     string   // Commit hash after pull
	ConflictFiles []string // Files with conflicts (if any)
}

PullResult contains the result of a pull operation.

type PushOptions

type PushOptions struct {
	Remote      string // Remote name (default: "origin")
	Branch      string // Local branch to push (empty = current branch)
	Force       bool   // Force push (overwrite remote)
	SetUpstream bool   // Set upstream tracking branch
}

PushOptions configures push operations.

type PushResult

type PushResult struct {
	Pushed        bool // Whether any commits were pushed
	Rejected      bool // Whether push was rejected
	CommitsPushed int  // Number of commits pushed
}

PushResult contains the result of a push operation.

type Remote

type Remote struct {
	Name     string
	FetchURL string
	PushURL  string
}

Remote represents a remote repository reference.

type Repository

type Repository interface {
	// GetStatus returns the current Git status of a node directory.
	GetStatus(ctx context.Context, nodePath string) (*Status, error)

	// GetDiff returns the diff of uncommitted changes.
	GetDiff(ctx context.Context, nodePath string, staged bool) (string, error)

	// GetHistory returns the commit history for a node.
	GetHistory(ctx context.Context, nodePath string, limit int) ([]Commit, error)

	// CreateCommit creates a new commit with the given message.
	CreateCommit(ctx context.Context, nodePath, message string) error

	// StageFiles stages the specified files for commit.
	StageFiles(ctx context.Context, nodePath string, files []string) error

	// UnstageFiles unstages the specified files.
	UnstageFiles(ctx context.Context, nodePath string, files []string) error

	// Clone creates a local copy of a remote repository.
	Clone(ctx context.Context, url string, localPath string, options CloneOptions) error

	// Fetch downloads objects and refs from remote repository.
	Fetch(ctx context.Context, nodePath string, options FetchOptions) error

	// Pull fetches from remote and integrates into current branch.
	Pull(ctx context.Context, nodePath string, options PullOptions) (*PullResult, error)

	// Push uploads local commits to remote repository.
	Push(ctx context.Context, nodePath string, options PushOptions) (*PushResult, error)

	// IsAncestor determines if one commit is an ancestor of another.
	IsAncestor(ctx context.Context, nodePath string, ancestor string, descendant string) (bool, error)

	// GetRemoteHead retrieves the commit hash of a remote branch.
	GetRemoteHead(ctx context.Context, nodePath string, remote string, branch string) (string, error)

	// GetCurrentCommit returns the commit hash of the current HEAD.
	GetCurrentCommit(ctx context.Context, nodePath string) (string, error)

	// Checkout switches to a different branch or commit.
	Checkout(ctx context.Context, nodePath string, ref string, options CheckoutOptions) error

	// InitRepository creates a new git repository.
	InitRepository(ctx context.Context, path string, options InitOptions) error

	// AddRemote adds a remote repository reference.
	AddRemote(ctx context.Context, nodePath string, name string, url string) error

	// ListRemotes returns all configured remotes.
	ListRemotes(ctx context.Context, nodePath string) ([]Remote, error)

	// GetFileAtCommit retrieves file content from a specific commit.
	GetFileAtCommit(ctx context.Context, nodePath string, commit string, filePath string) ([]byte, error)

	// ListFilesAtCommit lists all files in a directory at a specific commit.
	ListFilesAtCommit(ctx context.Context, nodePath string, commit string, dirPath string) ([]FileInfo, error)

	// IsRepoBare checks if a repository is bare (no working directory).
	IsRepoBare(ctx context.Context, repoPath string) (bool, error)

	// GetCurrentBranch returns the name of the current branch.
	// Returns error if repository is in detached HEAD state.
	GetCurrentBranch(ctx context.Context, repoPath string) (string, error)

	// ConfigureUser sets the user.name and user.email for a repository.
	// This is required before creating commits.
	ConfigureUser(ctx context.Context, repoPath string, name string, email string) error

	// UpdateRemoteURL updates the URL of an existing remote.
	UpdateRemoteURL(ctx context.Context, repoPath string, remoteName string, newURL string) error
}

Repository provides Git operations for node directories.

func NewRepository

func NewRepository(config Config) Repository

NewRepository creates a new Git repository interface.

type SparseCheckoutOptions

type SparseCheckoutOptions struct {
	// Cone enables cone mode sparse checkout (recommended).
	// When true, Paths are treated as directory paths.
	// When false, sparse checkout is disabled.
	Cone bool

	// Paths specifies the directories to checkout in cone mode.
	// Example: []string{".c2/recipes", "docs"}
	// Empty slice disables sparse checkout.
	Paths []string
}

SparseCheckoutOptions configures sparse checkout during clone operations.

type Status

type Status struct {
	Branch    string       `json:"branch"`
	Clean     bool         `json:"clean"`
	Files     []StatusFile `json:"files"`
	Ahead     int          `json:"ahead"`
	Behind    int          `json:"behind"`
	HasRemote bool         `json:"hasRemote"`
}

Status represents the current status of a Git repository.

type StatusFile

type StatusFile struct {
	Path   string `json:"path"`
	Status string `json:"status"` // "M", "A", "D", "?", etc.
}

StatusFile represents a single file in the Git status.

Directories

Path Synopsis
Package gitcollector provides git-aware file collection for LLM consumption
Package gitcollector provides git-aware file collection for LLM consumption
internal
Package selectorcache materializes git refs into reusable source directories.
Package selectorcache materializes git refs into reusable source directories.

Jump to

Keyboard shortcuts

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