Documentation ¶
Index ¶
- Variables
- func ExecGitCmd(gitBinDir, repoDir string, args ...string) ([]byte, error)
- func Get(path string) (types.LocalRepo, error)
- func GetAtWorkingDir(gitBinDir string) (types.LocalRepo, error)
- func GetWithGitModule(gitBinPath, path string) (types.LocalRepo, error)
- func InitRepository(name, rootDir, gitBinPath string) error
- type GetLocalRepoFunc
- type GitModule
- func (gm *GitModule) AddEntryToNote(notename, objectHash, note string, env ...string) error
- func (gm *GitModule) AmendRecentCommitWithMsg(msg, signingKey string, env ...string) error
- func (gm *GitModule) Checkout(refname string, create, force bool) error
- func (gm *GitModule) CreateBlob(content string) (string, error)
- func (gm *GitModule) CreateEmptyCommit(msg, signingKey string, env ...string) error
- func (gm *GitModule) CreateSingleFileCommit(filename, content, commitMsg, parent string) (string, error)
- func (gm *GitModule) CreateTagWithMsg(args []string, msg, signingKey string, env ...string) error
- func (gm *GitModule) DiffCommits(commitA, commitB string) (string, error)
- func (gm *GitModule) ExpandShortHash(hash string) (string, error)
- func (gm *GitModule) GC(pruneExpire ...string) error
- func (gm *GitModule) GetHEAD(short bool) (string, error)
- func (gm *GitModule) GetMergeCommits(reference string, env ...string) ([]string, error)
- func (gm *GitModule) GetPathLogInfo(path string, revision ...string) (*remotetypes.PathLogInfo, error)
- func (gm *GitModule) GetRecentCommitHash() (string, error)
- func (gm *GitModule) GetRefCommits(ref string, noMerges bool) ([]string, error)
- func (gm *GitModule) GetRefRootCommit(ref string) (string, error)
- func (gm *GitModule) HasMergeCommits(reference string, env ...string) (bool, error)
- func (gm *GitModule) ListTreeObjects(treename string, recursive bool, env ...string) (map[string]string, error)
- func (gm *GitModule) ListTreeObjectsSlice(treename string, recursive, showTrees bool, env ...string) ([]string, error)
- func (gm *GitModule) NumCommits(refname string, noMerges bool) (int, error)
- func (gm *GitModule) RefDelete(refname string) error
- func (gm *GitModule) RefFetch(params remotetypes.RefFetchArgs) error
- func (gm *GitModule) RefGet(refname string) (string, error)
- func (gm *GitModule) RefUpdate(refname, commitHash string) error
- func (gm *GitModule) RemoveEntryFromNote(notename, objectHash string, env ...string) error
- func (gm *GitModule) Size() (size float64, err error)
- func (gm *GitModule) TagDelete(tagname string) error
- func (gm *GitModule) Var(name string) (string, error)
- type InitRepositoryFunc
- type Repo
- func (r *Repo) GetAncestors(commit *object.Commit, stopHash string, reverse bool) (ancestors []*object.Commit, err error)
- func (r *Repo) GetBranches() (branches []string, err error)
- func (r *Repo) GetCommit(hash string) (*types.CommitResult, error)
- func (r *Repo) GetCommitAncestors(commitHash string, limit int) (res []*types.CommitResult, err error)
- func (r *Repo) GetCommits(ref string, limit int) (res []*types.CommitResult, err error)
- func (r *Repo) GetFile(ref, path string) (res string, err error)
- func (r *Repo) GetFileLines(ref, path string) (res []string, err error)
- func (r *Repo) GetGitConfigOption(path string) string
- func (r *Repo) GetLatestCommit(branch string) (*types.CommitResult, error)
- func (r *Repo) GetName() string
- func (r *Repo) GetNamespace() *state.Namespace
- func (r *Repo) GetNamespaceName() string
- func (r *Repo) GetObject(objHash string) (object.Object, error)
- func (r *Repo) GetObjectSize(objHash string) (int64, error)
- func (r *Repo) GetParentAndChildCommitDiff(commitHash string) (*types.GetCommitDiffResult, error)
- func (r *Repo) GetPath() string
- func (r *Repo) GetReferences() (refs []plumbing.ReferenceName, err error)
- func (r *Repo) GetRemoteURLs(names ...string) (urls []string)
- func (r *Repo) GetRepoConfig() (*types.LocalConfig, error)
- func (r *Repo) GetState() *state.Repository
- func (r *Repo) GetStorer() storage.Storer
- func (r *Repo) Head() (string, error)
- func (r *Repo) HeadObject() (object.Object, error)
- func (r *Repo) IsAncestor(commitA, commitB string) error
- func (r *Repo) IsClean() (bool, error)
- func (r *Repo) IsContributor(pushKeyID string) (isContrib bool)
- func (r *Repo) ListPath(ref, path string) (res []types.ListPathValue, err error)
- func (r *Repo) NumIssueBranches() (count int, err error)
- func (r *Repo) ObjectExist(objHash string) bool
- func (r *Repo) ObjectsOfCommit(hash string) ([]plumbing.Hash, error)
- func (r *Repo) Prune(olderThan time.Time) error
- func (r *Repo) Reload() error
- func (r *Repo) SetConfig(cfg *config.Config) error
- func (r *Repo) SetPath(path string)
- func (r *Repo) SetState(s *state.Repository)
- func (r *Repo) Tags() (storer.ReferenceIter, error)
- func (r *Repo) UpdateRepoConfig(cfg *types.LocalConfig) (err error)
- func (r *Repo) WrappedCommitObject(h plumbing.Hash) (types.Commit, error)
- type WrappedCommit
- func (c *WrappedCommit) GetAuthor() *object.Signature
- func (c *WrappedCommit) GetCommitter() *object.Signature
- func (c *WrappedCommit) GetHash() plumbing.Hash
- func (c *WrappedCommit) GetTree() (*object.Tree, error)
- func (c *WrappedCommit) GetTreeHash() plumbing.Hash
- func (c *WrappedCommit) IsParent(hash string) (bool, types.Commit)
- func (c *WrappedCommit) Parent(i int) (types.Commit, error)
- func (c *WrappedCommit) UnWrap() *object.Commit
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotAnAncestor = fmt.Errorf("not an ancestor") ErrPathNotFound = fmt.Errorf("path not found") ErrPathNotAFile = fmt.Errorf("path is not a file") )
var ErrGitVarNotFound = fmt.Errorf("variable not found")
Functions ¶
func ExecGitCmd ¶
ExecGitCmd executes git commands and returns the output
- repoDir: The directory of the target repository.
- args: Arguments for the git sub-command
func GetAtWorkingDir ¶
GetAtWorkingDir returns a RepoContext instance pointed to the repository in the current working directory.
func InitRepository ¶
InitRepository creates a bare git repository
Types ¶
type GetLocalRepoFunc ¶
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 ¶
NewGitModule creates an instance of GitModule.
- binPath: Git executable path
- path: The target repository path
func (*GitModule) AddEntryToNote ¶
AddEntryToNote adds a note
func (*GitModule) AmendRecentCommitWithMsg ¶
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 ¶
Checkout switches HEAD to the specified reference. When create is true, the -b is added
func (*GitModule) CreateBlob ¶
CreateBlob creates a blob object
func (*GitModule) CreateEmptyCommit ¶
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 ¶
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
DiffCommits returns the diff for the given commits
func (*GitModule) ExpandShortHash ¶
ExpandShortHash expands a short hash into its longer variant
func (*GitModule) GetHEAD ¶
GetHEAD returns the reference stored in HEAD
- short: When set to true, the full reference name is returned
func (*GitModule) GetMergeCommits ¶
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 ¶
GetRecentCommitHash gets the hash of the recent commit Returns ErrNoCommits if no commits exist
func (*GitModule) GetRefCommits ¶
GetRefCommits returns the hash of all commits in the specified reference's history
func (*GitModule) GetRefRootCommit ¶
GetRefRootCommit returns the hash of the root commit of the specified reference
func (*GitModule) HasMergeCommits ¶
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 ¶
NumCommits counts the number of commits in a reference. When noMerges is true, merges are not counted.
func (*GitModule) RefDelete ¶
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 ¶
RefGet returns the hash content of a reference. Returns ErrRefNotFound if ref does not exist
func (*GitModule) RefUpdate ¶
RefUpdate executes `git update-ref <refname> <commit hash>` to update/create a reference
func (*GitModule) RemoveEntryFromNote ¶
RemoveEntryFromNote removes a note
type InitRepositoryFunc ¶
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 ¶
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 ¶
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
GetFile returns the lines of a file
- ref: A full reference name or commit hash
- path: The case-sensitive file path
func (*Repo) GetFileLines ¶
GetFileLines returns the lines of a file
- ref: A full reference name or commit hash
- path: The case-sensitive file path
func (*Repo) GetGitConfigOption ¶
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) GetNamespace ¶
GetNamespace returns the repo's namespace
func (*Repo) GetNamespaceName ¶
GetNamespaceName returns the name of the repo's namespace
func (*Repo) GetObjectSize ¶
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) GetReferences ¶
func (r *Repo) GetReferences() (refs []plumbing.ReferenceName, err error)
GetReferences returns all references in the repo
func (*Repo) GetRemoteURLs ¶
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) HeadObject ¶
HeadObject returns the object of the HEAD reference. Returns plumbing.ErrReferenceNotFound if HEAD was not found.
func (*Repo) IsAncestor ¶
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 ¶
IsClean checks whether the working directory has no un-tracked, staged or modified files
func (*Repo) IsContributor ¶
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 ¶
NumIssueBranches counts the number of issues branches
func (*Repo) ObjectExist ¶
ObjectExist checks whether an object exist in the target repository
func (*Repo) ObjectsOfCommit ¶
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) 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
type WrappedCommit ¶
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