repository

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoConfigEntry       = errors.New("no config entry for the given key")
	ErrMultipleConfigEntry = errors.New("multiple config entry for the given key")
)
View Source
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")
	// ErrNotFound is the error returned when a git object can't be found
	ErrNotFound = errors.New("ref not found")
	// ErrRefChanged is the error returned when a ref doesn't have the expected value anymore
	ErrRefChanged = errors.New("ref changed")
)
View Source
var ErrKeyringKeyNotFound = keyring.ErrKeyNotFound

Functions

func GetDefaultString added in v0.11.0

func GetDefaultString(key string, cfg ConfigRead, def string) (string, error)

func NewMockRepo

func NewMockRepo() *mockRepo

func NewMockRepoClock

func NewMockRepoClock() *mockRepoClock

func NewMockRepoCommon

func NewMockRepoCommon() *mockRepoCommon

func NewMockRepoConfig

func NewMockRepoConfig() *mockRepoConfig

func NewMockRepoKeyring

func NewMockRepoKeyring() *mockRepoKeyring

func NewMockRepoStorage

func NewMockRepoStorage() *mockRepoStorage

func NewMockRepoTest

func NewMockRepoTest() *mockRepoTest

func ParseTimestamp

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

func RepoBrowseTest added in v0.11.0

func RepoBrowseTest(t *testing.T, repo browsable)

RepoBrowseTest exercises the RepoBrowse interface against any implementation.

Commit graph (oldest → newest):

c1 ── c2 ── c3   refs/heads/main (default)
       └────────  refs/heads/feature
c1 ←── refs/tags/v1.0

func RepoClockTest

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

helper to test a RepoClock

func RepoConfigTest

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

helper to test a RepoConfig

func RepoDataSignatureTest

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

func RepoDataTest

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

helper to test a RepoData

func RepoDataUpdateRefTest added in v0.11.0

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

RepoDataUpdateRefTest checks that UpdateRef only moves a ref from its expected value.

func RepoIndexTest

func RepoIndexTest(t *testing.T, repo RepoIndex)

func RepoStorageTest

func RepoStorageTest(t *testing.T, repo RepoStorage)

func RepoTest

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

Test suite for a Repo implementation

Types

type BranchInfo added in v0.11.0

type BranchInfo struct {
	Name string
	Hash Hash // commit hash
}

BranchInfo describes a local branch returned by RepoBrowse.Branches.

type ChangeStatus added in v0.11.0

type ChangeStatus string

ChangeStatus describes how a file was affected by a commit.

const (
	ChangeStatusAdded    ChangeStatus = "added"
	ChangeStatusModified ChangeStatus = "modified"
	ChangeStatusDeleted  ChangeStatus = "deleted"
	ChangeStatusRenamed  ChangeStatus = "renamed"
)

func (ChangeStatus) MarshalGQL added in v0.11.0

func (s ChangeStatus) MarshalGQL(w io.Writer)

func (*ChangeStatus) UnmarshalGQL added in v0.11.0

func (s *ChangeStatus) UnmarshalGQL(v any) error

type ChangedFile added in v0.11.0

type ChangedFile struct {
	Path    string
	OldPath *string // non-nil for renames
	Status  ChangeStatus
}

ChangedFile describes a file that was modified in a commit.

type ClockLoader

type ClockLoader struct {
	// Clocks hold the name of all the clocks this loader deals with.
	// Those clocks will be checked when the repo loads. 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
	RepoClock
}

ClockedRepo is a Repo that also has Lamport clocks

type Commit

type Commit struct {
	Hash       Hash
	Parents    []Hash    // hashes of the parents, if any
	TreeHash   Hash      // hash of the git Tree
	SignedData io.Reader // if signed, reader for the signed data (likely, the serialized commit)
	Signature  io.Reader // if signed, reader for the (non-armored) signature
}

type CommitDetail added in v0.11.0

type CommitDetail struct {
	CommitMeta
	FullMessage string
	Files       []ChangedFile
}

CommitDetail extends CommitMeta with the full message and the list of changed files (relative to the first parent).

type CommitMeta added in v0.11.0

type CommitMeta struct {
	Hash        Hash
	Message     string
	AuthorName  string
	AuthorEmail string
	Date        time.Time
	Parents     []Hash
}

CommitMeta holds the metadata for a single commit, suitable for listing.

type Config

type Config interface {
	ConfigRead
	ConfigWrite
}

Config represent the common function interacting with the repository config storage

