{"modulePath":"github.com/save-abandoned-projects/libgitops","version":"v0.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gitdir\n\n## Variables\n\n```go\nvar (\n\t// ErrNotStarted happens if you try to operate on the gitDirectory before you have started\n\t// it with StartCheckoutLoop.\n\tErrNotStarted = errors.New(\"the gitDirectory hasn't been started (and hence, cloned) yet\")\n\t// ErrCannotWriteToReadOnly happens if you try to do a write operation for a non-authenticated Git repo.\n\tErrCannotWriteToReadOnly = errors.New(\"the gitDirectory is read-only, cannot write\")\n)\n```\n\n## Types\n\n```go\ntype AuthMethod interface {\n\t// This AuthMethod is a superset of the go-git AuthMethod\n\ttransport.AuthMethod\n\t// TransportType defines what transport type should be used with this method\n\tTransportType() gitprovider.TransportType\n}\n```\nAuthMethod specifies the authentication method and related credentials for connecting to a Git repository.\n\n```go\nfunc NewHTTPSAuthMethod(username, password string) (AuthMethod, error)\n```\n\n```go\nfunc NewSSHAuthMethod(identityFile, knownHostsFile []byte) (AuthMethod, error)\n```\nNewSSHAuthMethod creates a new AuthMethod for the Git SSH protocol, using a given identity and known\\_hosts file.\n\nidentityFile is the bytes of e.g. ~/.ssh/id\\_rsa, given that ~/.ssh/id\\_rsa.pub is registered with and trusted by the Git provider.\n\nknownHostsFile should be the file content of the known\\_hosts file to use for remote (e.g. GitHub) public key verification. If you want to use the default git CLI behavior, populate this byte slice with contents from ioutil.ReadFile(\"~/.ssh/known\\_hosts\").\n\n```go\ntype GitDirectory interface {\n\t// Dir returns the backing temporary directory of the git clone.\n\tDir() string\n\t// MainBranch returns the configured main branch.\n\tMainBranch() string\n\t// RepositoryRef returns the repository reference.\n\tRepositoryRef() gitprovider.RepositoryRef\n\n\t// StartCheckoutLoop clones the repo synchronously, and then starts the checkout loop non-blocking.\n\t// If the checkout loop has been started already, this is a no-op.\n\tStartCheckoutLoop() error\n\t// Suspend waits for any pending transactions or operations, and then locks the internal mutex so that\n\t// no other operations can start. This means the periodic background checkout loop will momentarily stop.\n\tSuspend()\n\t// Resume unlocks the mutex locked in Suspend(), so that other Git operations, like the background checkout\n\t// loop can resume its operation.\n\tResume()\n\n\t// Pull performs a pull \u0026 checkout to the latest revision.\n\t// ErrNotStarted is returned if the repo hasn't been cloned yet.\n\tPull(ctx context.Context) error\n\n\t// CheckoutNewBranch creates a new branch and checks out to it.\n\t// ErrNotStarted is returned if the repo hasn't been cloned yet.\n\tCheckoutNewBranch(branchName string) error\n\t// CheckoutMainBranch goes back to the main branch.\n\t// ErrNotStarted is returned if the repo hasn't been cloned yet.\n\tCheckoutMainBranch() error\n\n\t// Commit creates a commit of all changes in the current worktree with the given parameters.\n\t// It also automatically pushes the branch after the commit.\n\t// ErrNotStarted is returned if the repo hasn't been cloned yet.\n\t// ErrCannotWriteToReadOnly is returned if opts.AuthMethod wasn't provided.\n\tCommit(ctx context.Context, authorName, authorEmail, msg string) error\n\t// CommitChannel is a channel to where new observed Git SHAs are written.\n\tCommitChannel() chan string\n\n\t// Cleanup terminates any pending operations, and removes the temporary directory.\n\tCleanup() error\n}\n```\nGitDirectory is an abstraction layer for a temporary Git clone. It pulls and checks out new changes periodically in the background. It also allows high-level access to write operations, like creating a new branch, committing, and pushing.\n\n```go\nfunc NewGitDirectory(repoRef gitprovider.RepositoryRef, opts GitDirectoryOptions) (GitDirectory, error)\n```\nCreate a new GitDirectory implementation. In order to start using this, run StartCheckoutLoop().\n\n```go\ntype GitDirectoryOptions struct {\n\t// Options\n\tBranch   string        // default \"master\"\n\tInterval time.Duration // default 30s\n\tTimeout  time.Duration // default 1m\n\n\t// Authentication\n\tAuthMethod AuthMethod\n}\n```\nGitDirectoryOptions provides options for the gitDirectory. TODO: Refactor this into the controller-runtime Options factory pattern.\n\n```go\nfunc (o *GitDirectoryOptions) Default()\n```\n\n","path":"github.com/save-abandoned-projects/libgitops/pkg/gitdir","name":"gitdir","synopsis":"","isRedistributable":true}
