gitrepo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitrepo clones and updates the Git repositories of Git stacks (#37, ADR-0039) with go-git: no git binary is needed on the host, and credentials stay in memory.

Index

Constants

View Source
const (
	KindToken = "token" // HTTPS with a username and an access token or password
	KindSSH   = "ssh"   // SSH with a private key
)

Credential kinds.

Variables

View Source
var ErrHostKeyChanged = errors.New("the SSH host key changed")

ErrHostKeyChanged is returned when an SSH server presents another key than the one trusted.

Functions

func IsSSH

func IsSSH(raw string) bool

IsSSH reports whether a URL uses SSH.

func RemoteHead

func RemoteHead(ctx context.Context, fullRef string, o Options) (string, error)

RemoteHead asks the remote for the commit its full ref points to, without fetching objects (git ls-remote). For an annotated tag it is the tagged commit.

func Update

func Update(ctx context.Context, dir, fullRef string, o Options) (Commit, Commit, error)

Update fetches the full ref (as returned by Clone) and resets the work tree to it. Files the repository does not track (e.g. .env, data of bind mounts) are kept. It returns the commits before and after.

func ValidateRef

func ValidateRef(ref string) error

ValidateRef checks a branch or tag name.

func ValidateURL

func ValidateURL(raw string, allowFile bool) error

ValidateURL accepts https, http, ssh and scp-like (git@host:owner/repo.git) URLs.

Types

type Commit

type Commit struct {
	Hash    string    `json:"hash"`
	Message string    `json:"message"`
	Author  string    `json:"author"`
	Date    time.Time `json:"date"`
}

Commit describes a checked-out commit. Keep in sync with api/openapi.yaml.

func Clone

func Clone(ctx context.Context, dir string, o Options) (Commit, string, error)

Clone clones the ref of a repository into dir (which must not exist) with depth 1. It returns the commit and the full ref name (refs/heads/... or refs/tags/...).

func Head(dir string) (Commit, error)

Head returns the checked-out commit of a clone.

type Credential

type Credential struct {
	Kind     string
	Username string
	// Secret is the token or password, or the PEM private key.
	Secret     string
	Passphrase string
}

Credential authenticates to a Git server.

type KnownHosts

type KnownHosts interface {
	HostKeys(ctx context.Context, host string) ([]string, error)
	AddHostKey(ctx context.Context, host, key string) error
}

KnownHosts remembers SSH host keys: the first key seen for a host is trusted, later connections must present the same key (trust on first use).

type Options

type Options struct {
	URL string
	// Ref is a branch or tag name, or a full ref (refs/heads/..., refs/tags/...); empty means
	// the default branch.
	Ref        string
	Credential *Credential
	KnownHosts KnownHosts
	// AllowFile permits file:// and local paths (tests).
	AllowFile bool
}

Options select a repository and a ref.

Jump to

Keyboard shortcuts

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