git package - github.com/Nivl/git-go - Go Packages
Package git contains methods to deal with git internals
- Variables
- type InitOptions
- type OpenOptions
- type Repository
- func InitRepository(workTreePath string) (*Repository, error)
- func InitRepositoryWithOptions(rootPath string, opts InitOptions) (r *Repository, err error)
- func InitRepositoryWithParams(cfg *config.Config, opts InitOptions) (r *Repository, err error)
- func OpenRepository(workTreePath string) (*Repository, error)
- func OpenRepositoryWithOptions(rootPath string, opts OpenOptions) (r *Repository, err error)
- func OpenRepositoryWithParams(cfg *config.Config, opts OpenOptions) (r *Repository, err error)
- func (r *Repository) Blob(oid ginternals.Oid) (*object.Blob, error)
- func (r *Repository) Close() error
- func (r *Repository) Commit(oid ginternals.Oid) (*object.Commit, error)
- func (r *Repository) IsBare() bool
- func (r *Repository) NewBlob(data []byte) (*object.Blob, error)
- func (r *Repository) NewCommit(refname string, tree *object.Tree, author object.Signature, ...) (*object.Commit, error)
- func (r *Repository) NewDetachedCommit(tree *object.Tree, author object.Signature, opts *object.CommitOptions) (*object.Commit, error)
- func (r *Repository) NewLightweightTag(tag string, targetID ginternals.Oid) (*ginternals.Reference, error)
- func (r *Repository) NewReference(name string, target ginternals.Oid) (*ginternals.Reference, error)
- func (r *Repository) NewReferenceSafe(name string, target ginternals.Oid) (*ginternals.Reference, error)
- func (r *Repository) NewSymbolicReference(name, target string) (*ginternals.Reference, error)
- func (r *Repository) NewSymbolicReferenceSafe(name, target string) (*ginternals.Reference, error)
- func (r *Repository) NewTag(p *object.TagParams) (*object.Tag, error)
- func (r *Repository) NewTreeBuilder() *TreeBuilder
- func (r *Repository) NewTreeBuilderFromTree(t *object.Tree) *TreeBuilder
- func (r *Repository) Object(oid ginternals.Oid) (*object.Object, error)
- func (r *Repository) Reference(name string) (*ginternals.Reference, error)
- func (r *Repository) Tag(name string) (*ginternals.Reference, error)
- func (r *Repository) Tree(oid ginternals.Oid) (*object.Tree, error)
- type TreeBuilder
This section is empty.
var ( ErrRepositoryNotExist = errors.New("repository does not exist") ErrRepositoryUnsupportedVersion = errors.New("repository nor supported") ErrTagNotFound = errors.New("tag not found") ErrTagExists = errors.New("tag already exists") ErrNotADirectory = errors.New("not a directory") ErrInvalidBranchName = errors.New("invalid branch name") )
List of errors returned by the Repository struct
This section is empty.
InitOptions contains all the optional data used to initialized a repository
OpenOptions contains all the optional data used to open a repository
Repository represent a git repository A Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time. https://blog.axosoft.com/learning-git-repository/
OpenRepository loads an existing git repository by reading its config file, and returns a Repository instance
This assumes: - The repo is not bare (see WithOptions) - We're not interested in env vars (see WithParams) - The git dir is in the working tree under .git
func OpenRepositoryWithOptions(rootPath string, opts OpenOptions) (r *Repository, err error)
OpenRepositoryWithOptions loads an existing git repository by reading its config file, and returns a Repository instance
This assumes: - We're not interested in env vars (see WithParams) - The git dir is in the working tree under .git
OpenRepositoryWithParams loads an existing git repository by reading its config file, and returns a Repository instance
This method makes no assumptions
Blob returns the blob matching the given ID This method will always work as long as the OID points to a valid object. Calling Blob with a commit OID, will return the raw data of the commit.
Close frees the resources used by the repository
Commit returns the commit matching the given SHA
IsBare returns whether the repo is bare or not. A bare repo doesn't have a workign tree
NewBlob creates, stores, and returns a new Blob object
NewCommit creates, stores, and returns a new Commit object The head of the reference $refname will be updated to this new commit. An empty refName will create a detached (loose) commit If the reference doesn't exists, it will be created
NewDetachedCommit creates, stores, and returns a new Commit object not attached to any reference
NewLightweightTag creates, stores, and returns a lightweight tag
NewReference creates, stores, and returns a new reference If the reference already exists, it will be overwritten
NewReferenceSafe creates, stores, and returns a new reference If the reference already exists, the method will fail
NewSymbolicReference creates, stores, and returns a new symbolic reference If the reference already exists, it will be overwritten
NewSymbolicReferenceSafe creates, stores, and returns a new symbolic reference. If the reference already exists, the method will fail
NewTag creates, stores, and returns a new annoted tag
func (r *Repository) NewTreeBuilder() *TreeBuilder
NewTreeBuilder create a new empty tree builder
NewTreeBuilderFromTree create a new tree builder containing the entries of another tree
Object returns the object matching the given ID
Reference returns the reference matching the given name
Tag returns the reference for the given tag To know if the tag is annoted or lightweight, call repo.GetObject() on the reference's target ad make sure that the returned object is not a tag with the same name (note that it's technically possible for a tag to target another tag)
Tree returns the tree matching the given SHA
TreeBuilder is used to build trees
Insert inserts a new object in a tree
Remove removes an object from tree
Write creates and persists a new Tree object