Documentation
¶
Overview ¶
Package gitclient provides a simple Git client for updating files in remote repositories using in-memory operations.
It uses go-git and go-billy's memfs to perform all git operations (clone, update, commit, push) without writing to disk. This is useful for ephemeral or serverless environments, or when you want to avoid filesystem side effects.
Example usage:
func main() {
client := &GitClient{
RepoURL: "https://github.com/youruser/yourrepo.git",
Branch: "main",
Token: "<your-git-token>",
}
err := client.UpdateFile("path/to/file.txt", "new file content", "Update file.txt via automation")
if err != nil {
panic(err)
}
fmt.Println("File updated and pushed successfully!")
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GitClient ¶
func NewGitClient ¶
func (*GitClient) CheckConnection ¶ added in v1.4.10
CheckConnection attempts to clone the repository to verify access and authentication. Returns nil if successful, or an error if the connection/auth fails.
func (*GitClient) CheckHealth ¶ added in v1.4.10
CheckHealth checks the health of the git connection and returns a health check
func (*GitClient) GetFile ¶ added in v1.4.10
GetFile clones the repo into an in-memory filesystem and returns the contents of the specified file as []byte. If the file does not exist, it returns nil and no error.
func (*GitClient) UploadFile ¶ added in v1.4.10
UpdateFile clones the repo into an in-memory filesystem, updates a file, commits, and pushes the change. No files are written to disk; all operations are performed in memory using go-billy/memfs.
Arguments:
filePath: Path to the file to update (relative to repo root) newContent: New content to write to the file commitMsg: Commit message for the change
Returns an error if any git operation fails.