type ConfigRead

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)

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

type ConfigWrite interface {
	// StoreString writes a single string key/value pair in the config
	StoreString(key, value string) error

	// StoreTimestamp writes a key and timestamp value to the config
	StoreTimestamp(key string, value time.Time) error

	// StoreBool 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 DiffHunk added in v0.11.0

type DiffHunk struct {
	OldStart int
	OldLines int
	NewStart int
	NewLines int
	Lines    []DiffLine
}

DiffHunk is a contiguous block of changes in a unified diff.

type DiffLine added in v0.11.0

type DiffLine struct {
	Type    DiffLineType
	Content string
	OldLine int
	NewLine int
}

DiffLine represents one line in a unified diff hunk.

type DiffLineType added in v0.11.0

type DiffLineType string

DiffLineType is the role of a line within a unified diff hunk.

const (
	DiffLineContext DiffLineType = "context"
	DiffLineAdded   DiffLineType = "added"
	DiffLineDeleted DiffLineType = "deleted"
)

func (DiffLineType) MarshalGQL added in v0.11.0

func (t DiffLineType) MarshalGQL(w io.Writer)

func (*DiffLineType) UnmarshalGQL added in v0.11.0

func (t *DiffLineType) UnmarshalGQL(v any) error

type FileDiff added in v0.11.0

type FileDiff struct {
	Path     string
	OldPath  *string // non-nil for renames
	IsBinary bool
	IsNew    bool
	IsDelete bool
	Hunks    []DiffHunk
}

FileDiff is the diff for a single file in a commit.

type GitRefType added in v0.11.0

type GitRefType string

GitRefType is the kind of git reference: a branch, a tag, or a detached commit.

const (
	// GitRefTypeBranch refers to a local branch (refs/heads/*).
	GitRefTypeBranch GitRefType = "BRANCH"
	// GitRefTypeTag refers to an annotated or lightweight tag (refs/tags/*).
	GitRefTypeTag GitRefType = "TAG"
	// GitRefTypeCommit represents a detached HEAD pointing directly at a commit.
	GitRefTypeCommit GitRefType = "COMMIT"
)

func (GitRefType) IsValid added in v0.11.0

func (e GitRefType) IsValid() bool

func (GitRefType) MarshalGQL added in v0.11.0

func (e GitRefType) MarshalGQL(w io.Writer)

func (GitRefType) MarshalJSON added in v0.11.0

func (e GitRefType) MarshalJSON() ([]byte, error)

func (GitRefType) String added in v0.11.0

func (e GitRefType) String() string

func (*GitRefType) UnmarshalGQL added in v0.11.0

func (e *GitRefType) UnmarshalGQL(v any) error

func (*GitRefType) UnmarshalJSON added in v0.11.0

func (e *GitRefType) UnmarshalJSON(b []byte) error

type GoGitRepo

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

func InitBareGoGitRepo

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

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

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

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

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

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) AllClocks

func (repo *GoGitRepo) AllClocks() (map[string]lamport.Clock, error)

func (*GoGitRepo) AnyConfig

func (repo *GoGitRepo) AnyConfig() ConfigRead

AnyConfig give access to a merged local/global configuration

func (*GoGitRepo) BlobAtPath added in v0.11.0

func (repo *GoGitRepo) BlobAtPath(ref, path string) (io.ReadCloser, int64, Hash, error)

BlobAtPath returns the content, size, and git object hash of the file at path under ref. rMutex is held for the entire function, covering all shared-Scanner access (CommitObject, Tree, File). The returned reader is safe to use without the mutex: small blobs are already materialized into a MemoryObject (bytes.Reader) by the time File() returns; large blobs come back as an FSObject whose Reader() opens its own independent file handle and Scanner and then reads via ReadAt — no shared state is touched after this function returns. Callers must Close the reader.

func (*GoGitRepo) Branches added in v0.11.0

func (repo *GoGitRepo) Branches() ([]BranchInfo, error)

