Documentation
¶
Overview ¶
Package gitsource loads a catalog from a git ref: a shallow fetch into a temporary directory with the git CLI, then catalog.LoadDir on the catalog's directory in it, with the commit as the snapshot's SHA (design/workstreams/dispatcher-core/LLD/catalog.md §Loading). Head resolves a ref to its commit with git ls-remote, for catalog-sync's polling; HeadAuth does the same on a private repository with a token (Auth).
Errors never carry credentials: user info in the repository URL (a token in https://x-access-token:<token>@host/…) and an Auth token are redacted from every error message.
It is the one part of catalog loading that runs a process and touches the network, so it is kept out of the pure catalog package. It shells out to git rather than linking go-git, which isn't on the dependency allow-list.
Index ¶
- Variables
- func Head(ctx context.Context, repoURL, ref string) (string, error)
- func HeadAuth(ctx context.Context, repoURL, ref string, auth Auth) (_ string, err error)
- func IsCommit(ref string) bool
- func Load(ctx context.Context, repoURL, ref, dir string, opts catalog.Options) (_ *catalog.Catalog, _ []catalog.Error, err error)
- func RedactURL(repoURL string) string
- type Auth
Constants ¶
This section is empty.
Variables ¶
var ErrGit = errors.New("git")
ErrGit is wrapped by every failure to fetch the ref (git missing, network, unknown ref).
Functions ¶
func Head ¶
Head returns the commit ref points to in repoURL, with git ls-remote (no clone). A ref that is already a full commit SHA is returned as is. A branch wins over a tag of the same name, and an annotated tag resolves to its commit. Errors wrap ErrGit (or the context's error) and carry no credentials.
func HeadAuth ¶
HeadAuth is Head on a repository that needs a credential: auth's token goes to git as an Authorization header scoped to repoURL (Auth.config), so the URL must be http(s) and carry no user info. A zero Auth is Head. The token never appears in an error.
func IsCommit ¶
IsCommit reports whether ref is a full commit SHA, which Head returns as is (no git, no credential needed).
func Load ¶
func Load(ctx context.Context, repoURL, ref, dir string, opts catalog.Options) (_ *catalog.Catalog, _ []catalog.Error, err error)
Load fetches ref (a branch, tag or commit) of repoURL at depth 1 into a temporary directory, loads the catalog in its subdirectory dir ("catalog"; "" or "." for the repo root) and removes the checkout. The snapshot's SHA is the fetched commit. The []Error is LoadDir's; err is set only when the ref couldn't be fetched (wrapping ErrGit) or dir doesn't exist.