git

package module
v0.0.0-...-63b74d4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 24 Imported by: 0

README

Git Shell

Build Status codecov Go Report Card GoDoc

This project is a Go module to access Git through shell commands. For further informations take a look at the current documentation.

Contributing

Fork -> Patch -> Push -> Pull Request

Authors

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const BranchPrefix = "refs/heads/"

BranchPrefix base dir of the branch information file store on git

View Source
const EmptySHA = "0000000000000000000000000000000000000000"

EmptySHA defines empty git SHA

View Source
const (
	// GitTimeLayout is the (default) time layout used by git.
	GitTimeLayout = "Mon Jan _2 15:04:05 2006 -0700"
)
View Source
const (
	// HookPathUpdate hook update path
	HookPathUpdate = "hooks/update"
)
View Source
const TagPrefix = "refs/tags/"

TagPrefix tags prefix path on the repository

Variables

View Source
var (
	// GlobalCommandArgs global command args for external package setting
	GlobalCommandArgs []string

	// DefaultCommandExecutionTimeout default command execution timeout duration
	DefaultCommandExecutionTimeout = 60 * time.Second
)
View Source
var (
	// Debug enables verbose logging on everything.
	// This should be false in case Gogs starts in SSH mode.
	Debug = false
	// Prefix the log prefix
	Prefix = "[git-module] "
	// GitVersionRequired is the minimum Git version required
	GitVersionRequired = "1.7.2"
)
View Source
var CommitsRangeSize = 50

CommitsRangeSize the default commits range size

View Source
var (
	// ErrNotValidHook error when a git hook is not valid
	ErrNotValidHook = errors.New("not a valid Git hook")
)

Functions

func AddChanges

func AddChanges(repoPath string, all bool, files ...string) error

AddChanges marks local changes to be ready for commit.

func BinVersion

func BinVersion() (string, error)

BinVersion returns current Git version from shell.

func Checkout

func Checkout(repoPath string, opts CheckoutOptions) error

Checkout checkouts a branch

func Clone

func Clone(from, to string, opts CloneRepoOptions) (err error)

Clone clones original repository to target path.

func CommitChanges

func CommitChanges(repoPath string, opts CommitChangesOptions) error

CommitChanges commits local changes with given committer, author and message. If author is nil, it will be the same as committer.

func CommitsCount

func CommitsCount(repoPath, revision string) (int64, error)

CommitsCount returns number of total commits of until given revision.

func Fsck

func Fsck(repoPath string, timeout time.Duration, args ...string) error

Fsck verifies the connectivity and validity of the objects in the database

func GetFullCommitID

func GetFullCommitID(repoPath, shortID string) (string, error)

GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.

func GetLatestCommitTime

func GetLatestCommitTime(repoPath string) (time.Time, error)

GetLatestCommitTime returns time for latest commit in repository (across all branches)

func InitRepository

func InitRepository(repoPath string, bare bool) error

InitRepository initializes a new Git repository.

func IsBranchExist

func IsBranchExist(repoPath, name string) bool

IsBranchExist returns true if given branch exists in the repository.

func IsErrExecTimeout

func IsErrExecTimeout(err error) bool

IsErrExecTimeout if some error is ErrExecTimeout

func IsErrNotExist

func IsErrNotExist(err error) bool

IsErrNotExist if some error is ErrNotExist

func IsErrUnsupportedVersion

func IsErrUnsupportedVersion(err error) bool

IsErrUnsupportedVersion if some error is ErrUnsupportedVersion

func IsReferenceExist

func IsReferenceExist(repoPath, name string) bool

IsReferenceExist returns true if given reference exists in the repository.

func IsRepoURLAccessible

func IsRepoURLAccessible(url string) bool

IsRepoURLAccessible checks if given repository URL is accessible.

func IsTagExist

func IsTagExist(repoPath, name string) bool

IsTagExist returns true if given tag exists in the repository.

func IsValidHookName

func IsValidHookName(name string) bool

IsValidHookName returns true if given name is a valid Git hook.

func MoveFile

func MoveFile(repoPath, oldTreeName, newTreeName string) error

MoveFile moves a file to another file or directory.

func Pull

func Pull(repoPath string, opts PullRemoteOptions) error

Pull pulls changes from remotes.

func Push

func Push(repoPath string, opts PushOptions) error