Branches returns all local branches (refs/heads/*).

func (*GoGitRepo) Close

func (repo *GoGitRepo) Close() error

func (*GoGitRepo) CommitDetail added in v0.11.0

func (repo *GoGitRepo) CommitDetail(hash Hash) (CommitDetail, error)

CommitDetail returns the full commit metadata and list of changed files.

func (*GoGitRepo) CommitFileDiff added in v0.11.0

func (repo *GoGitRepo) CommitFileDiff(hash Hash, filePath string) (FileDiff, error)

CommitFileDiff returns the unified diff for a single file in a commit, relative to the first parent.

func (*GoGitRepo) CommitLog added in v0.11.0

func (repo *GoGitRepo) CommitLog(ref, path string, limit int, after Hash, since, until *time.Time) ([]CommitMeta, error)

CommitLog returns at most limit commits reachable from ref, optionally filtered to those that touched path, starting after the given cursor hash, and bounded by the since/until author-date range.

func (*GoGitRepo) CopyRef

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

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

func (*GoGitRepo) EraseFromDisk

func (repo *GoGitRepo) EraseFromDisk() error

EraseFromDisk delete this repository entirely from the disk

func (*GoGitRepo) FetchRefs

func (repo *GoGitRepo) FetchRefs(remote string, prefixes ...string) (string, error)

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) GetCoreEditor

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

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

func (*GoGitRepo) GetIndex

func (repo *GoGitRepo) GetIndex(name string) (Index, error)

func (*GoGitRepo) GetLocalRemote

func (repo *GoGitRepo) GetLocalRemote() string

GetLocalRemote return the URL to use to add this repo as a local remote

func (*GoGitRepo) GetOrCreateClock

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) GetRemotes

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

GetRemotes returns the configured remotes repositories.

func (*GoGitRepo) GetUserEmail

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

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

func (*GoGitRepo) GetUserName

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

GetUserName returns the name the user has used to configure git

func (*GoGitRepo) GlobalConfig

func (repo *GoGitRepo) GlobalConfig() Config

GlobalConfig give access to the global scoped configuration

func (*GoGitRepo) Head added in v0.11.0

func (repo *GoGitRepo) Head() (RefMeta, error)

Head returns the ref that HEAD currently points to.

func (*GoGitRepo) Increment

func (repo *GoGitRepo) Increment(name string) (lamport.Time, error)

Increment is equivalent to c = GetOrCreateClock(name) + c.Increment()

func (*GoGitRepo) Keyring

func (repo *GoGitRepo) Keyring() Keyring

Keyring give access to a user-wide storage for secrets

func (*GoGitRepo) LastCommitForEntries added in v0.11.0

func (repo *GoGitRepo) LastCommitForEntries(ref, path string, names []string) (map[string]CommitMeta, error)

LastCommitForEntries performs a single history walk to find, for each name, the most recent commit that changed that entry in the directory at path.

Results are cached by (dirTreeHash, path). Because git trees are content-addressed, two refs that point to the same directory tree share one cache entry, and the cache never needs invalidation: a changed directory produces a new tree hash, which becomes a new key.

func (*GoGitRepo) ListCommits

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

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

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

func (*GoGitRepo) LocalConfig

func (repo *GoGitRepo) LocalConfig() Config

LocalConfig give access to the repository scoped configuration

func (*GoGitRepo) LocalStorage

func (repo *GoGitRepo) LocalStorage() LocalStorage

LocalStorage returns a billy.Filesystem giving access to $RepoPath/.git/$Namespace.

func (*GoGitRepo) PushRefs

func (repo *GoGitRepo) PushRefs(remote string, prefixes ...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.

func (*GoGitRepo) ReadCommit

func (repo *GoGitRepo) ReadCommit(hash Hash) (Commit, error)

func (*GoGitRepo) ReadData

func (repo *GoGitRepo) ReadData(hash Hash) (io.ReadCloser, error)

ReadData will attempt to read arbitrary data from the given hash

func (*GoGitRepo) ReadTree

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

ReadTree will return the list of entries in a Git tree

func (*GoGitRepo) RefExist

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

RefExist will check if a reference exist in Git

func (*GoGitRepo) RemoveRef

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

RemoveRef will remove a Git reference

func (*GoGitRepo) ResolveRef

func (repo *GoGitRepo) ResolveRef(ref string) (Hash, error)

func (*GoGitRepo) StoreCommit

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

StoreCommit will store a Git commit with the given Git tree

func (*GoGitRepo) StoreData

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

StoreData will store arbitrary data and return the corresponding hash

func (*GoGitRepo) StoreSignedCommit

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

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

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

func (*GoGitRepo) Tags added in v0.11.0

func (repo *GoGitRepo) Tags() ([]TagInfo, error)

Tags returns all tags. For annotated tags the hash is dereferenced to the target commit; for lightweight tags it is the commit hash directly.

func (*GoGitRepo) TreeAtPath added in v0.11.0

func (repo *GoGitRepo) TreeAtPath(ref, path string) ([]TreeEntry, error)

TreeAtPath returns the entries of the directory at path under ref.

func (*GoGitRepo) UpdateRef

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

UpdateRef sets a Git reference to hash, only if it currently points to old. An empty old means that the reference must not exist yet. Returns ErrRefChanged otherwise, and the reference is left unchanged.

func (*GoGitRepo) Witness

func (repo *GoGitRepo) Witness(name string, time lamport.Time) error

Witness is equivalent to c = GetOrCreateClock(name) + c.Witness(time)

type Hash

type Hash string

Hash is a git hash

func (*Hash) IsValid

func (h *Hash) IsValid() bool

IsValid tell if the hash is valid

func (Hash) MarshalGQL

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

MarshalGQL implement the Marshaler interface for gqlgen

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalGQL

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

UnmarshalGQL implement the Unmarshaler interface for gqlgen

type Index

type Index interface {
	// IndexOne indexes one document, for the given ID. If the document already exist,
	// it replaces it.
	IndexOne(id string, texts []string) error

	// IndexBatch start a batch indexing. The returned indexer function is used the same
	// way as IndexOne, and the closer function complete the batch insertion.
	IndexBatch() (indexer func(id string, texts []string) error, closer func() error)

	// Search returns the list of IDs matching the given terms.
	Search(terms []string) (ids []string, err error)

	// DocCount returns the number of document in the index.
	DocCount() (uint64, error)

	// Remove delete one document in the index.
	Remove(id string) error

	// Clear empty the index.
	Clear() error

	// Close closes the index and make sure everything is safely written. After this call
	// the index can't be used anymore.
	Close() error
}

Index is a full-text search index

type Item

type Item = keyring.Item

type Keyring

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 LocalStorage

type LocalStorage interface {
	billy.Filesystem
	RemoveAll(path string) error
}

type MemConfig

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

func NewMemConfig

func NewMemConfig() *MemConfig

func (*MemConfig) ReadAll

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

func (*MemConfig) ReadBool

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

func (*MemConfig) ReadString

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

func (*MemConfig) ReadTimestamp

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

func (*MemConfig) RemoveAll

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

RemoveAll remove all key/value pair matching the key prefix

func (*MemConfig) StoreBool

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

func (*MemConfig) StoreString

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

func (*MemConfig) StoreTimestamp

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

type ObjectType

type ObjectType int
const (
	Unknown    ObjectType = iota
	Blob                  // regular file      (100644)
	Tree                  // directory         (040000)
	Executable            // executable file   (100755)
	Symlink               // symbolic link     (120000)
	Submodule             // git submodule     (160000)
)

func ParseObjectType

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

func (ObjectType) Format

func (ot ObjectType) Format() string

func (ObjectType) MarshalGQL added in v0.11.0

func (ot ObjectType) MarshalGQL(w io.Writer)

func (*ObjectType) UnmarshalGQL added in v0.11.0

func (ot *ObjectType) UnmarshalGQL(v any) error

type RefMeta added in v0.11.0

type RefMeta struct {
	// Full reference name, e.g. refs/heads/main or refs/tags/v1.0.
	Name string `json:"name"`
	// Short name, e.g. main or v1.0.
	ShortName string `json:"shortName"`
	// Whether this reference is a branch or a tag.
	Type GitRefType `json:"type"`
	// Commit hash the reference points to.
	Hash string `json:"hash"`
}

type Repo

Repo represents a source code repository.

type RepoBrowse added in v0.11.0

type RepoBrowse interface {
	// Branches returns all local branches (refs/heads/*).
	// All other ref namespaces — including git-bug's internal refs
	// (refs/bugs/, refs/identities/, …) — are excluded.
	Branches() ([]BranchInfo, error)

	// Tags returns all tags (refs/tags/*).
	// All other ref namespaces are excluded.
	Tags() ([]TagInfo, error)

	// TreeAtPath returns the entries of the directory at path under ref.
	// An empty path returns the root tree.
	// Returns ErrNotFound if ref or path does not exist, or if path
	// resolves to a blob rather than a tree.
	// Symlinks appear as entries with ObjectType Symlink; they are not followed.
	TreeAtPath(ref, path string) ([]TreeEntry, error)

	// BlobAtPath returns the raw content, byte size, and git object hash of
	// the file at path under ref. Returns ErrNotFound if ref or path does
	// not exist, or if path resolves to a tree. Symlinks are not followed.
	// The caller must close the reader.
	BlobAtPath(ref, path string) (io.ReadCloser, int64, Hash, error)

	// CommitLog returns at most limit commits reachable from ref, filtered
	// to those touching path (empty = unrestricted). after is an exclusive
	// cursor; pass Hash("") for no cursor. since and until bound the author
	// date (inclusive); pass nil for no bound. Merge commits appear once,
	// compared against the first parent only.
	CommitLog(ref, path string, limit int, after Hash, since, until *time.Time) ([]CommitMeta, error)

	// LastCommitForEntries returns the most recent commit that touched each
	// name in the directory at path under ref. Entries not resolved within
	// the implementation's depth limit are silently absent from the result.
	LastCommitForEntries(ref, path string, names []string) (map[string]CommitMeta, error)

	// CommitDetail returns the full metadata and changed-file list for a
	// single commit identified by its hash. Diffs against the first parent
	// only; the initial commit is diffed against the empty tree.
	CommitDetail(hash Hash) (CommitDetail, error)

	// CommitFileDiff returns the unified diff for a single file in a commit
	// identified by its hash. Diffs against the first parent only; the
	// initial commit is diffed against the empty tree.
	CommitFileDiff(hash Hash, filePath string) (FileDiff, error)

	// Head returns the commit that HEAD currently points to.
	// Returns ErrNotFound if HEAD cannot be resolved to a commit, including
	// for an empty (unborn) repository.
	Head() (RefMeta, error)
}

RepoBrowse is implemented by all Repo implementations and provides code-browsing endpoints (file tree, history, diffs).

All methods accepting a ref parameter resolve it in order: refs/heads/<ref>, refs/tags/<ref>, full ref name, raw commit hash.

type RepoClock

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

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

type RepoCreator func(t testing.TB, bare bool) TestedRepo

type RepoData

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, prefixes ...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)

	// StoreData will store arbitrary data and return the corresponding hash
	StoreData(data []byte) (Hash, error)

	// ReadData returns a reader for arbitrary data associated with the given hash.
	// Returns ErrNotFound if not found.
	// The caller must close the reader.
	ReadData(hash Hash) (io.ReadCloser, 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
	// Returns ErrNotFound if not found.
	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
	// Returns ErrNotFound if not found.
	ReadCommit(hash Hash) (Commit, error)

	// ResolveRef returns the hash of the target commit of the given ref
	// Returns ErrNotFound if not found.
	ResolveRef(ref string) (Hash, error)

	// UpdateRef sets a Git reference to hash, only if it currently points to old.
	// An empty old means that the reference must not exist yet; that check is
	// not atomic, two concurrent creations of the same reference can both succeed.
	// Returns ErrRefChanged otherwise, and the reference is left unchanged.
	// Only direct references are supported: a symbolic reference like HEAD can't
	// be read as old, nor replaced by hash.
	UpdateRef(ref string, old Hash, 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 exists in Git
	RefExist(ref string) (bool, error)

	// CopyRef will create a new reference with the same value as another one
	// Returns ErrNotFound if not found.
	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 RepoIndex

type RepoIndex interface {
	GetIndex(name string) (Index, error)
}

RepoIndex gives access to full-text search indexes

type RepoKeyring

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

type RepoStorage interface {
	// LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug
	LocalStorage() LocalStorage
}

RepoStorage give access to the filesystem

type TagInfo added in v0.11.0

type TagInfo struct {
	Name string
	// Hash is always the target commit hash.  For annotated tags the tag
	// object is dereferenced; for lightweight tags this is the ref hash.
	Hash Hash
}

TagInfo describes a tag returned by RepoBrowse.Tags.

type TestedRepo

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

TestedRepo is an extended ClockedRepo with functions for testing only

func CreateGoGitTestRepo

func CreateGoGitTestRepo(t testing.TB, bare bool) TestedRepo

func SetupGoGitReposAndRemote

func SetupGoGitReposAndRemote(t *testing.T) (repoA, repoB, remote TestedRepo)

type TreeEntry

type TreeEntry struct {
	ObjectType ObjectType
	Hash       Hash
	Name       string
}

func ParseTreeEntry

func ParseTreeEntry(line string) (TreeEntry, error)

func SearchTreeEntry

func SearchTreeEntry(entries []TreeEntry, name string) (TreeEntry, bool)

SearchTreeEntry search a TreeEntry by name from an array

func (TreeEntry) Format

func (entry TreeEntry) Format() string

Format the entry as a git ls-tree compatible line

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL