Documentation
¶
Overview ¶
Package repository contains helper methods for working with the Git repo.
Package repository contains helper methods for working with a Git repo.
Index ¶
- Variables
- func CleanupTestRepos(repos ...Repo)
- func CreateKey(t testing.TB, email string) (keyId, armoredPub, gpgWrapper string)
- func CreatePubkey(t *testing.T) string
- func GetGiteaClient() (*gitea.Client, error)
- func GetGiteaConfig() (string, string, error)
- func GetPhabClient() (*gonduit.Conn, error)
- func GetPhabConfig() (string, string, error)
- func NewMockRepoForTest() *mockRepoForTest
- func ParseTimestamp(s string) (time.Time, error)
- func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner)
- func SetupKey(t testing.TB, repo TestedRepo, email, keyId, gpgWrapper string)
- func SetupSigningKey(t testing.TB, repo TestedRepo, email string) string
- type ClockLoader
- type ClockedRepo
- type Config
- type GitRepo
- func (repo *GitRepo) AddRemote(name string, url string) error
- func (repo *GitRepo) CommitObject(h plumbing.Hash) (*object.Commit, error)
- func (repo *GitRepo) CommitsBetween(excludeRef, mainRef string) ([]Hash, error)
- func (repo *GitRepo) CopyRef(source string, dest string) error
- func (repo *GitRepo) FetchRefs(remote string, prefixes ...string) (string, error)
- func (repo *GitRepo) FindCommonAncestor(hash1 Hash, hash2 Hash) (Hash, error)
- func (repo *GitRepo) GetCoreEditor() (string, error)
- func (repo *GitRepo) GetOrCreateClock(name string) (lamport.Clock, error)
- func (repo *GitRepo) GetPath() string
- func (repo *GitRepo) GetRemotes() (map[string]string, error)
- func (repo *GitRepo) GetTreeHash(commit Hash) (Hash, error)
- func (repo *GitRepo) GetUserEmail() (string, error)
- func (repo *GitRepo) GetUserName() (string, error)
- func (repo *GitRepo) GlobalConfig() Config
- func (repo *GitRepo) LastCommit(ref string) (Hash, error)
- func (repo *GitRepo) ListCommits(ref string) ([]Hash, error)
- func (repo *GitRepo) ListRefs(refspec string) ([]string, error)
- func (repo *GitRepo) LocalConfig() Config
- func (repo *GitRepo) PushRefs(remote string, prefixes ...string) (string, error)
- func (repo *GitRepo) PushSingleRef(remote string, ref string) (string, error)
- func (repo *GitRepo) ReadData(hash Hash) ([]byte, error)
- func (repo *GitRepo) ReadTree(hash Hash) ([]TreeEntry, error)
- func (repo *GitRepo) RefExist(ref string) (bool, error)
- func (repo *GitRepo) RemoveRef(ref string) error
- func (repo *GitRepo) ResolveRef(ref string) (Hash, error)
- func (repo *GitRepo) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error)
- func (repo *GitRepo) StoreCommit(treeHash Hash) (Hash, error)
- func (repo *GitRepo) StoreCommitWithParent(treeHash Hash, parent Hash) (Hash, error)
- func (repo *GitRepo) StoreData(data []byte) (Hash, error)
- func (repo *GitRepo) StoreTree(mapping []TreeEntry) (Hash, error)
- func (repo *GitRepo) UpdateRef(ref string, hash Hash) error
- type Hash
- 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 RepoCleaner
- type RepoCommon
- type RepoConfig
- type RepoCreator
- 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") // ErrNotARepo is the error returned when the git repo root wan'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") )
Functions ¶
func CleanupTestRepos ¶
func CleanupTestRepos(repos ...Repo)
func CreatePubkey ¶
CreatePubkey returns an armored public PGP key.
func GetGiteaClient ¶
GetGiteaClient returns the connection ready to be queried. Must be called within a git repo which has the Gitea URL and API token set in the git config.
func GetGiteaConfig ¶
GetGiteaConfig returns the Gitea URL and API token from the repository config
func GetPhabClient ¶
GetPhabClient returns the connection ready to be queried. Must be called within a git repo which has the Phabricator URL and conduit API token set in the git config.
func GetPhabConfig ¶
GetPhabConfig returns the Phabricator URL and API token from the repository config
func NewMockRepoForTest ¶
func NewMockRepoForTest() *mockRepoForTest
func RepoTest ¶
func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner)
Test suite for a Repo implementation
func SetupSigningKey ¶
func SetupSigningKey(t testing.TB, repo TestedRepo, email string) string
SetupSigningKey creates a GPG key and sets up the local config so it's used. The key id is set as "user.signingkey". For the key to be found, a `gpg` wrapper which uses only a custom keyring is created and set as "gpg.program". Finally "commit.gpgsign" is set to true so the signing takes place.
Returns the armored public key.
Types ¶
type ClockLoader ¶
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 ¶
type ClockedRepo interface {
Repo
// GetOrCreateClock return a Lamport clock stored in the Repo.
// If the clock doesn't exist, it's created.
GetOrCreateClock(name string) (lamport.Clock, error)
}
ClockedRepo is a Repo that also has Lamport clocks
type Config ¶
type Config 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
// 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)
// RemoveAll removes all key/value pair matching the key prefix
RemoveAll(keyPrefix string) error
}
Config represent the common function interacting with the repository config storage
type GitRepo ¶
type GitRepo struct {
// contains filtered or unexported fields
}
GitRepo represents an instance of a (local) git repository.
func InitBareGitRepo ¶
InitBareGitRepo create a new --bare empty git repo at the given path
func InitGitRepo ¶
InitGitRepo create a new empty git repo at the given path
func NewGitRepo ¶
func NewGitRepo(path string, clockLoaders []ClockLoader) (*GitRepo, error)
NewGitRepo determines if the given working directory is inside of a git repository, and returns the corresponding GitRepo instance if it is.
func NewGitRepoNoInit ¶
NewGitRepoNoInit returns a GitRepo instance for the given directory, does not attempt to initialise clocks if not already done
func (*GitRepo) AddRemote ¶
AddRemote add a new remote to the repository Not in the interface because it's only used for testing
func (*GitRepo) CommitObject ¶
func (*GitRepo) CommitsBetween ¶
CommitsBetween will return the commits reachable from 'mainRef' which are not reachable from 'excludeRef'
func (*GitRepo) FetchRefs ¶
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 (*GitRepo) FindCommonAncestor ¶
FindCommonAncestor will return the last common ancestor of two chain of commit
func (*GitRepo) GetCoreEditor ¶
GetCoreEditor returns the name of the editor that the user has used to configure git.
func (*GitRepo) GetOrCreateClock ¶
GetOrCreateClock return a Lamport clock stored in the Repo. If the clock doesn't exist, it's created.
func (*GitRepo) GetRemotes ¶
GetRemotes returns the configured remotes repositories.
func (*GitRepo) GetTreeHash ¶
GetTreeHash return the git tree hash referenced in a commit
func (*GitRepo) GetUserEmail ¶
GetUserEmail returns the email address that the user has used to configure git.
func (*GitRepo) GetUserName ¶
GetUserName returns the name the the user has used to configure git
func (*GitRepo) GlobalConfig ¶
GlobalConfig give access to the git global configuration
func (*GitRepo) LastCommit ¶
LastCommit will return the latest commit hash of a ref
func (*GitRepo) ListCommits ¶
ListCommits will return the list of commit hashes of a ref, in chronological order
func (*GitRepo) LocalConfig ¶
LocalConfig give access to the repository scoped configuration
func (*GitRepo) PushRefs ¶
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 (*GitRepo) PushSingleRef ¶
PushSingleRef pushes a given git ref to the remote. Ex: prefix="bugs/1234" will push any local refs matching "refs/bugs/1234" to the given remote at "refs/bugs/1234".
func (*GitRepo) ResolveRef ¶
Resolve the reference to the commit hash it represents
func (*GitRepo) ResolveRevision ¶
func (*GitRepo) StoreCommit ¶
StoreCommit will store a Git commit with the given Git tree
func (*GitRepo) StoreCommitWithParent ¶
StoreCommitWithParent will store a Git commit with the given Git tree
type Hash ¶
type Hash string
Hash is a git hash
func (Hash) MarshalGQL ¶
MarshalGQL implement the Marshaler interface for gqlgen
func (*Hash) UnmarshalGQL ¶
UnmarshalGQL implement the Unmarshaler interface for gqlgen
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
RepoCommon
// 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, prefixes ...string) (string, error)
// PushSingleRef pushes a given git ref to the remote.
// Ex: prefix="bugs/1234" will push any local refs matching "refs/bugs/1234" to the given remote at
// "refs/bugs/1234".
PushSingleRef(remote string, ref 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
ReadTree(hash Hash) ([]TreeEntry, error)
// StoreCommit will store a Git commit with the given Git tree
StoreCommit(treeHash Hash) (Hash, error)
// StoreCommit will store a Git commit with the given Git tree
StoreCommitWithParent(treeHash Hash, parent Hash) (Hash, error)
// GetTreeHash return the git tree hash referenced in a commit
GetTreeHash(commit Hash) (Hash, error)
// FindCommonAncestor will return the last common ancestor of two chain of commit
FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, error)
// UpdateRef will create or update a Git reference
UpdateRef(ref string, hash Hash) error
// RemoveRef will remove a Git reference
RemoveRef(ref string) error
// ListRefs will return a list of Git ref matching the given refspec
ListRefs(refspec 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
// Resolve the reference to the commit hash it represents
ResolveRef(ref string) (Hash, error)
// ListCommits will return the list of tree hashes of a ref, in chronological order
ListCommits(ref string) ([]Hash, error)
// CommitsBetween will return the commits reachable from 'mainRef' which are not reachable from 'excludeRef'
CommitsBetween(excludeRef, mainRef string) ([]Hash, error)
// LastCommit will return the latest commit hash of a ref
LastCommit(ref string) (Hash, error)
// CommitObject return a Commit with the given hash. If not found
// plumbing.ErrObjectNotFound is returned.
CommitObject(h plumbing.Hash) (*object.Commit, error)
// ResolveRevision resolves revision to corresponding hash. It will always
// resolve to a commit hash, not a tree or annotated tag.
//
// Implemented resolvers : HEAD, branch, tag, heads/branch, refs/heads/branch,
// refs/tags/tag, refs/remotes/origin/branch, refs/remotes/origin/HEAD, tilde and caret (HEAD~1, master~^, tag~2, ref/heads/master~1, ...), selection by text (HEAD^{/fix nasty bug})
ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error)
}
Repo represents a source code repository.
type RepoCleaner ¶
type RepoCleaner func(repos ...Repo)
type RepoCommon ¶
type RepoCommon interface {
// GetPath returns the path to the repo.
GetPath() string
// GetUserName returns the name the 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 the we want all the repo to implement
type RepoConfig ¶
type RepoConfig interface {
// LocalConfig give access to the repository scoped configuration
LocalConfig() Config
// GlobalConfig give access to the git global configuration
GlobalConfig() Config
}
RepoConfig access the configuration of a repository
type RepoCreator ¶
type RepoCreator func(bare bool) TestedRepo
type TestedRepo ¶
type TestedRepo interface {
ClockedRepo
// AddRemote add a new remote to the repository
AddRemote(name string, url string) error
// contains filtered or unexported methods
}
TestedRepo is an extended ClockedRepo with function for testing only
func CreateTestRepo ¶
func CreateTestRepo(bare bool) TestedRepo
func SetupReposAndRemote ¶
func SetupReposAndRemote() (repoA, repoB, remote TestedRepo)