repo

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAnAncestor = fmt.Errorf("not an ancestor")
	ErrPathNotFound  = fmt.Errorf("path not found")
	ErrPathNotAFile  = fmt.Errorf("path is not a file")
)
View Source
var ErrGitVarNotFound = fmt.Errorf("variable not found")

Functions

func ExecGitCmd

func ExecGitCmd(gitBinDir, repoDir string, args ...string) ([]byte, error)

ExecGitCmd executes git commands and returns the output

  • repoDir: The directory of the target repository.
  • args: Arguments for the git sub-command

func Get

func Get(path string) (types.LocalRepo, error)

Get opens a local repository and returns a handle.

func GetAtWorkingDir

func GetAtWorkingDir(gitBinDir string) (types.LocalRepo, error)

GetAtWorkingDir returns a RepoContext instance pointed to the repository in the current working directory.

func GetWithGitModule

func GetWithGitModule(gitBinPath, path string) (types.LocalRepo, error)

func InitRepository

func InitRepository(name, rootDir, gitBinPath string) error

InitRepository creates a bare git repository

Types

type GetLocalRepoFunc

type GetLocalRepoFunc func(gitBinPath, path string) (types.LocalRepo, error)

GetLocalRepoFunc describes a function for getting a local repository handle

type GitModule

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

GitModule provides convenience methods that utilize the git tool to access and modify a repository

func NewGitModule

func NewGitModule(gitBinPath, path string) *GitModule

NewGitModule creates an instance of GitModule.

  • binPath: Git executable path
  • path: The target repository path

func (*GitModule) AddEntryToNote

func (gm *GitModule) AddEntryToNote(notename, objectHash, note string, env ...string) error

AddEntryToNote adds a note

func (*GitModule) AmendRecentCommitWithMsg

func (gm *GitModule) AmendRecentCommitWithMsg(msg, signingKey string, env ...string) error

AmendRecentCommitWithMsg amends the recent commit

  • msg: The commit message.
  • signingKey: An optional signing key
  • env: Optional environment variables to pass to the command.

func (*GitModule) Checkout

func (gm *GitModule) Checkout(refname string, create, force bool) error

Checkout switches HEAD to the specified reference. When create is true, the -b is added

func (*GitModule) CreateBlob

func (gm *GitModule) CreateBlob(content string) (string, error)

CreateBlob creates a blob object

func (*GitModule) CreateEmptyCommit

func (gm *GitModule) CreateEmptyCommit(msg, signingKey string, env ...string) error

CreateEmptyCommit creates a quiet commit.

  • msg: The commit message.
  • signingKey: The optional signing key. If provided, the commit is signed
  • env: Optional environment variables to pass to the command.

func (*GitModule) CreateSingleFileCommit

func (gm *GitModule) CreateSingleFileCommit(filename, content, commitMsg, parent string) (string, error)

CreateSingleFileCommit creates a commit tree with no parent and has only one file

func (*GitModule) CreateTagWithMsg

func (gm *GitModule) CreateTagWithMsg(args []string, msg, signingKey string, env ...string) error

CreateTagWithMsg an annotated tag

  • args: `git tag` options (NOTE: -a and --file=- are added by default)
  • msg: The tag's message which is passed to the command's stdin.
  • signingKey: The signing key to use
  • env: Optional environment variables to pass to the command.

func (*GitModule) DiffCommits added in v0.0.30

func (gm *GitModule) DiffCommits(commitA, commitB string) (string, error)

DiffCommits returns the diff for the given commits

func (*GitModule) ExpandShortHash

func (gm *GitModule) ExpandShortHash(hash string) (string, error)

ExpandShortHash expands a short hash into its longer variant

func (*GitModule) GC

func (gm *GitModule) GC(pruneExpire ...string) error

GC performs garbage collection

func (*GitModule) GetHEAD

func (gm *GitModule) GetHEAD(short bool) (string, error)

GetHEAD returns the reference stored in HEAD

  • short: When set to true, the full reference name is returned

