Documentation
¶
Index ¶
- Constants
- Variables
- func IsBinaryContent(content []byte) bool
- func ParseSigningKey(armored, passphrase string) (*openpgp.Entity, error)
- func RepositoryAttribute(rawURL string) attribute.KeyValue
- func ValidatePath(repoPath, requestedPath string) error
- type AuthConfig
- type BranchInfo
- type Client
- func (c *Client) BrowseTree(ctx context.Context, repoPath, targetPath string) ([]gitops.FileTreeNode, error)
- func (c *Client) CheckoutForWrite(ctx context.Context, url, branch string, auth AuthConfig) (*WriteCheckout, error)
- func (c *Client) Cleanup(repoPath string) error
- func (c *Client) Clone(ctx context.Context, url, branch string, auth AuthConfig, depth int) (repoPath string, err error)
- func (c *Client) CommitAndPush(ctx context.Context, checkout *WriteCheckout, req CommitRequest, ...) (string, bool, error)
- func (c *Client) CommitDiff(ctx context.Context, repoPath, commitHash, directory string) (HistoryEntry, []FileDiff, error)
- func (c *Client) DirectoryHistory(ctx context.Context, repoPath, directory string, limit int) ([]HistoryEntry, error)
- func (c *Client) Discard(ctx context.Context, repoPath string)
- func (c *Client) FileExists(ctx context.Context, repoPath, filePath string) bool
- func (c *Client) GetCurrentCommit(ctx context.Context, repoPath string) (string, error)
- func (c *Client) ListBranches(ctx context.Context, url string, auth AuthConfig) ([]BranchInfo, error)
- func (c *Client) ProbeRemote(ctx context.Context, url string, auth AuthConfig) error
- func (c *Client) PurgeScratchDirs(ctx context.Context, maxAge time.Duration) (int, error)
- func (c *Client) ReadFile(ctx context.Context, repoPath, filePath string) (string, error)
- func (c *Client) RemoteBranchHead(ctx context.Context, url, branch string, auth AuthConfig) (string, bool, error)
- func (c *Client) TestConnection(ctx context.Context, url, branch string, auth AuthConfig) error
- func (c *Client) WalkDirectory(ctx context.Context, repoPath, composePath string, maxFiles int, ...) (*DirectoryWalkResult, error)
- type CollectOptions
- type CommitFile
- type CommitIdentity
- type CommitRequest
- type DirectoryWalkResult
- type FileDiff
- type HistoryEntry
- type SyncFileInfo
- type WriteCheckout
Constants ¶
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 ¶
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
IsBinaryContent reports whether content looks binary rather than text.
func ParseSigningKey ¶ added in v2.12.0
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
RepositoryAttribute names the repository on spans without credentials or query tokens.
func ValidatePath ¶
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 ¶
BranchInfo holds information about a git branch
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles git operations
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 ¶
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
Discard removes a scratch checkout, logging instead of failing when removal breaks.
func (*Client) FileExists ¶
FileExists checks if a file exists in the repository
func (*Client) GetCurrentCommit ¶
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 ¶
ProbeRemote verifies that a remote repository is reachable without cloning it.
func (*Client) PurgeScratchDirs ¶ added in v2.10.0
PurgeScratchDirs removes clone scratch dirs ("gitops-*") under the work dir whose mtime is older than maxAge. maxAge <= 0 removes all (boot sweep).
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 ¶
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
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
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 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.