gitclient

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

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

type GitClient struct {
	RepoURL string
	Branch  string
	Token   string
}

func NewGitClient

func NewGitClient(repoURL, branch, token string) *GitClient

func (*GitClient) UpdateFile

func (c *GitClient) UpdateFile(filePath string, newContent []byte, commitMsg string) error

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.

Jump to

Keyboard shortcuts

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