func (*GitModule) GetMergeCommits

func (gm *GitModule) GetMergeCommits(reference string, env ...string) ([]string, error)

GetMergeCommits returns the hash of merge commits in a reference

func (*GitModule) GetPathLogInfo added in v0.0.30

func (gm *GitModule) GetPathLogInfo(path string, revision ...string) (*remotetypes.PathLogInfo, error)

GetPathLogInfo returns log info for a given path

  • path: The file or directory path.
  • revision: The references whose log is fetched (optional)

func (*GitModule) GetRecentCommitHash

func (gm *GitModule) GetRecentCommitHash() (string, error)

GetRecentCommitHash gets the hash of the recent commit Returns ErrNoCommits if no commits exist

func (*GitModule) GetRefCommits

func (gm *GitModule) GetRefCommits(ref string, noMerges bool) ([]string, error)

GetRefCommits returns the hash of all commits in the specified reference's history

func (*GitModule) GetRefRootCommit

func (gm *GitModule) GetRefRootCommit(ref string) (string, error)

GetRefRootCommit returns the hash of the root commit of the specified reference

func (*GitModule) HasMergeCommits

func (gm *GitModule) HasMergeCommits(reference string, env ...string) (bool, error)

HasMergeCommits checks whether a reference has merge commits

func (*GitModule) ListTreeObjects

func (gm *GitModule) ListTreeObjects(treename string, recursive bool, env ...string) (map[string]string, error)

ListTreeObjects returns a map containing tree entries (filename: objectname)

func (*GitModule) ListTreeObjectsSlice

func (gm *GitModule) ListTreeObjectsSlice(treename string, recursive, showTrees bool, env ...string) ([]string, error)

ListTreeObjectsSlice returns a slice containing objects name of tree entries

func (*GitModule) NumCommits

func (gm *GitModule) NumCommits(refname string, noMerges bool) (int, error)

NumCommits counts the number of commits in a reference. When noMerges is true, merges are not counted.

func (*GitModule) RefDelete

func (gm *GitModule) RefDelete(refname string) error

RefDelete executes `git update-ref -d <refname>` to delete a reference

func (*GitModule) RefFetch

func (gm *GitModule) RefFetch(params remotetypes.RefFetchArgs) error

RefFetch fetches a remote branch into a local branch

func (*GitModule) RefGet

func (gm *GitModule) RefGet(refname string) (string, error)

RefGet returns the hash content of a reference. Returns ErrRefNotFound if ref does not exist

func (*GitModule) RefUpdate

func (gm *GitModule) RefUpdate(refname, commitHash string) error

RefUpdate executes `git update-ref <refname> <commit hash>` to update/create a reference

func (*GitModule) RemoveEntryFromNote

func (gm *GitModule) RemoveEntryFromNote(notename, objectHash string, env ...string) error

RemoveEntryFromNote removes a note

func (*GitModule) Size

func (gm *GitModule) Size() (size float64, err error)

Size returns the size of all packed, loose and garbage objects

func (*GitModule) TagDelete

func (gm *GitModule) TagDelete(tagname string) error

TagDelete executes `git tag -d <tagname>` to delete a tag

func (*GitModule) Var

func (gm *GitModule) Var(name string) (string, error)

Var returns the value of git's logical variables

type InitRepositoryFunc

type InitRepositoryFunc func(name string, rootDir string, gitBinPath string) error

type Repo

type Repo struct {
	*GitModule
	*git.Repository
	Path          string
	NamespaceName string
	Namespace     *state.Namespace
	State         *state.Repository
}

Repo provides functions for accessing and modifying a local repository.

func (*Repo) GetAncestors

func (r *Repo) GetAncestors(commit *object.Commit, stopHash string, reverse bool) (ancestors []*object.Commit, err error)

GetAncestors returns the ancestors of the given commit up til the ancestor matching the stop hash. The stop hash ancestor is not included in the result. Reverse reverses the result.

func (*Repo) GetBranches

func (r *Repo) GetBranches() (branches []string, err error)

GetBranches returns a list of branches

func (*Repo) GetCommit added in v0.0.30

func (r *Repo) GetCommit(hash string) (*types.CommitResult, error)

GetCommit gets a commit by hash

  • hash: The commit hash

func (*Repo) GetCommitAncestors

func (r *Repo) GetCommitAncestors(commitHash string, limit int) (res []*types.CommitResult, err error)

GetCommitAncestors returns ancestors of a commit with the given hash.

  • commitHash: The hash of the commit.
  • limit: The number of commit to return. 0 means all.

func (*Repo) GetCommits

func (r *Repo) GetCommits(ref string, limit int) (res []*types.CommitResult, err error)

GetCommits returns commits of a branch or commit hash

  • ref: The target reference name (branch or commit hash)
  • limit: The number of commit to return. 0 means all.

func (*Repo) GetFile added in v0.0.30

func (r *Repo) GetFile(ref, path string) (res string, err error)

GetFile returns the lines of a file

  • ref: A full reference name or commit hash
  • path: The case-sensitive file path

func (*Repo) GetFileLines

func (r *Repo) GetFileLines(ref, path string) (res []string, err error)

GetFileLines returns the lines of a file

  • ref: A full reference name or commit hash
  • path: The case-sensitive file path

func (*Repo) GetGitConfigOption

func (r *Repo) GetGitConfigOption(path string) string

GetGitConfigOption finds and returns git config option value

func (*Repo) GetLatestCommit

func (r *Repo) GetLatestCommit(branch string) (*types.CommitResult, error)

GetLatestCommit returns the recent commit of a branch

func (*Repo) GetName

func (r *Repo) GetName() string

GetName returns the name of the repo

func (*Repo) GetNamespace

func (r *Repo) GetNamespace() *state.Namespace

GetNamespace returns the repo's namespace

func (*Repo) GetNamespaceName

func (r *Repo) GetNamespaceName() string

GetNamespaceName returns the name of the repo's namespace

func (*Repo) GetObject

func (r *Repo) GetObject(objHash string) (object.Object, error)

GetObject returns an object

func (*Repo) GetObjectSize

func (r *Repo) GetObjectSize(objHash string) (int64, error)

GetObjectSize returns the size of a decompressed object

func (*Repo) GetParentAndChildCommitDiff added in v0.0.30

func (r *Repo) GetParentAndChildCommitDiff(commitHash string) (*types.GetCommitDiffResult, error)

GetParentAndChildCommitDiff returns the commit diff output between a child commit and its parent commit(s). If the commit has more than one parent, the diff will be run for all parents.

  • commitHash: The child commit hash.

func (*Repo) GetPath

func (r *Repo) GetPath() string

GetPath returns the bare repository path.

func (*Repo) GetReferences

func (r *Repo) GetReferences() (refs []plumbing.ReferenceName, err error)

GetReferences returns all references in the repo

func (*Repo) GetRemoteURLs

func (r *Repo) GetRemoteURLs(names ...string) (urls []string)

GetRemoteURLs returns the remote URLS of the repository. Use `names` to select specific remotes with matching name.

func (*Repo) GetRepoConfig

func (r *Repo) GetRepoConfig() (*types.LocalConfig, error)

GetRepoConfig returns the repo's 'repocfg' config object. Returns an empty LocalConfig and nil if no repo config file was found

func (*Repo) GetState

func (r *Repo) GetState() *state.Repository

GetState returns the repository's network state

func (*Repo) GetStorer

func (r *Repo) GetStorer() storage.Storer

GetStorer returns the storage engine of the repository

func (*Repo) Head

func (r *Repo) Head() (string, error)

Head returns the reference where HEAD is pointing to.

func (*Repo) HeadObject

func (r *Repo) HeadObject() (object.Object, error)

HeadObject returns the object of the HEAD reference. Returns plumbing.ErrReferenceNotFound if HEAD was not found.

func (*Repo) IsAncestor

func (r *Repo) IsAncestor(commitA, commitB string) error

IsAncestor checks whether commitA is an ancestor to commitB. It returns ErrNotAncestor when not an ancestor. It returns ErrObjectNotFound if commit A or B does not exist.

func (*Repo) IsClean

func (r *Repo) IsClean() (bool, error)

IsClean checks whether the working directory has no un-tracked, staged or modified files

func (*Repo) IsContributor

func (r *Repo) IsContributor(pushKeyID string) (isContrib bool)

IsContributor checks whether a push key is a contributor to either the repository or its namespace

func (*Repo) ListPath

func (r *Repo) ListPath(ref, path string) (res []types.ListPathValue, err error)

ListPath lists entries in a given path on the given reference.

func (*Repo) NumIssueBranches

func (r *Repo) NumIssueBranches() (count int, err error)

NumIssueBranches counts the number of issues branches

func (*Repo) ObjectExist

func (r *Repo) ObjectExist(objHash string) bool

ObjectExist checks whether an object exist in the target repository

func (*Repo) ObjectsOfCommit

func (r *Repo) ObjectsOfCommit(hash string) ([]plumbing.Hash, error)

ObjectsOfCommit returns a hashes of objects a commit is composed of. This objects a the commit itself, its tree and the tree blobs.

func (*Repo) Prune

func (r *Repo) Prune(olderThan time.Time) error

Prune deletes objects older than the given time

func (*Repo) Reload

func (r *Repo) Reload() error

Reload reloads the repository

func (*Repo) SetConfig

func (r *Repo) SetConfig(cfg *config.Config) error

SetConfig sets the repo config

func (*Repo) SetPath

func (r *Repo) SetPath(path string)

SetPath sets the repository root path

func (*Repo) SetState

func (r *Repo) SetState(s *state.Repository)

SetState sets the repository's network state

func (*Repo) Tags

func (r *Repo) Tags() (storer.ReferenceIter, error)

Tags return all tag references in the repository. If you want to check to see if the tag is an annotated tag, you can call TagObject on the hash Reference

func (*Repo) UpdateRepoConfig

func (r *Repo) UpdateRepoConfig(cfg *types.LocalConfig) (err error)

UpdateRepoConfig updates the repo's 'repocfg' configuration file

func (*Repo) WrappedCommitObject

func (r *Repo) WrappedCommitObject(h plumbing.Hash) (types.Commit, error)

WrappedCommitObject returns commit that implements types.WrappedCommit interface.

type WrappedCommit

type WrappedCommit struct {
	*object.Commit
}

WrappedCommit wraps a go-git commit to ensure it conforms to types.WrappedCommit

func WrapCommit

func WrapCommit(gc *object.Commit) *WrappedCommit

wrapCommit creates a WrappedCommit that wraps a go-git commit object

func (*WrappedCommit) GetAuthor

func (c *WrappedCommit) GetAuthor() *object.Signature

GetAuthor returns the original author of the commit.

func (*WrappedCommit) GetCommitter

func (c *WrappedCommit) GetCommitter() *object.Signature

GetCommitter returns the one performing the commit, might be different from Author

func (*WrappedCommit) GetHash

func (c *WrappedCommit) GetHash() plumbing.Hash

GetHash returns the hash of the commit object

func (*WrappedCommit) GetTree

func (c *WrappedCommit) GetTree() (*object.Tree, error)

Tree returns the tree from the commit

func (*WrappedCommit) GetTreeHash

func (c *WrappedCommit) GetTreeHash() plumbing.Hash

GetTreeHash returns the hash of the root tree of the commit

func (*WrappedCommit) IsParent

func (c *WrappedCommit) IsParent(hash string) (bool, types.Commit)

IsParent checks whether the specified hash is a parent of the commit

func (*WrappedCommit) Parent

func (c *WrappedCommit) Parent(i int) (types.Commit, error)

Parent returns the ith parent of a commit.

func (*WrappedCommit) UnWrap

func (c *WrappedCommit) UnWrap() *object.Commit

UnWrap returns the underlying commit object

Jump to

Keyboard shortcuts

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