Push pushs local commits to given remote branch.

func RefEndName

func RefEndName(refStr string) string

RefEndName return the end name of a ref name

func ResetHEAD

func ResetHEAD(repoPath string, hard bool, revision string) error

ResetHEAD resets HEAD to given revision or head of branch.

func SetUpdateHook

func SetUpdateHook(repoPath, content string) (err error)

SetUpdateHook writes given content to update hook of the reposiotry.

func Version

func Version() string

Version return this package's current version

Types

type ArchiveType

type ArchiveType int

ArchiveType archive types

const (
	// ZIP zip archive type
	ZIP ArchiveType = iota + 1
	// TARGZ tar gz archive type
	TARGZ
)

type Blob

type Blob struct {
	*TreeEntry
	// contains filtered or unexported fields
}

Blob represents a Git object.

func (*Blob) Data

func (b *Blob) Data() (io.Reader, error)

Data gets content of blob all at once and wrap it as io.Reader. This can be very slow and memory consuming for huge content.

func (*Blob) DataAsync

func (b *Blob) DataAsync() (io.ReadCloser, error)

DataAsync gets a ReadCloser for the contents of a blob without reading it all. Calling the Close function on the result will discard all unread output.

func (*Blob) DataPipeline

func (b *Blob) DataPipeline(stdout, stderr io.Writer) error

DataPipeline gets content of blob and write the result or error to stdout or stderr

type Branch

type Branch struct {
	Name string
	Path string
}

Branch represents a Git branch.

type CheckoutOptions

type CheckoutOptions struct {
	Timeout   time.Duration
	Branch    string
	OldBranch string
}

CheckoutOptions options when heck out some branch

type CloneRepoOptions

type CloneRepoOptions struct {
	Timeout time.Duration
	Mirror  bool
	Bare    bool
	Quiet   bool
	Branch  string
}

CloneRepoOptions options when clone a repository

type Command

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

Command represents a command with its subcommands or arguments.

func NewCommand

func NewCommand(args ...string) *Command

NewCommand creates and returns a new Git Command based on given command and arguments.

func (*Command) AddArguments

func (c *Command) AddArguments(args ...string) *Command

AddArguments adds new argument(s) to the command.

func (*Command) Run

func (c *Command) Run() (string, error)

Run executes the command in defualt working directory and returns stdout in string and error (combined with stderr).

func (*Command) RunInDir

func (c *Command) RunInDir(dir string) (string, error)

RunInDir executes the command in given directory and returns stdout in string and error (combined with stderr).

func (*Command) RunInDirBytes

func (c *Command) RunInDirBytes(dir string) ([]byte, error)

RunInDirBytes executes the command in given directory and returns stdout in []byte and error (combined with stderr).

func (*Command) RunInDirPipeline

func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error

RunInDirPipeline executes the command in given directory, it pipes stdout and stderr to given io.Writer.

func (*Command) RunInDirTimeout

func (c *Command) RunInDirTimeout(timeout time.Duration, dir string) ([]byte, error)

RunInDirTimeout executes the command in given directory with given timeout, and returns stdout in []byte and error (combined with stderr).

func (*Command) RunInDirTimeoutPipeline

func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error

RunInDirTimeoutPipeline executes the command in given directory with given timeout, it pipes stdout and stderr to given io.Writer.

func (*Command) RunTimeout

func (c *Command) RunTimeout(timeout time.Duration) (string, error)

RunTimeout executes the command in defualt working directory with given timeout, and returns stdout in string and error (combined with stderr).

func (*Command) String

func (c *Command) String() string

type Commit

type Commit struct {
	Branch string // Branch this commit belongs to
	Tree
	ID            SHA1 // The ID of this commit object
	Author        *Signature
	Committer     *Signature
	CommitMessage string
	Signature     *CommitGPGSignature
	// contains filtered or unexported fields
}

Commit represents a git commit.

func (*Commit) CommitsBefore

func (c *Commit) CommitsBefore() (*list.List, error)

CommitsBefore returns all the commits before current revision

func (*Commit) CommitsBeforeLimit

func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error)

CommitsBeforeLimit returns num commits before current revision

func (*Commit) CommitsBeforeUntil

func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error)

CommitsBeforeUntil returns the commits between commitID to current revision

func (*Commit) CommitsByRange

func (c *Commit) CommitsByRange(page int) (*list.List, error)

CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize

func (*Commit) CommitsCount

func (c *Commit) CommitsCount() (int64, error)

CommitsCount returns number of total commits of until current revision.

func (*Commit) CreateArchive

func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error

CreateArchive create archive content to the target path

func (*Commit) GetCommitByPath

func (c *Commit) GetCommitByPath(relpath string) (*Commit, error)

GetCommitByPath return the commit of relative path object.

func (*Commit) GetFilesChangedSinceCommit

func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error)

GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision

func (*Commit) GetSubModule

func (c *Commit) GetSubModule(entryname string) (*SubModule, error)

GetSubModule get the sub module according entryname

func (*Commit) GetSubModules

func (c *Commit) GetSubModules() (*ObjectCache, error)

GetSubModules get all the sub modules of current revision git tree

func (*Commit) IsImageFile

func (c *Commit) IsImageFile(name string) bool

IsImageFile is a file image type

func (*Commit) Message

func (c *Commit) Message() string

Message returns the commit message. Same as retrieving CommitMessage directly.

func (*Commit) Parent

func (c *Commit) Parent(n int) (*Commit, error)

Parent returns n-th parent (0-based index) of the commit.

func (*Commit) ParentCount

func (c *Commit) ParentCount() int

ParentCount returns number of parents of the commit. 0 if this is the root commit, otherwise 1,2, etc.

func (*Commit) ParentID

func (c *Commit) ParentID(n int) (SHA1, error)

ParentID returns oid of n-th parent (0-based index). It returns nil if no such parent exists.

func (*Commit) SearchCommits

func (c *Commit) SearchCommits(keyword string, all bool) (*list.List, error)

SearchCommits returns the commits match the keyword before current revision

func (*Commit) Summary

func (c *Commit) Summary() string

Summary returns first line of commit message.

type CommitChangesOptions

type CommitChangesOptions struct {
	Committer *Signature
	Author    *Signature
	Message   string
}

CommitChangesOptions the options when a commit created

type CommitFileStatus

type CommitFileStatus struct {
	Added    []string
	Removed  []string
	Modified []string
}

CommitFileStatus represents status of files in a commit.

func GetCommitFileStatus

func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error)

GetCommitFileStatus returns file status of commit in given repository.

func NewCommitFileStatus

func NewCommitFileStatus() *CommitFileStatus

NewCommitFileStatus creates a CommitFileStatus

type CommitGPGSignature

type CommitGPGSignature struct {
	Signature string
	Payload   string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data
}

CommitGPGSignature represents a git commit signature part.

type CountObject

type CountObject struct {
	Count       int64
	Size        int64
	InPack      int64
	Packs       int64
	SizePack    int64
	PrunePack   int64
	Garbage     int64
	SizeGarbage int64
}

CountObject represents repository count objects report

func GetRepoSize

func GetRepoSize(repoPath string) (*CountObject, error)

GetRepoSize returns disk consumption for repo in path

type DeleteBranchOptions

type DeleteBranchOptions struct {
	Force bool
}

DeleteBranchOptions Option(s) for delete branch

type Entries

type Entries []*TreeEntry

Entries a list of entry

func (Entries) CustomSort

func (tes Entries) CustomSort(cmp func(s1, s2 string) bool)

CustomSort customizable string comparing sort entry list

func (Entries) GetCommitsInfo

func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCommitCache) ([][]interface{}, error)

GetCommitsInfo gets information of all commits that are corresponding to these entries

func (Entries) Sort

func (tes Entries) Sort()

Sort sort the list of entry

type EntryMode

type EntryMode int

EntryMode the type of the object in the git tree

const (
	// EntryModeBlob
	EntryModeBlob EntryMode = 0x0100644
	// EntryModeExec
	EntryModeExec EntryMode = 0x0100755
	// EntryModeSymlink
	EntryModeSymlink EntryMode = 0x0120000
	// EntryModeCommit
	EntryModeCommit EntryMode = 0x0160000
	// EntryModeTree
	EntryModeTree EntryMode = 0x0040000
)

There are only a few file modes in Git. They look like unix file modes, but they can only be one of these.

type ErrBadLink struct {
	Name    string
	Message string
}

ErrBadLink entry.FollowLink error

func (ErrBadLink) Error

func (err ErrBadLink) Error() string

type ErrExecTimeout

type ErrExecTimeout struct {
	Duration time.Duration
}

ErrExecTimeout error when exec timed out

func (ErrExecTimeout) Error

func (err ErrExecTimeout) Error() string

type ErrNotExist

type ErrNotExist struct {
	ID      string
	RelPath string
}

ErrNotExist commit not exist error

func (ErrNotExist) Error

func (err ErrNotExist) Error() string

type ErrUnsupportedVersion

type ErrUnsupportedVersion struct {
	Required string
}

ErrUnsupportedVersion error when required git version not matched

func (ErrUnsupportedVersion) Error

func (err ErrUnsupportedVersion) Error() string

type Hook

type Hook struct {
	IsActive bool   // Indicates whether repository has this hook.
	Content  string // Content of hook if it's active.
	Sample   string // Sample content from Git.
	// contains filtered or unexported fields
}

Hook represents a Git hook.

func GetHook

func GetHook(repoPath, name string) (*Hook, error)

GetHook returns a Git hook by given name and repository.

func ListHooks

func ListHooks(repoPath string) (_ []*Hook, err error)

ListHooks returns a list of Git hooks of given repository.

func (*Hook) Name

func (h *Hook) Name() string

Name return the name of the hook

func (*Hook) Update

func (h *Hook) Update() error

Update updates hook settings.

type LastCommitCache

type LastCommitCache interface {
	Get(repoPath, ref, entryPath string) (*Commit, error)
	Put(repoPath, ref, entryPath string, commit *Commit) error
}

LastCommitCache cache

type ObjectCache

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

ObjectCache provides thread-safe cache opeations.

func (*ObjectCache) Get

func (oc *ObjectCache) Get(id string) (interface{}, bool)

Get get cached obj by id

func (*ObjectCache) Set

func (oc *ObjectCache) Set(id string, obj interface{})

Set add obj to cache

type ObjectType

type ObjectType string

ObjectType git object type

const (
	// ObjectCommit commit object type
	ObjectCommit ObjectType = "commit"
	// ObjectTree tree object type
	ObjectTree ObjectType = "tree"
	// ObjectBlob blob object type
	ObjectBlob ObjectType = "blob"
	// ObjectTag tag object type
	ObjectTag ObjectType = "tag"
)

type PullRemoteOptions

type PullRemoteOptions struct {
	Timeout time.Duration
	All     bool
	Rebase  bool
	Remote  string
	Branch  string
}

PullRemoteOptions options when pull from remote

type PullRequestInfo

type PullRequestInfo struct {
	MergeBase string
	Commits   *list.List
	NumFiles  int
}

PullRequestInfo represents needed information for a pull request.

type PushOptions

type PushOptions struct {
	Remote string
	Branch string
	Force  bool
}

PushOptions options when push to remote

type Reference

type Reference struct {
	Name string

	Object SHA1 // The id of this commit object
	Type   string
	// contains filtered or unexported fields
}

Reference represents a Git ref.

func (*Reference) Commit

func (ref *Reference) Commit() (*Commit, error)

Commit return the commit of the reference

type Repository

type Repository struct {
	Path string
	// contains filtered or unexported fields
}

Repository represents a Git repository.

func OpenRepository

func OpenRepository(repoPath string) (*Repository, error)

OpenRepository opens the repository at the given path.

func (*Repository) AddRemote

func (repo *Repository) AddRemote(name, url string, fetch bool) error

AddRemote adds a new remote to repository.

func (*Repository) CommitsBetween

func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error)

CommitsBetween returns a list that contains commits between [last, before).

func (*Repository) CommitsBetweenIDs

func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error)

CommitsBetweenIDs return commits between twoe commits

func (*Repository) CommitsByFileAndRange

func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error)

CommitsByFileAndRange return the commits accroding revison file and the page

func (*Repository) CommitsCountBetween

func (repo *Repository) CommitsCountBetween(start, end string) (int64, error)

CommitsCountBetween return numbers of commits between two commits

func (*Repository) CreateBranch

func (repo *Repository) CreateBranch(branch, newBranch string) error

CreateBranch create a new branch

func (*Repository) CreateTag

func (repo *Repository) CreateTag(name, revision string) error

CreateTag create one tag in the repository

func (*Repository) DeleteBranch

func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error

DeleteBranch delete a branch by name on repository.

func (*Repository) FileBlame

func (repo *Repository) FileBlame(revision, path, file string) ([]byte, error)

FileBlame return the Blame object of file

func (*Repository) FileCommitsCount

func (repo *Repository) FileCommitsCount(revision, file string) (int64, error)

FileCommitsCount return the number of files at a revison

func (*Repository) FilesCountBetween

func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)

FilesCountBetween return the number of files changed between two commits

func (*Repository) GetBlob

func (repo *Repository) GetBlob(idStr string) (*Blob, error)

GetBlob finds the blob object in the repository.

func (*Repository) GetBranchCommit

func (repo *Repository) GetBranchCommit(name string) (*Commit, error)

GetBranchCommit returns the last commit of given branch.

func (*Repository) GetBranchCommitID

func (repo *Repository) GetBranchCommitID(name string) (string, error)

GetBranchCommitID returns last commit ID string of given branch.

func (*Repository) GetBranches

func (repo *Repository) GetBranches() ([]string, error)

GetBranches returns all branches of the repository.

func (*Repository) GetCommit

func (repo *Repository) GetCommit(commitID string) (*Commit, error)

GetCommit returns commit object of by ID string.

func (*Repository) GetCommitByPath

func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)

GetCommitByPath returns the last commit of relative path.

func (*Repository) GetFormatPatch

func (repo *Repository) GetFormatPatch(base, head string) (io.Reader, error)

GetFormatPatch generates and returns format-patch data between given revisions.

func (*Repository) GetHEADBranch

func (repo *Repository) GetHEADBranch() (*Branch, error)

GetHEADBranch returns corresponding branch of HEAD.

func (*Repository) GetHook

func (repo *Repository) GetHook(name string) (*Hook, error)

GetHook get one hook accroding the name on a repository

func (*Repository) GetMergeBase

func (repo *Repository) GetMergeBase(base, head string) (string, error)

GetMergeBase checks and returns merge base of two branches.

func (*Repository) GetPatch

func (repo *Repository) GetPatch(base, head string) ([]byte, error)

GetPatch generates and returns patch data between given revisions.

func (*Repository) GetPullRequestInfo

func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error)

GetPullRequestInfo generates and returns pull request information between base and head branches of repositories.

func (*Repository) GetRefCommitID

func (repo *Repository) GetRefCommitID(name string) (string, error)

GetRefCommitID returns the last commit ID string of given reference (branch or tag).

func (*Repository) GetRefs

func (repo *Repository) GetRefs() ([]*Reference, error)

GetRefs returns all references of the repository.

func (*Repository) GetRefsFiltered

func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error)

GetRefsFiltered returns all references of the repository that matches patterm exactly or starting with.

func (*Repository) GetTag

func (repo *Repository) GetTag(name string) (*Tag, error)

GetTag returns a Git tag by given name.

func (*Repository) GetTagCommit

func (repo *Repository) GetTagCommit(name string) (*Commit, error)

GetTagCommit get the commit of the specific tag via name

func (*Repository) GetTagCommitID

func (repo *Repository) GetTagCommitID(name string) (string, error)

GetTagCommitID returns last commit ID string of given tag.

func (*Repository) GetTagInfos

func (repo *Repository) GetTagInfos() ([]*Tag, error)

GetTagInfos returns all tag infos of the repository.

func (*Repository) GetTags

func (repo *Repository) GetTags() ([]string, error)

GetTags returns all tags of the repository.

func (*Repository) GetTree

func (repo *Repository) GetTree(idStr string) (*Tree, error)

GetTree find the tree object in the repository.

func (*Repository) Hooks

func (repo *Repository) Hooks() ([]*Hook, error)

Hooks get all the hooks on the repository

func (*Repository) IsBranchExist

func (repo *Repository) IsBranchExist(name string) bool

IsBranchExist returns true if given branch exists in current repository.

func (*Repository) IsTagExist

func (repo *Repository) IsTagExist(name string) bool

IsTagExist returns true if given tag exists in the repository.

func (*Repository) LineBlame

func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error)

LineBlame returns the latest commit at the given line

func (*Repository) RemoveRemote

func (repo *Repository) RemoveRemote(name string) error

RemoveRemote removes a remote from repository.

func (*Repository) SetDefaultBranch

func (repo *Repository) SetDefaultBranch(name string) error

SetDefaultBranch sets default branch of repository.

