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

git

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package git provides Git repository operations for MCPRegistry sources.

This package implements a thin wrapper around the go-git library to enable MCPRegistry resources to fetch registry data directly from Git repositories. It supports cloning repositories, checking out specific branches/tags/commits, and retrieving file contents from the repository.

Key Components:

Client Interface

The Client interface defines the core Git operations:

  • Clone: Clone public repositories
  • Pull: Update existing repositories (planned for future implementation)
  • GetFileContent: Retrieve specific files from repositories
  • GetCommitHash: Get current commit hash for change detection
  • Cleanup: Remove local repository directories

Example Usage

client := git.NewDefaultGitClient()
config := &git.CloneConfig{
    URL:       "https://github.com/example/registry.git",
    Branch:    "main",
    Directory: "/tmp/repo",
}

repoInfo, err := client.Clone(ctx, config)
if err != nil {
    return err
}
defer client.Cleanup(repoInfo)

content, err := client.GetFileContent(repoInfo, "registry.json")
if err != nil {
    return err
}

Security Considerations

This package is designed to be used within a Kubernetes operator environment where Git repositories contain MCP server registry data. Future versions will include security hardening such as:

  • Repository URL validation to prevent SSRF attacks
  • Sandboxed Git operations
  • Secure credential management via Kubernetes secrets

Implementation Status

Current implementation supports:

  • Public repository access via HTTPS
  • Branch, tag, and commit checkout
  • File content retrieval
  • Temporary directory management

Planned features:

  • Authentication for private repositories
  • Repository caching for performance
  • Webhook support for immediate sync triggers
  • Git LFS support for large files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Clone clones a repository with the given configuration
	Clone(ctx context.Context, config *CloneConfig) (*RepositoryInfo, error)

	// GetFileContent retrieves the content of a file from the repository
	GetFileContent(repoInfo *RepositoryInfo, path string) ([]byte, error)

	// Cleanup removes local repository directory
	Cleanup(repoInfo *RepositoryInfo) error
}

Client defines the interface for Git operations

type CloneConfig

type CloneConfig struct {
	// URL is the repository URL to clone
	URL string

	// Branch is the specific branch to clone (optional)
	Branch string

	// Tag is the specific tag to clone (optional)
	Tag string

	// Commit is the specific commit to clone (optional)
	Commit string

	// Directory is the local directory to clone into
	Directory string
}

CloneConfig contains configuration for cloning a repository

type DefaultGitClient

type DefaultGitClient struct{}

DefaultGitClient implements GitClient using go-git

func NewDefaultGitClient

func NewDefaultGitClient() *DefaultGitClient

NewDefaultGitClient creates a new DefaultGitClient

func (*DefaultGitClient) Cleanup

func (*DefaultGitClient) Cleanup(repoInfo *RepositoryInfo) error

Cleanup removes local repository directory

func (*DefaultGitClient) Clone

func (c *DefaultGitClient) Clone(ctx context.Context, config *CloneConfig) (*RepositoryInfo, error)

Clone clones a repository with the given configuration

func (*DefaultGitClient) GetFileContent

func (*DefaultGitClient) GetFileContent(repoInfo *RepositoryInfo, path string) ([]byte, error)

GetFileContent retrieves the content of a file from the repository

type RepositoryInfo

type RepositoryInfo struct {
	// Repository is the go-git repository instance
	Repository *git.Repository

	// Branch is the current branch name
	Branch string

	// RemoteURL is the remote repository URL
	RemoteURL string
}

RepositoryInfo contains information about a Git repository

Jump to

Keyboard shortcuts

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