Documentation ¶
Overview ¶
Package GoGits - Git is a pure Go implementation of Git manipulation.
Index ¶
- Variables
- func CreateBranch(repoPath, branchName, id string) error
- func CreateRef(head, repoPath, branchName, id string) error
- func CreateTag(repoPath, tagName, id string) error
- func IntToStr(n int) string
- func IsBranchExist(repoPath, branchName string) bool
- func IsNotFound(err error) bool
- func IsSha1(sha1 string) bool
- func NewId(b []byte) (sha1, error)
- func NewIdFromString(s string) (sha1, error)
- func ParseModeType(modeString string) (EntryMode, ObjectType, error)
- func PrependObjectHeader(objectType ObjectType, r io.ReadSeeker) (io.Reader, error)
- func RefEndName(refStr string) string
- func ScanTreeEntry(data []byte, atEOF bool) (advance int, token []byte, err error)
- func StoreObjectSHA(objectType ObjectType, w io.Writer, r io.ReadSeeker) (sha1, error)
- func StrToInt(str string) (int, error)
- func UnpackRefs(repoPath string) error
- type ArchiveType
- type Blob
- type Commit
- func (c *Commit) BehindAhead(commitId string) (behind int, ahead int, treeErr error)
- func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error
- func (c *Commit) IsAncestor(commitId string) bool
- func (c *Commit) Message() string
- func (c *Commit) Parent(n int) (*Commit, error)
- func (c *Commit) ParentCount() int
- func (c *Commit) ParentId(n int) (id sha1, err error)
- func (c *Commit) ParentIds() []sha1
- func (c *Commit) Summary() string
- func (c *Commit) TreeId() sha1
- func (c *Commit) Walk(walkFn CommitWalkFunc) error
- type CommitWalkFunc
- type Entries
- type EntryMode
- type ObjectNotFound
- type ObjectType
- type RefNotFound
- type Repository
- func (repo *Repository) CommitsBefore(commitId string) (*list.List, error)
- func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error)
- func (repo *Repository) CreateBranch(branchName, idStr string) error
- func (repo *Repository) CreateTag(tagName, idStr string) error
- func (repo *Repository) GetBranches() ([]string, error)
- func (repo *Repository) GetCommit(commitId string) (*Commit, error)
- func (repo *Repository) GetCommitIdOfBranch(branchName string) (string, error)
- func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error)
- func (repo *Repository) GetCommitOfBranch(branchName string) (*Commit, error)
- func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error)
- func (repo *Repository) GetModules() ([]string, error)
- func (repo *Repository) GetTag(tagName string) (*Tag, error)
- func (repo *Repository) GetTags() ([]string, error)
- func (repo *Repository) GetTree(idStr string) (*Tree, error)
- func (repo *Repository) HaveObject(idStr string) (found, packed bool, err error)
- func (repo *Repository) HaveObjectFromReadSeeker(objectType ObjectType, r io.ReadSeeker) (found bool, id sha1, err error)
- func (repo *Repository) IsBranchExist(branchName string) bool
- func (repo *Repository) IsTagExist(tagName string) bool
- func (repo *Repository) StoreObjectLoose(objectType ObjectType, r io.ReadSeeker) (sha1, error)
- func (repo *Repository) TagPath(tagName string) string
- type Signature
- type Submodule
- type Tag
- type Tree
- func (t *Tree) GetBlobByPath(rpath string) (*Blob, error)
- func (t *Tree) GetSubmodules() ([]*Submodule, error)
- func (t *Tree) GetTreeEntryByPath(rpath string) (*TreeEntry, error)
- func (t *Tree) ListEntries() (Entries, error)
- func (t *Tree) Scanner() (*TreeScanner, error)
- func (t *Tree) SubTree(rpath string) (*Tree, error)
- func (t *Tree) Walk(walkFn TreeWalkFunc) error
- type TreeEntry
- func (te *TreeEntry) Blob() *Blob
- func (te *TreeEntry) EntryMode() EntryMode
- func (te *TreeEntry) IsDir() bool
- func (te *TreeEntry) ModTime() time.Time
- func (te *TreeEntry) Mode() (mode os.FileMode)
- func (te *TreeEntry) Name() string
- func (te *TreeEntry) Size() int64
- func (te *TreeEntry) Sys() interface{}
- func (te *TreeEntry) Tree() *Tree
- type TreeScanner
- type TreeWalkFunc
Constants ¶
This section is empty.
Variables ¶
var (
ErrBranchExisted = errors.New("branch has existed")
)
var ErrDisjoint = errors.New("commit trees are disjoint")
var ErrNoPackedRefs = errors.New("no packed-refs")
var ErrNotExist = os.ErrNotExist
var (
IdNotExist = errors.New("sha1 id not exist")
)
var (
SkipCommit = errors.New("skip this commit's ancestry")
)
var (
SkipDir = errors.New("skip this directory")
)
var TreeEntryRe = regexp.MustCompile("^([0-9]+) ([^\x00]+)\x00")
Functions ¶
func CreateBranch ¶
func IsBranchExist ¶
func IsNotFound ¶
IsNotFound returns whether the error is about failing to find an object (RefNotFound, ObjectNotFound, etc).
func NewIdFromString ¶
Create a new sha1 from a Sha1 string of length 40.
func ParseModeType ¶
func ParseModeType(modeString string) (EntryMode, ObjectType, error)
func PrependObjectHeader ¶
func PrependObjectHeader(objectType ObjectType, r io.ReadSeeker) (io.Reader, error)
Add '<type> <size>\x00' to beginning of `r`.
func RefEndName ¶
func ScanTreeEntry ¶
func StoreObjectSHA ¶
func StoreObjectSHA( objectType ObjectType, w io.Writer, r io.ReadSeeker, ) (sha1, error)
Write an the object contents in `r` in compressed form to `w` and return the hash. Special case: if `w` is `ioutil.Discard`, the data is not compressed, since the data is not consumed anywhere.
func UnpackRefs ¶
UnpackRefs unpacks 'packed-refs' to git repository.
Types ¶
type Commit ¶
type Commit struct { Tree Id sha1 // The id of this commit object Author *Signature Committer *Signature CommitMessage string // contains filtered or unexported fields }
Commit represents a git commit.
func (*Commit) BehindAhead ¶
BehindAhead computes the number of commits are behind (missing) and ahead (extra) of commitId. ErrDisjoint is returned when the two commits don't have a common ancestor, and the length of the tree depth for each.
BehindAhead will traverse the entire ancestry of this commit, then traversing the ancestroy of the target commitId until a common ancestor is found.
TODO: Use a bitmap index for reachability (https://github.com/shazow/go-git/issues/4)
func (*Commit) CreateArchive ¶
func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error
func (*Commit) IsAncestor ¶
IsAncestor returns whether commitId is an ancestor of this commit. False if it's the same commit. Similar to `git merge-base --is-ancestor`.
IsAncestor will traverse the ancestry of the current commit until it finds the target commitIt.
TODO: Use a bitmap index for reachability (https://github.com/shazow/go-git/issues/4)
func (*Commit) ParentCount ¶
Return the number of parents of the commit. 0 if this is the root commit, otherwise 1,2,...
func (*Commit) ParentId ¶
Return oid of the parent number n (0-based index). Return nil if no such parent exists.
func (*Commit) TreeId ¶
func (c *Commit) TreeId() sha1
Return oid of the (root) tree of this commit.
func (*Commit) Walk ¶
func (c *Commit) Walk(walkFn CommitWalkFunc) error
Commit and its' parents will be traversed iteratively in depth-first order, walkFn called on each commit.
type CommitWalkFunc ¶
CommitWalkFunc is similar to path/filepath.WalkFunc, it will traverse all of a commit's ancestry as long as the returned error is nil. If SkipCommit is returned, then it will bypass that commit's subtree.
type ObjectNotFound ¶
type ObjectNotFound sha1
ObjectNotFound error returned when a repo query is performed for an ID that does not exist.
func (ObjectNotFound) Error ¶
func (id ObjectNotFound) Error() string
type ObjectType ¶
type ObjectType int
Who am I?
const ( ObjectCommit ObjectType = 0x10 ObjectTree ObjectType = 0x20 ObjectBlob ObjectType = 0x30 ObjectTag ObjectType = 0x40 )
func (ObjectType) String ¶
func (t ObjectType) String() string
type RefNotFound ¶
type RefNotFound string
RefNotFound error returned when a commit is fetched by ref that is not found.
func (RefNotFound) Error ¶
func (err RefNotFound) Error() string
type Repository ¶
type Repository struct { Path string // contains filtered or unexported fields }
A Repository is the base of all other actions. If you need to lookup a commit, tree or blob, you do it from here.
func OpenRepository ¶
func OpenRepository(path string) (*Repository, error)
Open the repository at the given path.
func (*Repository) CommitsBefore ¶
func (repo *Repository) CommitsBefore(commitId string) (*list.List, error)
func (*Repository) CommitsBetween ¶
used only for single tree, (]
func (*Repository) CreateBranch ¶
func (repo *Repository) CreateBranch(branchName, idStr string) error
func (*Repository) CreateTag ¶
func (repo *Repository) CreateTag(tagName, idStr string) error
func (*Repository) GetBranches ¶
func (repo *Repository) GetBranches() ([]string, error)
func (*Repository) GetCommit ¶
func (repo *Repository) GetCommit(commitId string) (*Commit, error)
Find the commit object in the repository.
func (*Repository) GetCommitIdOfBranch ¶
func (repo *Repository) GetCommitIdOfBranch(branchName string) (string, error)
func (*Repository) GetCommitIdOfTag ¶
func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error)
func (*Repository) GetCommitOfBranch ¶
func (repo *Repository) GetCommitOfBranch(branchName string) (*Commit, error)
get branch's last commit or a special commit by id string
func (*Repository) GetCommitOfTag ¶
func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error)
func (*Repository) GetModules ¶
func (repo *Repository) GetModules() ([]string, error)
GetModules returns the submodule names that are initialized and cached within .git/modules
func (*Repository) GetTags ¶
func (repo *Repository) GetTags() ([]string, error)
GetTags returns all tags of given repository.
func (*Repository) GetTree ¶
func (repo *Repository) GetTree(idStr string) (*Tree, error)
Find the tree object in the repository.
func (*Repository) HaveObject ¶
func (repo *Repository) HaveObject(idStr string) (found, packed bool, err error)
func (*Repository) HaveObjectFromReadSeeker ¶
func (repo *Repository) HaveObjectFromReadSeeker( objectType ObjectType, r io.ReadSeeker, ) (found bool, id sha1, err error)
Returns true if the content in `io.ReadSeeker` is aleady present in the object database. Leaves the initial seek position of `r` intact.
func (*Repository) IsBranchExist ¶
func (repo *Repository) IsBranchExist(branchName string) bool
func (*Repository) IsTagExist ¶
func (repo *Repository) IsTagExist(tagName string) bool
func (*Repository) StoreObjectLoose ¶
func (repo *Repository) StoreObjectLoose( objectType ObjectType, r io.ReadSeeker, ) (sha1, error)
Write an object into git's loose database. If the object already exists in the database, it is not overwritten, though the compression is still performed. To avoid the compression, call HaveObjectFromReader first, which is fast and just does the SHA.
func (*Repository) TagPath ¶
func (repo *Repository) TagPath(tagName string) string
type Tag ¶
type Tag struct { Name string Id sha1 Object sha1 // The id of this commit object Type string Tagger *Signature TagMessage string // contains filtered or unexported fields }
Tag
type Tree ¶
type Tree struct { Id sha1 // contains filtered or unexported fields }
A tree is a flat directory listing.
func NewTree ¶
func NewTree(repo *Repository, id sha1) *Tree
func (*Tree) GetSubmodules ¶
GetSubmodules returns the submodules in this commit tree (parsed from .gitmodules)
func (*Tree) GetTreeEntryByPath ¶
func (*Tree) ListEntries ¶
func (*Tree) Scanner ¶
func (t *Tree) Scanner() (*TreeScanner, error)
func (*Tree) Walk ¶
func (t *Tree) Walk(walkFn TreeWalkFunc) error
The tree's directory heirarchy will be traversed recursively in breadth-first order, walkFn will be called once for each entry.
type TreeEntry ¶
type TreeEntry struct { Id sha1 Type ObjectType // contains filtered or unexported fields }
type TreeScanner ¶
func NewTreeScanner ¶
func NewTreeScanner(parent *Tree, rc io.ReadCloser) *TreeScanner
func (*TreeScanner) Err ¶
func (t *TreeScanner) Err() error
func (*TreeScanner) Scan ¶
func (t *TreeScanner) Scan() bool
func (*TreeScanner) TreeEntry ¶
func (t *TreeScanner) TreeEntry() *TreeEntry
Source Files ¶
- blob.go
- commit.go
- commit_archive.go
- commit_utils.go
- commit_walk.go
- reference.go
- repo.go
- repo_branch.go
- repo_commit.go
- repo_object.go
- repo_submodule.go
- repo_tag.go
- repo_tree.go
- repo_utils.go
- repo_utils_parse.go
- repo_utils_reader.go
- sha1.go
- signature.go
- submodule.go
- tag.go
- tree.go
- tree_blob.go
- tree_entry.go
- tree_submodule.go
- tree_utils.go
- utils.go