git-bug: github.com/MichaelMure/git-bug/repository Index | Files

package repository

import "github.com/MichaelMure/git-bug/repository"

Package repository contains helper methods for working with the Git repo.

Package repository contains helper methods for working with a Git repo.

Index

Package Files

config.go config_mem.go config_testing.go git.go git_cli.go git_config.go git_testing.go gogit.go gogit_config.go gogit_testing.go hash.go keyring.go mock_repo.go repo.go repo_testing.go tree_entry.go

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 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")
)
var ErrKeyringKeyNotFound = keyring.ErrKeyNotFound

func CleanupTestRepos Uses

func CleanupTestRepos(repos ...Repo)

func NewMockRepoClock Uses

func NewMockRepoClock() *mockRepoClock

func NewMockRepoCommon Uses

func NewMockRepoCommon() *mockRepoCommon

func NewMockRepoConfig Uses

func NewMockRepoConfig() *mockRepoConfig

func NewMockRepoData Uses

func NewMockRepoData() *mockRepoData

func NewMockRepoForTest Uses

func NewMockRepoForTest() *mockRepoForTest

func NewMockRepoKeyring Uses

func NewMockRepoKeyring() *mockRepoKeyring

func ParseTimestamp Uses

func ParseTimestamp(s string) (time.Time, error)

func RepoClockTest Uses

func RepoClockTest(t *testing.T, repo RepoClock)

helper to test a RepoClock

func RepoConfigTest Uses

func RepoConfigTest(t *testing.T, repo RepoConfig)

helper to test a RepoConfig

func RepoDataTest Uses

func RepoDataTest(t *testing.T, repo RepoData)

helper to test a RepoData

func RepoTest Uses

func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner)

Test suite for a Repo implementation

type ClockLoader Uses

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 Uses

type ClockedRepo interface {
    Repo
    RepoClock
}

ClockedRepo is a Repo that also has Lamport clocks

type Config Uses

type Config interface {
    ConfigRead
    ConfigWrite
}

Config represent the common function interacting with the repository config storage

type ConfigRead Uses

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 Uses

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 GitRepo Uses

type GitRepo struct {
    // contains filtered or unexported fields
}

GitRepo represents an instance of a (local) git repository.

func InitBareGitRepo Uses

func InitBareGitRepo(path string) (*GitRepo, error)

InitBareGitRepo create a new --bare empty git repo at the given path

func InitGitRepo Uses

func InitGitRepo(path string) (*GitRepo, error)

InitGitRepo create a new empty git repo at the given path

func NewGitRepo Uses

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 (*GitRepo) AddRemote Uses

func (repo *GitRepo) AddRemote(name string, url string) error

AddRemote add a new remote to the repository Not in the interface because it's only used for testing

func (*GitRepo) AnyConfig Uses

func (repo *GitRepo) AnyConfig() ConfigRead

AnyConfig give access to a merged local/global configuration

func (*GitRepo) CopyRef Uses

func (repo *GitRepo) CopyRef(source string, dest string) error

CopyRef will create a new reference with the same value as another one

func (*GitRepo) FetchRefs Uses

func (repo *GitRepo) FetchRefs(remote, refSpec string) (string, error)

FetchRefs fetch git refs from a remote

func (*GitRepo) FindCommonAncestor Uses

func (repo *GitRepo) FindCommonAncestor(hash1 Hash, hash2 Hash) (Hash, error)

FindCommonAncestor will return the last common ancestor of two chain of commit

func (*GitRepo) GetCoreEditor Uses

func (repo *GitRepo) GetCoreEditor() (string, error)

GetCoreEditor returns the name of the editor that the user has used to configure git.

func (*GitRepo) GetOrCreateClock Uses

func (repo *GitRepo) GetOrCreateClock(name string) (lamport.Clock, error)

GetOrCreateClock return a Lamport clock stored in the Repo. If the clock doesn't exist, it's created.

func (*GitRepo) GetPath Uses

func (repo *GitRepo) GetPath() string

GetPath returns the path to the repo.

func (*GitRepo) GetRemotes Uses

func (repo *GitRepo) GetRemotes() (map[string]string, error)

GetRemotes returns the configured remotes repositories.

func (*GitRepo) GetTreeHash Uses

func (repo *GitRepo) GetTreeHash(commit Hash) (Hash, error)

GetTreeHash return the git tree hash referenced in a commit

func (*GitRepo) GetUserEmail Uses

func (repo *GitRepo) GetUserEmail() (string, error)

GetUserEmail returns the email address that the user has used to configure git.

func (*GitRepo) GetUserName Uses

func (repo *GitRepo) GetUserName() (string, error)

GetUserName returns the name the the user has used to configure git

func (*GitRepo) GlobalConfig Uses

func (repo *GitRepo) GlobalConfig() Config

GlobalConfig give access to the global scoped configuration

func (*GitRepo) Keyring Uses

func (repo *GitRepo) Keyring() Keyring

Keyring give access to a user-wide storage for secrets

func (*GitRepo) ListCommits Uses

func (repo *GitRepo) ListCommits(ref string) ([]Hash, error)

ListCommits will return the list of commit hashes of a ref, in chronological order

func (*GitRepo) ListRefs Uses

func (repo *GitRepo) ListRefs(refPrefix string) ([]string, error)

ListRefs will return a list of Git ref matching the given refspec

func (*GitRepo) LocalConfig Uses

func (repo *GitRepo) LocalConfig() Config

LocalConfig give access to the repository scoped configuration

func (*GitRepo) PushRefs Uses

func (repo *GitRepo) PushRefs(remote string, refSpec string) (string, error)

PushRefs push git refs to a remote

func (*GitRepo) ReadData Uses

func (repo *GitRepo) ReadData(hash Hash) ([]byte, error)

ReadData will attempt to read arbitrary data from the given hash

func (*GitRepo) ReadTree Uses

func (repo *GitRepo) ReadTree(hash Hash) ([]TreeEntry, error)

ReadTree will return the list of entries in a Git tree

func (*GitRepo) RefExist Uses

func (repo *GitRepo) RefExist(ref string) (bool, error)

RefExist will check if a reference exist in Git

func (*GitRepo) RemoveRef Uses

func (repo *GitRepo) RemoveRef(ref string) error

RemoveRef will remove a Git reference

func (*GitRepo) StoreCommit Uses

func (repo *GitRepo) StoreCommit(treeHash Hash) (Hash, error)

StoreCommit will store a Git commit with the given Git tree

func (*GitRepo) StoreCommitWithParent Uses

func (repo *GitRepo) StoreCommitWithParent(treeHash Hash, parent Hash) (Hash, error)

StoreCommitWithParent will store a Git commit with the given Git tree

func (*GitRepo) StoreData Uses

func (repo *GitRepo) StoreData(data []byte) (Hash, error)

StoreData will store arbitrary data and return the corresponding hash

func (*GitRepo) StoreTree Uses

func (repo *GitRepo) StoreTree(entries []TreeEntry) (Hash, error)

StoreTree will store a mapping key-->Hash as a Git tree

func (*GitRepo) UpdateRef Uses

func (repo *GitRepo) UpdateRef(ref string, hash Hash) error

UpdateRef will create or update a Git reference

type GoGitRepo Uses

type GoGitRepo struct {
    // contains filtered or unexported fields
}

func InitBareGoGitRepo Uses

func InitBareGoGitRepo(path string) (*GoGitRepo, error)

InitBareGoGitRepo create a new --bare empty git repo at the given path

func InitGoGitRepo Uses

func InitGoGitRepo(path string) (*GoGitRepo, error)

InitGoGitRepo create a new empty git repo at the given path

func NewGoGitRepo Uses

func NewGoGitRepo(path string, clockLoaders []ClockLoader) (*GoGitRepo, error)

func (*GoGitRepo) AddRemote Uses

func (repo *GoGitRepo) AddRemote(name string, url string) error

AddRemote add a new remote to the repository Not in the interface because it's only used for testing

func (*GoGitRepo) AnyConfig Uses

func (repo *GoGitRepo) AnyConfig() ConfigRead

AnyConfig give access to a merged local/global configuration

func (*GoGitRepo) CopyRef Uses

func (repo *GoGitRepo) CopyRef(source string, dest string) error

CopyRef will create a new reference with the same value as another one

