Documentation ¶
Overview ¶
Package repository contains helper methods for working with a Git repo.
Index ¶
- Variables
- func NewMockRepo() *mockRepo
- func NewMockRepoClock() *mockRepoClock
- func NewMockRepoCommon() *mockRepoCommon
- func NewMockRepoConfig() *mockRepoConfig
- func NewMockRepoData() *mockRepoData
- func NewMockRepoKeyring() *mockRepoKeyring
- func NewMockRepoStorage() *mockRepoStorage
- func NewMockRepoTest() *mockRepoTest
- func ParseTimestamp(s string) (time.Time, error)
- func RepoClockTest(t *testing.T, repo RepoClock)
- func RepoConfigTest(t *testing.T, repo RepoConfig)
- func RepoDataSignatureTest(t *testing.T, repo RepoData)
- func RepoDataTest(t *testing.T, repo RepoData)
- func RepoTest(t *testing.T, creator RepoCreator)
- type ClockLoader
- type ClockedRepo
- type Commit
- type Config
- type ConfigRead
- type ConfigWrite
- type GoGitRepo
- func (repo *GoGitRepo) AddRemote(name string, url string) error
- func (repo *GoGitRepo) AllClocks() (map[string]lamport.Clock, error)
- func (repo *GoGitRepo) AnyConfig() ConfigRead
- func (repo *GoGitRepo) ClearBleveIndex(name string) error
- func (repo *GoGitRepo) Close() error
- func (repo *GoGitRepo) CopyRef(source string, dest string) error
- func (repo *GoGitRepo) EraseFromDisk() error
- func (repo *GoGitRepo) FetchRefs(remote string, prefix string) (string, error)
- func (repo *GoGitRepo) FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, error)
- func (repo *GoGitRepo) GetBleveIndex(name string) (bleve.Index, error)
- func (repo *GoGitRepo) GetCoreEditor() (string, error)
- func (repo *GoGitRepo) GetLocalRemote() string
- func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error)
- func (repo *GoGitRepo) GetRemotes() (map[string]string, error)
- func (repo *GoGitRepo) GetTreeHash(commit Hash) (Hash, error)
- func (repo *GoGitRepo) GetUserEmail() (string, error)
- func (repo *GoGitRepo) GetUserName() (string, error)
- func (repo *GoGitRepo) GlobalConfig() Config
- func (repo *GoGitRepo) Increment(name string) (lamport.Time, error)
- func (repo *GoGitRepo) Keyring() Keyring
- func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error)
- func (repo *GoGitRepo) ListRefs(refPrefix string) ([]string, error)
- func (repo *GoGitRepo) LocalConfig() Config
- func (repo *GoGitRepo) LocalStorage() billy.Filesystem
- func (repo *GoGitRepo) PushRefs(remote string, prefix string) (string, error)
- func (repo *GoGitRepo) ReadCommit(hash Hash) (Commit, error)
- func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error)
- func (repo *GoGitRepo) ReadTree(hash Hash) ([]TreeEntry, error)
- func (repo *GoGitRepo) RefExist(ref string) (bool, error)
- func (repo *GoGitRepo) RemoveRef(ref string) error
- func (repo *GoGitRepo) ResolveRef(ref string) (Hash, error)
- func (repo *GoGitRepo) StoreCommit(treeHash Hash, parents ...Hash) (Hash, error)
- func (repo *GoGitRepo) StoreData(data []byte) (Hash, error)
- func (repo *GoGitRepo) StoreSignedCommit(treeHash Hash, signKey *openpgp.Entity, parents ...Hash) (Hash, error)
- func (repo *GoGitRepo) StoreTree(mapping []TreeEntry) (Hash, error)
- func (repo *GoGitRepo) UpdateRef(ref string, hash Hash) error
- func (repo *GoGitRepo) Witness(name string, time lamport.Time) error
- type Hash
- type Item
- type Keyring
- type MemConfig
- func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error)
- func (mc *MemConfig) ReadBool(key string) (bool, error)
- func (mc *MemConfig) ReadString(key string) (string, error)
- func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error)
- func (mc *MemConfig) RemoveAll(keyPrefix string) error
- func (mc *MemConfig) StoreBool(key string, value bool) error
- func (mc *MemConfig) StoreString(key, value string) error
- func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error
- type ObjectType
- type Repo
- type RepoBleve
- type RepoClock
- type RepoCommon
- type RepoCommonStorage
- type RepoConfig
- type RepoCreator
- type RepoData
- type RepoKeyring
- type RepoStorage
- type TestedRepo
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoConfigEntry = errors.New("no config entry for the given key") ErrMultipleConfigEntry = errors.New("multiple config entry for the given key") )
var ( // ErrNotARepo is the error returned when the git repo root can't be found ErrNotARepo = errors.New("not a git repository") // ErrClockNotExist is the error returned when a clock can't be found ErrClockNotExist = errors.New("clock doesn't exist") )
var ErrKeyringKeyNotFound = keyring.ErrKeyNotFound
Functions ¶
func NewMockRepo ¶ added in v0.8.0
func NewMockRepo() *mockRepo
func NewMockRepoClock ¶ added in v0.8.0
func NewMockRepoClock() *mockRepoClock
func NewMockRepoCommon ¶ added in v0.8.0
func NewMockRepoCommon() *mockRepoCommon
func NewMockRepoConfig ¶ added in v0.8.0
func NewMockRepoConfig() *mockRepoConfig
func NewMockRepoData ¶ added in v0.8.0
func NewMockRepoData() *mockRepoData
func NewMockRepoKeyring ¶ added in v0.8.0
func NewMockRepoKeyring() *mockRepoKeyring
func NewMockRepoStorage ¶ added in v0.8.0
func NewMockRepoStorage() *mockRepoStorage
func NewMockRepoTest ¶ added in v0.8.0
func NewMockRepoTest() *mockRepoTest
func RepoClockTest ¶ added in v0.8.0
helper to test a RepoClock
func RepoConfigTest ¶ added in v0.8.0
func RepoConfigTest(t *testing.T, repo RepoConfig)
helper to test a RepoConfig
func RepoDataSignatureTest ¶ added in v0.8.0
func RepoDataTest ¶ added in v0.8.0
helper to test a RepoData
func RepoTest ¶ added in v0.8.0
func RepoTest(t *testing.T, creator RepoCreator)
Test suite for a Repo implementation
Types ¶
type ClockLoader ¶ added in v0.8.0
type ClockLoader struct { // Clocks hold the name of all the clocks this loader deal with. // Those clocks will be checked when the repo load. If not present or broken, // Witnesser will be used to create them. Clocks []string // Witnesser is a function that will initialize the clocks of a repo // from scratch Witnesser func(repo ClockedRepo) error }
ClockLoader hold which logical clock need to exist for an entity and how to create them if they don't.
type ClockedRepo ¶
ClockedRepo is a Repo that also has Lamport clocks
type Config ¶
type Config interface { ConfigRead ConfigWrite }
Config represent the common function interacting with the repository config storage
type ConfigRead ¶ added in v0.8.0
type ConfigRead interface { // ReadAll reads all key/value pair matching the key prefix ReadAll(keyPrefix string) (map[string]string, error) // ReadBool read a single boolean value from the config // Return ErrNoConfigEntry or ErrMultipleConfigEntry if // there is zero or more than one entry for this key ReadBool(key string) (bool, error) // ReadBool read a single string value from the config // Return ErrNoConfigEntry or ErrMultipleConfigEntry if // there is zero or more than one entry for this key ReadString(key string) (string, error) // ReadTimestamp read a single timestamp value from the config // Return ErrNoConfigEntry or ErrMultipleConfigEntry if // there is zero or more than one entry for this key ReadTimestamp(key string) (time.Time, error) }
type ConfigWrite ¶ added in v0.8.0
type ConfigWrite interface { // Store writes a single key/value pair in the config StoreString(key, value string) error // Store writes a key and timestamp value to the config StoreTimestamp(key string, value time.Time) error // Store writes a key and boolean value to the config StoreBool(key string, value bool) error // RemoveAll removes all key/value pair matching the key prefix RemoveAll(keyPrefix string) error }
type GoGitRepo ¶ added in v0.8.0
type GoGitRepo struct {
// contains filtered or unexported fields
}
func InitBareGoGitRepo ¶ added in v0.8.0
InitBareGoGitRepo creates a new --bare empty git repo at the given path and with the specified LocalStorage namespace. Given a repository path of "~/myrepo" and a namespace of "git-bug", local storage for the GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func InitGoGitRepo ¶ added in v0.8.0
InitGoGitRepo creates a new empty git repo at the given path and with the specified LocalStorage namespace. Given a repository path of "~/myrepo" and a namespace of "git-bug", local storage for the GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func OpenGoGitRepo ¶ added in v0.8.0
func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRepo, error)
OpenGoGitRepo opens an already existing repo at the given path and with the specified LocalStorage namespace. Given a repository path of "~/myrepo" and a namespace of "git-bug", local storage for the GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func (*GoGitRepo) AddRemote ¶ added in v0.8.0
AddRemote add a new remote to the repository Not in the interface because it's only used for testing
func (*GoGitRepo) AnyConfig ¶ added in v0.8.0
func (repo *GoGitRepo) AnyConfig() ConfigRead
AnyConfig give access to a merged local/global configuration
func (*GoGitRepo) ClearBleveIndex ¶ added in v0.8.0
ClearBleveIndex will wipe the given index
func (*GoGitRepo) CopyRef ¶ added in v0.8.0
CopyRef will create a new reference with the same value as another one
func (*GoGitRepo) EraseFromDisk ¶ added in v0.8.0
EraseFromDisk delete this repository entirely from the disk
func (*GoGitRepo) FetchRefs ¶ added in v0.8.0
FetchRefs fetch git refs matching a directory prefix to a remote Ex: prefix="foo" will fetch any remote refs matching "refs/foo/*" locally. The equivalent git refspec would be "refs/foo/*:refs/remotes/<remote>/foo/*"
func (*GoGitRepo) FindCommonAncestor ¶ added in v0.8.0
FindCommonAncestor will return the last common ancestor of two chain of commit
func (*GoGitRepo) GetBleveIndex ¶ added in v0.8.0
GetBleveIndex return a bleve.Index that can be used to index documents
func (*GoGitRepo) GetCoreEditor ¶ added in v0.8.0
GetCoreEditor returns the name of the editor that the user has used to configure git.
func (*GoGitRepo) GetLocalRemote ¶ added in v0.8.0
GetLocalRemote return the URL to use to add this repo as a local remote
func (*GoGitRepo) GetOrCreateClock ¶ added in v0.8.0
GetOrCreateClock return a Lamport clock stored in the Repo. If the clock doesn't exist, it's created.
func (*GoGitRepo) GetRemotes ¶ added in v0.8.0
GetRemotes returns the configured remotes repositories.
func (*GoGitRepo) GetTreeHash ¶ added in v0.8.0
GetTreeHash return the git tree hash referenced in a commit
func (*GoGitRepo) GetUserEmail ¶ added in v0.8.0
GetUserEmail returns the email address that the user has used to configure git.
func (*GoGitRepo) GetUserName ¶ added in v0.8.0
GetUserName returns the name the user has used to configure git
func (*GoGitRepo) GlobalConfig ¶ added in v0.8.0
GlobalConfig give access to the global scoped configuration
func (*GoGitRepo) Increment ¶ added in v0.8.0
Increment is equivalent to c = GetOrCreateClock(name) + c.Increment()
func (*GoGitRepo) ListCommits ¶ added in v0.8.0
ListCommits will return the list of tree hashes of a ref, in chronological order
func (*GoGitRepo) ListRefs ¶ added in v0.8.0
ListRefs will return a list of Git ref matching the given refspec
func (*GoGitRepo) LocalConfig ¶ added in v0.8.0
LocalConfig give access to the repository scoped configuration
func (*GoGitRepo) LocalStorage ¶ added in v0.8.0
func (repo *GoGitRepo) LocalStorage() billy.Filesystem
LocalStorage returns a billy.Filesystem giving access to $RepoPath/.git/$Namespace.
func (*GoGitRepo) PushRefs ¶ added in v0.8.0
PushRefs push git refs matching a directory prefix to a remote Ex: prefix="foo" will push any local refs matching "refs/foo/*" to the remote. The equivalent git refspec would be "refs/foo/*:refs/foo/*"
Additionally, PushRefs will update the local references in refs/remotes/<remote>/foo to match the remote state.
func (*GoGitRepo) ReadCommit ¶ added in v0.8.0
func (*GoGitRepo) ReadData ¶ added in v0.8.0
ReadData will attempt to read arbitrary data from the given hash
func (*GoGitRepo) ResolveRef ¶ added in v0.8.0
func (*GoGitRepo) StoreCommit ¶ added in v0.8.0
StoreCommit will store a Git commit with the given Git tree
func (*GoGitRepo) StoreData ¶ added in v0.8.0
StoreData will store arbitrary data and return the corresponding hash
func (*GoGitRepo) StoreSignedCommit ¶ added in v0.8.0
func (repo *GoGitRepo) StoreSignedCommit(treeHash Hash, signKey *openpgp.Entity, parents ...Hash) (Hash, error)
StoreSignedCommit will store a Git commit with the given Git tree. If signKey is not nil, the commit will be signed accordingly.
func (*GoGitRepo) StoreTree ¶ added in v0.8.0
StoreTree will store a mapping key-->Hash as a Git tree
type Hash ¶ added in v0.8.0
type Hash string
Hash is a git hash
func (Hash) MarshalGQL ¶ added in v0.8.0
MarshalGQL implement the Marshaler interface for gqlgen
func (*Hash) UnmarshalGQL ¶ added in v0.8.0
UnmarshalGQL implement the Unmarshaler interface for gqlgen
type Keyring ¶ added in v0.8.0
type Keyring interface { // Get returns an Item matching the key or ErrKeyringKeyNotFound Get(key string) (Item, error) // Set stores an Item on the keyring. Set is idempotent. Set(item Item) error // Remove removes the item with matching key Remove(key string) error // Keys provides a slice of all keys stored on the keyring Keys() ([]string, error) }
Keyring provides the uniform interface over the underlying backends
type MemConfig ¶
type MemConfig struct {
// contains filtered or unexported fields
}
func NewMemConfig ¶
func NewMemConfig() *MemConfig
func (*MemConfig) StoreString ¶
type ObjectType ¶
type ObjectType int
const ( Unknown ObjectType = iota Blob Tree )
func ParseObjectType ¶
func ParseObjectType(mode, objType string) (ObjectType, error)
func (ObjectType) Format ¶
func (ot ObjectType) Format() string
type Repo ¶
type Repo interface { RepoConfig RepoKeyring RepoCommon RepoStorage RepoBleve RepoData Close() error }
Repo represents a source code repository.
type RepoBleve ¶ added in v0.8.0
type RepoBleve interface { // GetBleveIndex return a bleve.Index that can be used to index documents GetBleveIndex(name string) (bleve.Index, error) // ClearBleveIndex will wipe the given index ClearBleveIndex(name string) error }
RepoBleve give access to Bleve to implement full-text search indexes.
type RepoClock ¶ added in v0.8.0
type RepoClock interface { // AllClocks return all the known clocks AllClocks() (map[string]lamport.Clock, error) // GetOrCreateClock return a Lamport clock stored in the Repo. // If the clock doesn't exist, it's created. GetOrCreateClock(name string) (lamport.Clock, error) // Increment is equivalent to c = GetOrCreateClock(name) + c.Increment() Increment(name string) (lamport.Time, error) // Witness is equivalent to c = GetOrCreateClock(name) + c.Witness(time) Witness(name string, time lamport.Time) error }
RepoClock give access to Lamport clocks
type RepoCommon ¶
type RepoCommon interface { // GetUserName returns the name the user has used to configure git GetUserName() (string, error) // GetUserEmail returns the email address that the user has used to configure git. GetUserEmail() (string, error) // GetCoreEditor returns the name of the editor that the user has used to configure git. GetCoreEditor() (string, error) // GetRemotes returns the configured remotes repositories. GetRemotes() (map[string]string, error) }
RepoCommon represent the common function we want all repos to implement
type RepoCommonStorage ¶ added in v0.8.0
type RepoCommonStorage interface { RepoCommon RepoStorage }
type RepoConfig ¶
type RepoConfig interface { // LocalConfig give access to the repository scoped configuration LocalConfig() Config // GlobalConfig give access to the global scoped configuration GlobalConfig() Config // AnyConfig give access to a merged local/global configuration AnyConfig() ConfigRead }
RepoConfig access the configuration of a repository
type RepoCreator ¶ added in v0.8.0
type RepoCreator func(t testing.TB, bare bool) TestedRepo
type RepoData ¶ added in v0.8.0
type RepoData interface { // FetchRefs fetch git refs matching a directory prefix to a remote // Ex: prefix="foo" will fetch any remote refs matching "refs/foo/*" locally. // The equivalent git refspec would be "refs/foo/*:refs/remotes/<remote>/foo/*" FetchRefs(remote string, prefix string) (string, error) // PushRefs push git refs matching a directory prefix to a remote // Ex: prefix="foo" will push any local refs matching "refs/foo/*" to the remote. // The equivalent git refspec would be "refs/foo/*:refs/foo/*" // // Additionally, PushRefs will update the local references in refs/remotes/<remote>/foo to match // the remote state. PushRefs(remote string, prefix string) (string, error) // StoreData will store arbitrary data and return the corresponding hash StoreData(data []byte) (Hash, error) // ReadData will attempt to read arbitrary data from the given hash ReadData(hash Hash) ([]byte, error) // StoreTree will store a mapping key-->Hash as a Git tree StoreTree(mapping []TreeEntry) (Hash, error) // ReadTree will return the list of entries in a Git tree // The given hash could be from either a commit or a tree ReadTree(hash Hash) ([]TreeEntry, error) // StoreCommit will store a Git commit with the given Git tree StoreCommit(treeHash Hash, parents ...Hash) (Hash, error) // StoreSignedCommit will store a Git commit with the given Git tree. If signKey is not nil, the commit // will be signed accordingly. StoreSignedCommit(treeHash Hash, signKey *openpgp.Entity, parents ...Hash) (Hash, error) // ReadCommit read a Git commit and returns some of its characteristic ReadCommit(hash Hash) (Commit, error) // GetTreeHash return the git tree hash referenced in a commit // Deprecated GetTreeHash(commit Hash) (Hash, error) // ResolveRef returns the hash of the target commit of the given ref ResolveRef(ref string) (Hash, error) // UpdateRef will create or update a Git reference UpdateRef(ref string, hash Hash) error // RemoveRef will remove a Git reference // RemoveRef is idempotent. RemoveRef(ref string) error // ListRefs will return a list of Git ref matching the given refspec ListRefs(refPrefix string) ([]string, error) // RefExist will check if a reference exist in Git RefExist(ref string) (bool, error) // CopyRef will create a new reference with the same value as another one CopyRef(source string, dest string) error // FindCommonAncestor will return the last common ancestor of two chain of commit // Deprecated FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, error) // ListCommits will return the list of tree hashes of a ref, in chronological order ListCommits(ref string) ([]Hash, error) }
RepoData give access to the git data storage
type RepoKeyring ¶ added in v0.8.0
type RepoKeyring interface { // Keyring give access to a user-wide storage for secrets Keyring() Keyring }
RepoKeyring give access to a user-wide storage for secrets
type RepoStorage ¶ added in v0.8.0
type RepoStorage interface {
// LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug
LocalStorage() billy.Filesystem
}
RepoStorage give access to the filesystem
type TestedRepo ¶ added in v0.8.0
type TestedRepo interface { ClockedRepo // contains filtered or unexported methods }
TestedRepo is an extended ClockedRepo with function for testing only
func CreateGoGitTestRepo ¶ added in v0.8.0
func CreateGoGitTestRepo(t testing.TB, bare bool) TestedRepo
func SetupGoGitReposAndRemote ¶ added in v0.8.0
func SetupGoGitReposAndRemote(t *testing.T) (repoA, repoB, remote TestedRepo)
type TreeEntry ¶
type TreeEntry struct { ObjectType ObjectType Hash Hash Name string }
func ParseTreeEntry ¶
func SearchTreeEntry ¶ added in v0.8.0
SearchTreeEntry search a TreeEntry by name from an array