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
- Variables
- func IsSSH(raw string) bool
- func RemoteHead(ctx context.Context, fullRef string, o Options) (string, error)
- func Update(ctx context.Context, dir, fullRef string, o Options) (Commit, Commit, error)
- func ValidateRef(ref string) error
- func ValidateURL(raw string, allowFile bool) error
- type Commit
- type Credential
- type KnownHosts
- type Options
Constants ¶
const ( KindToken = "token" // HTTPS with a username and an access token or password KindSSH = "ssh" // SSH with a private key )
Credential kinds.
Variables ¶
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 RemoteHead ¶
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 ¶
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 ValidateURL ¶
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.
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.