type SHA1

type SHA1 [20]byte

SHA1 a git commit name

func MustID

func MustID(b []byte) SHA1

MustID always creates a new SHA1 from a [20]byte array with no validation of input.

func MustIDFromString

func MustIDFromString(s string) SHA1

MustIDFromString always creates a new sha from a ID with no validation of input.

func NewID

func NewID(b []byte) (SHA1, error)

NewID creates a new SHA1 from a [20]byte array.

func NewIDFromString

func NewIDFromString(s string) (SHA1, error)

NewIDFromString creates a new SHA1 from a ID string of length 40.

func (SHA1) Equal

func (id SHA1) Equal(s2 interface{}) bool

Equal returns true if s has the same SHA1 as caller. Support 40-length-string, []byte, SHA1.

func (SHA1) String

func (id SHA1) String() string

String returns string (hex) representation of the Oid.

type Signature

type Signature struct {
	Email string
	Name  string
	When  time.Time
}

Signature represents the Author or Committer information.

type SubModule

type SubModule struct {
	Name string
	URL  string
}

SubModule submodule is a reference on git repository

type SubModuleFile

type SubModuleFile struct {
	*Commit
	// contains filtered or unexported fields
}

SubModuleFile represents a file with submodule type.

func NewSubModuleFile

func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile

NewSubModuleFile create a new submodule file

func (*SubModuleFile) RefID

func (sf *SubModuleFile) RefID() string

RefID returns reference ID.

func (*SubModuleFile) RefURL

func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string

RefURL guesses and returns reference URL.

type Tag

type Tag struct {
	Name string
	ID   SHA1

	Object  SHA1 // The id of this commit object
	Type    string
	Tagger  *Signature
	Message string
	// contains filtered or unexported fields
}

Tag represents a Git tag.

func (*Tag) Commit

func (tag *Tag) Commit() (*Commit, error)

Commit return the commit of the tag reference

type Tree

type Tree struct {
	ID SHA1
	// contains filtered or unexported fields
}

Tree represents a flat directory listing.

func NewTree

func NewTree(repo *Repository, id SHA1) *Tree

NewTree create a new tree according the repository and commit id

func (*Tree) GetBlobByPath

func (t *Tree) GetBlobByPath(relpath string) (*Blob, error)

GetBlobByPath get the blob object accroding the path

func (*Tree) GetTreeEntryByPath

func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error)

GetTreeEntryByPath get the tree entries accroding the sub dir

func (*Tree) ListEntries

func (t *Tree) ListEntries() (Entries, error)

ListEntries returns all entries of current tree.

func (*Tree) ListEntriesRecursive

func (t *Tree) ListEntriesRecursive() (Entries, error)

ListEntriesRecursive returns all entries of current tree recursively including all subtrees

func (*Tree) SubTree

func (t *Tree) SubTree(rpath string) (*Tree, error)

SubTree get a sub tree by the sub dir path

type TreeEntry

type TreeEntry struct {
	ID   SHA1
	Type ObjectType
	// contains filtered or unexported fields
}

TreeEntry the leaf in the git tree

func ParseTreeEntries

func ParseTreeEntries(data []byte) ([]*TreeEntry, error)

ParseTreeEntries parses the output of a `git ls-tree` command.

func (*TreeEntry) Blob

func (te *TreeEntry) Blob() *Blob

Blob retrun the blob object the entry

func (te *TreeEntry) FollowLink() (*TreeEntry, error)

FollowLink returns the entry pointed to by a symlink

func (*TreeEntry) GetSubJumpablePathName

func (te *TreeEntry) GetSubJumpablePathName() string

GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )

func (*TreeEntry) IsDir

func (te *TreeEntry) IsDir() bool

IsDir if the entry is a sub dir

func (te *TreeEntry) IsLink() bool

IsLink if the entry is a symlink

func (*TreeEntry) IsSubModule

func (te *TreeEntry) IsSubModule() bool

IsSubModule if the entry is a sub module

func (*TreeEntry) Mode

func (te *TreeEntry) Mode() EntryMode

Mode returns the mode of the entry

func (*TreeEntry) Name

func (te *TreeEntry) Name() string

Name returns the name of the entry

func (*TreeEntry) Size

func (te *TreeEntry) Size() int64

Size returns the size of the entry

Jump to

Keyboard shortcuts

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