git

package
v0.0.0-...-d1209a5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DIFF_LINE_PLAIN = iota + 1
	DIFF_LINE_ADD
	DIFF_LINE_DEL
	DIFF_LINE_SECTION
)

Diff line types.

View Source
const (
	DIFF_FILE_ADD = iota + 1
	DIFF_FILE_CHANGE
	DIFF_FILE_DEL
)
View Source
const DIFF_HEAD = "diff --git "

Variables

View Source
var (
	ErrNotExist = errors.New("error not exist")
)
View Source
var (
	ErrNotValidHook = errors.New("not a valid Git hook")
)
View Source
var (
	IdNotExist = errors.New("sha1 id not exist")
)

Functions

func IsBranchExist

func IsBranchExist(repoPath, branchName string) bool

func IsTagExist

func IsTagExist(repoPath, tagName string) bool

func IsValidHookName

func IsValidHookName(name string) bool

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

func NewId

func NewId(b []byte) (sha1, error)

Create a new sha1 from a 20 byte slice.

func NewIdFromString

func NewIdFromString(s string) (sha1, error)

Create a new sha1 from a Sha1 string of length 40.

func RefEndName

func RefEndName(refStr string) string

Types

type ArchiveType

type ArchiveType int
const (
	ZIP ArchiveType = iota + 1
	TARGZ
)

type Blob

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

func (*Blob) Data

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

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) CommitsBefore

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

func (*Commit) CommitsBeforeUntil

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

func (*Commit) CommitsByRange

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

func (*Commit) CommitsCount

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

func (*Commit) CreateArchive

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

func (*Commit) GetCommitOfRelPath

func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error)

func (*Commit) GetSubModule

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

func (*Commit) GetSubModules

func (c *Commit) GetSubModules() (map[string]*SubModule, error)

func (*Commit) Message

func (c *Commit) Message() string

Return the commit message. Same as retrieving CommitMessage directly.

func (*Commit) Parent

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

Return parent number n (0-based index)

func (*Commit) ParentCount

func (c *Commit) ParentCount() int

Return the number of parents of the commit. 0 if this is the root commit, otherwise 1,2,...

func (*Commit) ParentId

func (c *Commit) ParentId(n int) (id sha1, err error)

Return oid of the parent number n (0-based index). Return nil if no such parent exists.

func (*Commit) SearchCommits

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

func (*Commit) Summary

func (c *Commit) Summary() string

type Diff

type Diff struct {
	TotalAddition, TotalDeletion int
	Files                        []*DiffFile
}

func (*Diff) NumFiles

func (diff *Diff) NumFiles() int

type DiffFile

type DiffFile struct {
	Name               string
	Index              int
	Addition, Deletion int
	Type               int
	IsCreated          bool
	IsDeleted          bool
	IsBin              bool
}

type Entries

type Entries []*TreeEntry

func (Entries) Len

func (bs Entries) Len() int

func (Entries) Less

func (bs Entries) Less(i, j int) bool

func (Entries) Sort

func (bs Entries) Sort()

func (Entries) Swap

func (bs Entries) Swap(i, j int)

type EntryMode

type EntryMode int
const (
	ModeBlob    EntryMode = 0100644
	ModeExec    EntryMode = 0100755
	ModeSymlink EntryMode = 0120000
	ModeCommit  EntryMode = 0160000
	ModeTree    EntryMode = 0040000
)

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

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

func (*Hook) Update

func (h *Hook) Update() error

Update updates hook settings.

type ObjectType

type ObjectType string
const (
	COMMIT ObjectType = "commit"
	TREE   ObjectType = "tree"
	BLOB   ObjectType = "blob"
	TAG    ObjectType = "tag"
)

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) Checkout

func (r *Repository) Checkout(commit string)

func (*Repository) CommitsBetween

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

used only for single tree, (]

func (*Repository) CommitsByFileAndRange

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

func (*Repository) CommitsCount

func (repo *Repository) CommitsCount(commitId string) (int, error)

func (*Repository) CreateTag

func (repo *Repository) CreateTag(tagName, idStr string) error

func (*Repository) FileCommitsCount

func (repo *Repository) FileCommitsCount(branch, file string) (int, 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) GetCommitsSinceLastUpdate

func (r *Repository) GetCommitsSinceLastUpdate(branch, latestCommit string) ([]*Commit, error)

func (*Repository) GetDiffCommit

func (r *Repository) GetDiffCommit(commitId string) (*Diff, error)

func (*Repository) GetDiffRange

func (r *Repository) GetDiffRange(beforeCommitId string, afterCommitId string) (*Diff, error)

func (*Repository) GetFilesChangedSinceUpdate

func (r *Repository) GetFilesChangedSinceUpdate(branch, latestCommit string) (*Diff, error)

func (*Repository) GetFilesChangedSinceUpdateRange

func (r *Repository) GetFilesChangedSinceUpdateRange(start, end string) (*Diff, error)

func (*Repository) GetHook

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

func (*Repository) GetRecentCommits

func (r *Repository) GetRecentCommits(branch string) ([]*Commit, error)

func (*Repository) GetTag

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

GetTag returns a Git tag by given name.

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) Hooks

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

func (*Repository) IsBranchExist

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

func (*Repository) IsTagExist

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

func (*Repository) UpdateGitRepo

func (r *Repository) UpdateGitRepo(branch string) error

type Signature

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

Author and Committer information

type SubModule

type SubModule struct {
	Name string
	Url  string
}

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

func (*SubModuleFile) RefId

func (sf *SubModuleFile) RefId() string

RefId returns reference ID.

func (*SubModuleFile) RefUrl

func (sf *SubModuleFile) RefUrl() 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
	TagMessage string
	// contains filtered or unexported fields
}

Tag represents a Git tag.

func (*Tag) Commit

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

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) GetBlobByPath

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

func (*Tree) GetTreeEntryByPath

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

func (*Tree) ListEntries

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

func (*Tree) SubTree

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

type TreeEntry

type TreeEntry struct {
	Id   sha1
	Type ObjectType
	// contains filtered or unexported fields
}

func (*TreeEntry) Blob

func (te *TreeEntry) Blob() *Blob

func (*TreeEntry) EntryMode

func (te *TreeEntry) EntryMode() EntryMode

func (*TreeEntry) IsDir

func (te *TreeEntry) IsDir() bool

func (*TreeEntry) IsSubModule

func (te *TreeEntry) IsSubModule() bool

func (*TreeEntry) Name

func (te *TreeEntry) Name() string

func (*TreeEntry) Size

func (te *TreeEntry) Size() int64

type Version

type Version struct {
	Major, Minor, Patch int
}

Version represents version of Git.

func GetVersion

func GetVersion() (*Version, error)

GetVersion returns current Git version installed.

func MustParseVersion

func MustParseVersion(verStr string) *Version

func ParseVersion

func ParseVersion(verStr string) (*Version, error)

func (*Version) AtLeast

func (v *Version) AtLeast(that *Version) bool

func (*Version) Compare

func (v *Version) Compare(that *Version) int

Compare compares two versions, it returns 1 if original is greater, -1 if original is smaller, 0 if equal.

func (*Version) LessThan

func (v *Version) LessThan(that *Version) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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