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

git

package
v2.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CloneScratchPrefix names the per-run clone scratch dirs created by Clone.
	CloneScratchPrefix = "gitops-"

	SSHHostKeyVerificationStrict    = "strict"     // Require host key in known_hosts
	SSHHostKeyVerificationAcceptNew = "accept_new" // Auto-add unknown host keys
	SSHHostKeyVerificationSkip      = "skip"       // Skip host key verification (insecure)

)

Variables

View Source
var (
	// ErrPushRejected reports that the remote branch advanced between checkout and push.
	ErrPushRejected        = errors.New("push rejected: remote branch was updated by another writer")
	ErrInvalidCommit       = errors.New("invalid commit hash")
	ErrSelectionUnreadable = errors.New("selection is unreadable")
	ErrSelectionLimits     = errors.New("selection exceeds limits")
	ErrSelectionInvalid    = errors.New("selection is invalid")
)

Functions

func IsBinaryContent added in v2.12.0

func IsBinaryContent(content []byte) bool

IsBinaryContent reports whether content looks binary rather than text.

func ParseSigningKey added in v2.12.0

func ParseSigningKey(armored, passphrase string) (*openpgp.Entity, error)

ParseSigningKey loads an armored OpenPGP private key and unlocks it with passphrase when the key material is encrypted.

func RepositoryAttribute added in v2.16.0

func RepositoryAttribute(rawURL string) attribute.KeyValue

RepositoryAttribute names the repository on spans without credentials or query tokens.

func ValidatePath

func ValidatePath(repoPath, requestedPath string) error

ValidatePath ensures the path is safe and doesn't escape the repo

Types

type AuthConfig

type AuthConfig struct {
	AuthType               string
	Username               string
	Token                  string
	SSHKey                 string
	SSHHostKeyVerification string // strict, accept_new, skip
}

AuthConfig holds authentication configuration

type BranchInfo

type BranchInfo struct {
	Name      string
	IsDefault bool
}

BranchInfo holds information about a git branch

type Client

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

Client handles git operations

func NewClient

func NewClient(workDir string) *Client

NewClient creates a new git client

func (*Client) BrowseTree

func (c *Client) BrowseTree(ctx context.Context, repoPath, targetPath string) ([]gitops.FileTreeNode, error)

BrowseTree returns the file tree at targetPath, confined to the clone directory: escaping paths and symlinks pointing outside it are rejected rather than followed.

func (*Client) CheckoutForWrite added in v2.12.0

func (c *Client) CheckoutForWrite(ctx context.Context, url, branch string, auth AuthConfig) (*WriteCheckout, error)

CheckoutForWrite clones url at branch into a scratch directory. A branch that does not exist yet is created from the remote default branch, and an empty repository is initialized locally so the first push creates the branch.

func (*Client) Cleanup

func (c *Client) Cleanup(repoPath string) error

Cleanup removes a temporary repository directory with os.RemoveAll, since acfs refuses to remove its own root.

func (*Client) Clone

func (c *Client) Clone(ctx context.Context, url, branch string, auth AuthConfig, depth int) (repoPath string, err error)

Clone clones a repository to a temporary directory. A depth of 0 fetches the full history; read-only callers pass 1 to fetch only the branch tip.

func (*Client) CommitAndPush added in v2.12.0

func (c *Client) CommitAndPush(ctx context.Context, checkout *WriteCheckout, req CommitRequest, auth AuthConfig) (string, bool, error)

CommitAndPush writes the requested files, removes the listed paths, commits when the tree changed, pushes without force, and verifies the remote branch points at the pushed commit. It returns the resulting head and whether a new commit was created.

func (*Client) CommitDiff added in v2.12.0

func (c *Client) CommitDiff(ctx context.Context, repoPath, commitHash, directory string) (HistoryEntry, []FileDiff, error)

CommitDiff returns the commit and the per-file unified diffs inside directory.

func (*Client) DirectoryHistory added in v2.12.0

func (c *Client) DirectoryHistory(ctx context.Context, repoPath, directory string, limit int) ([]HistoryEntry, error)

DirectoryHistory lists the newest commits that touched directory, newest first.

func (*Client) Discard added in v2.12.0

func (c *Client) Discard(ctx context.Context, repoPath string)

Discard removes a scratch checkout, logging instead of failing when removal breaks.

func (*Client) FileExists

