Skip to content

repo

Git repository operations for Go — clone, commit, push, branch, inspect trees, and work with worktrees — over go-git, behind focused interfaces that make consumers easy to test.

go get gitlab.com/phpboyscout/go/repo
r, err := repo.NewRepo(repo.Settings{
    Forge: repo.ForgeGitHub,
    Token: repo.StaticToken(os.Getenv("GITHUB_TOKEN")),
    FS:    afero.NewOsFs(),
})

Why

  • No forge dependency. It authenticates to GitHub, GitLab, Bitbucket and Gitea while importing none of them — you pass a forge name and a token, not a forge client. No vendor SDK enters your dependency graph. See why git needs no forge.
  • Depend on the narrowest role. RepoLike is a composite of small interfaces — TreeReader, Opener, Committer, Brancher and friends. Take the one your code actually uses and mocking becomes trivial. See role interfaces.
  • In memory or on disk. The same API drives a real checkout or a purely in-memory repository — which makes tests fast and hermetic. See work in memory.
  • The worktree is an afero.Fs. Read and write a checked-out tree with ordinary afero code, live — no copy, no sync step. See read and write the worktree.
  • Lazy credentials. A token is a TokenSource, resolved only if the token path is taken — so an SSH-configured repository never triggers a keychain prompt.

Where next

Reference

The API reference is on pkg.go.dev.