vcs fetcher and cloner for Go.
A Go library for fetching files from version control systems (vcs).
Easily retrieve individual files or repositories over a vcs location.
- Support
gitrepositories - Support SPDX Locators (spdx downloadLocation attribute)
- Support common
git-urlschemes
All fetched resources are exposed for read-only operations only.
If you're looking for general purpose vcs support in Go for read/write or other git-heavy operations,
consider using github.com/go-git/go-git instead.
Work in progress. Unreleased.
- retrieve a single file over a remote repo (e.g. config file)
- retrieve an entire folder at a specific version
- ...
Not intended to work with local resources (e.g. file://...).
VCS (Version Control System)
- Works without git installed
- Supported schemes: http, https, ssh, git TCP
- Authentication (basic, ssh)
-
Fetch(single file) orClone(folder or entire repo) -
Fetchoptimized for common SCMs (github.com, gitlab), with https raw content download to bypass pure-git operations - In memory or filesystem-backed
- Supports sparse-cloning
- Auto-detects the presence of the
gitbinary for faster fetching using thegitcommand line
Resolving versions
- Ref as commit sha, branch or tag, with exact match
- Semver tag resolution with incomplete semver: e.g. resolve
v2as the latest tag<v3, and2.1as the latest tag<v2.2
SCM-specific URLs
-
git-urlparses resource locators for well-known schemes- azure
- bitbucket
- gitea
- github
- gitlab
- know how to transform a resource locator into a raw-content URL
go get github.com/fredbi/go-vcsfetchimport (
"bytes"
"context"
"log"
"github.com/fredbi/go-vcsfetch"
)
...
vf := vcsfetch.NewFetcher()
w := new(bytes.Buffer)
ctx := context.Background()
const spdxDownloadLocation = "https://github.com/fredbi/go-vcsfetch@HEAD#.golangci.yml"
if err := vf.Fetch(ctx, w, spdxDownloadLocation); err != nil {
...
}
log.Println(w.String())Example use cases:
- authentication
- git over TCP
- repo cloning
- git-urls
- folder retrieval and repeated fetches
- exact vs semver tag resolution
- using shorthand slugs
- git-archive (with benchmark)
- TLS settings
This library is built on top of github.com/go-git/go-git, a pure Go git implementation.
It does not require runtime dependencies (e.g. like when using go-git bindings from git2go).
It does not require the git binary to be installed.
However, when the git binary is present and auto-detection is not disabled, the library may chose to perform
some operations using the native git implementation, which is usually faster than the native go port.
TODO
- Support for
git-archivedownload, when well-known SCM will start support this protocol - Support for mercurial, with a runtime dependency on
hg. - native go git-archive support (or from go-git/v6?)
- support semver version constraint such as
^v1.2.3or~v1.2.3 - mock git server
This library is distributed under the Apache 2.0 license.
SPDX-FileCopyrightText: Copyright 2025 Frédéric BIDON
SPDX-License-Identifier: Apache-2.0
Initially, my intent was to enable a shared golangci-lint config file on a repository common to all repos within an organization.
Doing a little research on how to work with vcs resources in Go, I stumbled over this little package github.com/carabiner-dev/vcslocator.
I started to use it right away, but was quickly hindered by a number of limitations. My requirements departed quite a bit from that implementation, to the point that forking wasn't an option. And so started this implementation.
Thank you to the guys at carabiner-dev, who provided me the inspiration
to use a SPDX locator on top of go-git.
Notice that this implementation is 100% original code and not a plagiarism of the above.