func (*GoGitRepo) FetchRefs Uses

func (repo *GoGitRepo) FetchRefs(remote string, refSpec string) (string, error)

FetchRefs fetch git refs from a remote

func (*GoGitRepo) FindCommonAncestor Uses

func (repo *GoGitRepo) FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, error)

FindCommonAncestor will return the last common ancestor of two chain of commit

func (*GoGitRepo) GetCoreEditor Uses

func (repo *GoGitRepo) GetCoreEditor() (string, error)

GetCoreEditor returns the name of the editor that the user has used to configure git.

func (*GoGitRepo) GetOrCreateClock Uses

func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error)

GetOrCreateClock return a Lamport clock stored in the Repo. If the clock doesn't exist, it's created.

func (*GoGitRepo) GetPath Uses

func (repo *GoGitRepo) GetPath() string

GetPath returns the path to the repo.

func (*GoGitRepo) GetRemotes Uses

func (repo *GoGitRepo) GetRemotes() (map[string]string, error)

GetRemotes returns the configured remotes repositories.

func (*GoGitRepo) GetTreeHash Uses

func (repo *GoGitRepo) GetTreeHash(commit Hash) (Hash, error)

GetTreeHash return the git tree hash referenced in a commit

func (*GoGitRepo) GetUserEmail Uses

func (repo *GoGitRepo) GetUserEmail() (string, error)

GetUserEmail returns the email address that the user has used to configure git.

func (*GoGitRepo) GetUserName Uses

func (repo *GoGitRepo) GetUserName() (string, error)

GetUserName returns the name the the user has used to configure git

func (*GoGitRepo) GlobalConfig Uses

func (repo *GoGitRepo) GlobalConfig() Config

GlobalConfig give access to the global scoped configuration

func (*GoGitRepo) Keyring Uses

func (repo *GoGitRepo) Keyring() Keyring

Keyring give access to a user-wide storage for secrets

func (*GoGitRepo) ListCommits Uses

func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error)

ListCommits will return the list of tree hashes of a ref, in chronological order

func (*GoGitRepo) ListRefs Uses

func (repo *GoGitRepo) ListRefs(refPrefix string) ([]string, error)

ListRefs will return a list of Git ref matching the given refspec

func (*GoGitRepo) LocalConfig Uses

func (repo *GoGitRepo) LocalConfig() Config

LocalConfig give access to the repository scoped configuration

func (*GoGitRepo) PushRefs Uses

func (repo *GoGitRepo) PushRefs(remote string, refSpec string) (string, error)

PushRefs push git refs to a remote

func (*GoGitRepo) ReadData Uses

func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error)

ReadData will attempt to read arbitrary data from the given hash

func (*GoGitRepo) ReadTree Uses

func (repo *GoGitRepo) ReadTree(hash Hash) ([]TreeEntry, error)

ReadTree will return the list of entries in a Git tree

func (*GoGitRepo) RefExist Uses

func (repo *GoGitRepo) RefExist(ref string) (bool, error)

RefExist will check if a reference exist in Git

func (*GoGitRepo) RemoveRef Uses

func (repo *GoGitRepo) RemoveRef(ref string) error

RemoveRef will remove a Git reference

func (*GoGitRepo) StoreCommit Uses

func (repo *GoGitRepo) StoreCommit(treeHash Hash) (Hash, error)

StoreCommit will store a Git commit with the given Git tree

func (*GoGitRepo) StoreCommitWithParent Uses

func (repo *GoGitRepo) StoreCommitWithParent(treeHash Hash, parent Hash) (Hash, error)

StoreCommit will store a Git commit with the given Git tree

func (*GoGitRepo) StoreData Uses

func (repo *GoGitRepo) StoreData(data []byte) (Hash, error)

StoreData will store arbitrary data and return the corresponding hash

func (*GoGitRepo) StoreTree Uses

func (repo *GoGitRepo) StoreTree(mapping []TreeEntry) (Hash, error)

StoreTree will store a mapping key-->Hash as a Git tree

func (*GoGitRepo) UpdateRef Uses

func (repo *GoGitRepo) UpdateRef(ref string, hash Hash) error

UpdateRef will create or update a Git reference

type Hash Uses

type Hash string

Hash is a git hash