func (c *Client) FileExists(ctx context.Context, repoPath, filePath string) bool

FileExists checks if a file exists in the repository

func (*Client) GetCurrentCommit

func (c *Client) GetCurrentCommit(ctx context.Context, repoPath string) (string, error)

GetCurrentCommit returns the HEAD commit hash of a cloned repository

func (*Client) ListBranches

func (c *Client) ListBranches(ctx context.Context, url string, auth AuthConfig) ([]BranchInfo, error)

ListBranches lists a remote repository's branches, default branch first.

func (*Client) ProbeRemote

func (c *Client) ProbeRemote(ctx context.Context, url string, auth AuthConfig) error

ProbeRemote verifies that a remote repository is reachable without cloning it.

func (*Client) PurgeScratchDirs added in v2.10.0

func (c *Client) PurgeScratchDirs(ctx context.Context, maxAge time.Duration) (int, error)

PurgeScratchDirs removes clone scratch dirs ("gitops-*") under the work dir whose mtime is older than maxAge. maxAge <= 0 removes all (boot sweep).

func (*Client) ReadFile

func (c *Client) ReadFile(ctx context.Context, repoPath, filePath string) (string, error)

ReadFile reads a file from the repository

func (*Client) RemoteBranchHead added in v2.12.0

func (c *Client) RemoteBranchHead(ctx context.Context, url, branch string, auth AuthConfig) (string, bool, error)

RemoteBranchHead resolves the remote head of branch without cloning.

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context, url, branch string, auth AuthConfig) error

TestConnection tests if the repository can be accessed with the given credentials

func (*Client) WalkDirectory

func (c *Client) WalkDirectory(ctx context.Context, repoPath, composePath string,
	maxFiles int, maxTotalSize, maxBinarySize int64,
) (*DirectoryWalkResult, error)

WalkDirectory returns every file in the compose file's directory, enforcing file count and total size limits and skipping large binary files.

type CollectOptions added in v2.12.0

type CollectOptions struct {
	MaxFiles     int
	MaxTotalSize int64
	SkipDir      func(name string) bool
	SkipFile     func(name string) bool
}

CollectOptions bounds CollectFiles; SkipDir and SkipFile see base names while directories expand.

type CommitFile added in v2.12.0

type CommitFile struct {
	Path       string
	Content    []byte
	Executable bool
}

CommitFile is one file to write into the checkout, repo-relative.

func CollectFiles added in v2.12.0

func CollectFiles(ctx context.Context, root string, selection []string, opts CollectOptions) ([]CommitFile, error)

CollectFiles reads the selected files and directories under root as commit files, sorted by path.

type CommitIdentity added in v2.12.0

type CommitIdentity struct {
	Name    string
	Email   string
	SignKey *openpgp.Entity
}

CommitIdentity is the author Arcane commits as for one repository.

type CommitRequest added in v2.12.0

type CommitRequest struct {
	Files       []CommitFile
	Remove      []string
	Message     string
	AuthorName  string
	AuthorEmail string
	SignKey     *openpgp.Entity
}

CommitRequest describes the tree mutation to commit and push.

type DirectoryWalkResult

type DirectoryWalkResult struct {
	Files           []SyncFileInfo
	TotalFiles      int
	TotalSize       int64
	SkippedBinaries int
}

DirectoryWalkResult holds the result of walking a directory for sync

type FileDiff added in v2.12.0

type FileDiff struct {
	Path  string
	Patch string
}

FileDiff is the unified diff of one file within a commit.

type HistoryEntry added in v2.12.0

type HistoryEntry struct {
	Hash    string
	Author  string
	Email   string
	Message string
	Date    time.Time
	Files   []string
}

HistoryEntry is one commit touching a directory.

type SyncFileInfo

type SyncFileInfo struct {
	RelativePath string // Path relative to the sync directory
	Content      []byte
	Size         int64
	IsBinary     bool
	// Executable mirrors git's +x bit so lifecycle hook scripts arrive runnable.
	Executable bool
}

SyncFileInfo holds information about a file to be synced

type WriteCheckout added in v2.12.0

type WriteCheckout struct {
	RepoPath     string
	Branch       string
	HeadCommit   string
	BranchExists bool
	// contains filtered or unexported fields
}

WriteCheckout is a scratch clone prepared for committing to one branch.

Jump to

Keyboard shortcuts

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