func (*Hash) IsValid Uses

func (h *Hash) IsValid() bool

IsValid tell if the hash is valid

func (Hash) MarshalGQL Uses

func (h Hash) MarshalGQL(w io.Writer)

MarshalGQL implement the Marshaler interface for gqlgen

func (Hash) String Uses

func (h Hash) String() string

func (*Hash) UnmarshalGQL Uses

func (h *Hash) UnmarshalGQL(v interface{}) error

UnmarshalGQL implement the Unmarshaler interface for gqlgen

type Item Uses

type Item = keyring.Item

type Keyring Uses

type Keyring interface {
    // Returns an Item matching the key or ErrKeyringKeyNotFound
    Get(key string) (Item, error)
    // Stores an Item on the keyring
    Set(item Item) error
    // Removes the item with matching key
    Remove(key string) error
    // Provides a slice of all keys stored on the keyring
    Keys() ([]string, error)
}

Keyring provides the uniform interface over the underlying backends

type MemConfig Uses

type MemConfig struct {
    // contains filtered or unexported fields
}

func NewMemConfig Uses

func NewMemConfig() *MemConfig

func (*MemConfig) ReadAll Uses

func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error)

func (*MemConfig) ReadBool Uses

func (mc *MemConfig) ReadBool(key string) (bool, error)

func (*MemConfig) ReadString Uses

func (mc *MemConfig) ReadString(key string) (string, error)

func (*MemConfig) ReadTimestamp Uses

func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error)

func (*MemConfig) RemoveAll Uses

func (mc *MemConfig) RemoveAll(keyPrefix string) error

RmConfigs remove all key/value pair matching the key prefix

func (*MemConfig) StoreBool Uses

func (mc *MemConfig) StoreBool(key string, value bool) error

func (*MemConfig) StoreString Uses

func (mc *MemConfig) StoreString(key, value string) error

func (*MemConfig) StoreTimestamp Uses

func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error

type ObjectType Uses

type ObjectType int
const (
    Unknown ObjectType = iota
    Blob
    Tree
)

func ParseObjectType Uses

func ParseObjectType(mode, objType string) (ObjectType, error)

func (ObjectType) Format Uses

func (ot ObjectType) Format() string

type Repo Uses

type Repo interface {
    RepoConfig
    RepoKeyring
    RepoCommon
    RepoData
}

Repo represents a source code repository.

type RepoCleaner Uses

type RepoCleaner func(repos ...Repo)

type RepoClock Uses

type RepoClock interface {
    // GetOrCreateClock return a Lamport clock stored in the Repo.
    // If the clock doesn't exist, it's created.
    GetOrCreateClock(name string) (lamport.Clock, error)
}

RepoClock give access to Lamport clocks

type RepoCommon Uses

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 Uses

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 Uses

type RepoCreator func(bare bool) TestedRepo

type RepoData Uses

type RepoData interface {
    // FetchRefs fetch git refs from a remote
    FetchRefs(remote string, refSpec string) (string, error)

    // PushRefs push git refs to a remote
    PushRefs(remote string, refSpec 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) (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(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

    // 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 Uses

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 TestedRepo Uses

type TestedRepo interface {
    ClockedRepo
    // contains filtered or unexported methods
}

TestedRepo is an extended ClockedRepo with function for testing only

func CreateGoGitTestRepo Uses

func CreateGoGitTestRepo(bare bool) TestedRepo

func CreateTestRepo Uses

func CreateTestRepo(bare bool) TestedRepo

func SetupGoGitReposAndRemote Uses

func SetupGoGitReposAndRemote() (repoA, repoB, remote TestedRepo)

func SetupReposAndRemote Uses

func SetupReposAndRemote() (repoA, repoB, remote TestedRepo)

type TreeEntry Uses

type TreeEntry struct {
    ObjectType ObjectType
    Hash       Hash
    Name       string
}

func ParseTreeEntry Uses

func ParseTreeEntry(line string) (TreeEntry, error)

func (TreeEntry) Format Uses

func (entry TreeEntry) Format() string

Format the entry as a git ls-tree compatible line

Package repository imports 28 packages (graph) and is imported by 26 packages. Updated 2020-10-01. Refresh now. Tools for package owners.