git

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HEAD represents the name of the HEAD reference.
	HEAD = "HEAD"
	// RefsHeads represents the prefix for branch references.
	RefsHeads = git.RefsHeads
	// RefsTags represents the prefix for tag references.
	RefsTags = git.RefsTags
)

Variables

View Source
var (
	// ErrFileNotFound is returned when a file is not found.
	ErrFileNotFound = errors.New("file not found")
	// ErrDirectoryNotFound is returned when a directory is not found.
	ErrDirectoryNotFound = errors.New("directory not found")
	// ErrReferenceNotFound is returned when a reference is not found.
	ErrReferenceNotFound = errors.New("reference not found")
	// ErrRevisionNotExist is returned when a revision is not found.
	ErrRevisionNotExist = git.ErrRevisionNotExist
	// ErrNotAGitRepository is returned when the given path is not a Git repository.
	ErrNotAGitRepository = errors.New("not a git repository")
)
View Source
var (
	// DiffMaxFile is the maximum number of files to show in a diff.
	DiffMaxFiles = 1000
	// DiffMaxFileLines is the maximum number of lines to show in a file diff.
	DiffMaxFileLines = 1000
	// DiffMaxLineChars is the maximum number of characters to show in a line diff.
	DiffMaxLineChars = 1000
)

Functions

func Clone

func Clone(src, dst string, opts ...git.CloneOptions) error

Clone clones a repository.

func IsBinary

func IsBinary(r io.Reader) (bool, error)

IsBinary detects if data is a binary value based on: http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198

Types

type Commit

type Commit struct {
	*git.Commit
	Hash Hash
}

Commit is a wrapper around git.Commit with helper methods.

type Commits

type Commits []*Commit

Commits is a list of commits.

func (Commits) Len

func (cl Commits) Len() int

Len implements sort.Interface.

func (Commits) Less

func (cl Commits) Less(i, j int) bool

Less implements sort.Interface.

func (Commits) Swap

func (cl Commits) Swap(i, j int)

Swap implements sort.Interface.

type Diff

type Diff struct {
	*git.Diff
	Files []*DiffFile
}

Diff is a wrapper around git.Diff with helper methods.

func (*Diff) Patch

func (d *Diff) Patch() string

Patch returns the diff as a patch.

func (*Diff) Stats

func (d *Diff) Stats() FileStats

FileStats returns the diff file stats.

type DiffFile

type DiffFile struct {
	*git.DiffFile
	Sections []*DiffSection
}

DiffFile is a wrapper to git.DiffFile with helper methods.

func (*DiffFile) Files

func (f *DiffFile) Files() (from *DiffFileChange, to *DiffFileChange)

Files returns the diff files.

type DiffFileChange

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

DiffFileChange represents a file diff.

func (*DiffFileChange) Hash

func (f *DiffFileChange) Hash() string

Hash returns the diff file hash.

func (*DiffFileChange) Mode

func (f *DiffFileChange) Mode() git.EntryMode

Mode returns the diff file mode.

func (*DiffFileChange) Name

func (f *DiffFileChange) Name() string

Name returns the diff name.

type DiffSection

type DiffSection struct {
	*git.DiffSection
	// contains filtered or unexported fields
}

DiffSection is a wrapper to git.DiffSection with helper methods.

type Entries

type Entries []*TreeEntry

Entries is a wrapper around git.Entries.

func (Entries) Len

func (es Entries) Len() int

Len implements sort.Interface.

func (Entries) Less

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

Less implements sort.Interface.

func (Entries) Sort

func (es Entries) Sort()

Sort sorts the entries in the tree.

func (Entries) Swap

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

Swap implements sort.Interface.

type File

type File struct {
	*git.Blob
	Entry *TreeEntry
}

File is a wrapper around git.Blob with helper methods.

func (*File) Contents

func (f *File) Contents() ([]byte, error)

Contents returns the contents of the file.

func (*File) IsBinary

func (f *File) IsBinary() (bool, error)

IsBinary returns true if the file is binary.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file.

func (*File) Path

func (f *File) Path() string

Path returns the full path of the file.

type FileStats

type FileStats []*DiffFile

FileStats

func (FileStats) String

func (fs FileStats) String() string

String returns a string representation of file stats.

type Hash

type Hash string

Hash represents a git hash.

var (
	ZeroHash Hash = git.EmptyID
)

func (Hash) SHA1

func (h Hash) SHA1() *git.SHA1

SHA1 represents the hash as a SHA1.

func (Hash) String

func (h Hash) String() string

String returns the string representation of a hash as a string.

type Reference

type Reference struct {
	*git.Reference
	Hash Hash
	// contains filtered or unexported fields
}

Reference is a wrapper around git.Reference with helper methods.

func NewReference

func NewReference(rp, refspec string) *Reference

NewReference creates a new reference.

func (*Reference) IsBranch

func (r *Reference) IsBranch() bool

IsBranch returns true if the reference is a branch.

func (*Reference) IsTag

func (r *Reference) IsTag() bool

IsTag returns true if the reference is a tag.

func (*Reference) Name

func (r *Reference) Name() ReferenceName

Name returns the reference name i.e. refs/heads/master.

func (*Reference) TargetHash

func (r *Reference) TargetHash() Hash

TargetHash returns the hash of the reference target.

type ReferenceName

type ReferenceName string

ReferenceName is a Refspec wrapper.

func (ReferenceName) Short

func (r ReferenceName) Short() string

Short returns the short name of the reference i.e. master.

func (ReferenceName) String

func (r ReferenceName) String() string

String returns the reference name i.e. refs/heads/master.

type Repository

type Repository struct {
	*git.Repository
	Path   string
	IsBare bool
}

Repository is a wrapper around git.Repository with helper methods.

func Init

func Init(path string, bare bool) (*Repository, error)

Init initializes and opens a new git repository.

func Open

func Open(path string) (*Repository, error)

Open opens a git repository at the given path.

func (*Repository) CommitsByPage

func (r *Repository) CommitsByPage(ref *Reference, page, size int) (Commits, error)

CommitsByPage returns the commits for a given page and size.

func (*Repository) CountCommits

func (r *Repository) CountCommits(ref *Reference) (int64, error)

CountCommits returns the number of commits in the repository.

func (*Repository) Diff

func (r *Repository) Diff(commit *Commit) (*Diff, error)

Diff returns the diff for the given commit.

func (*Repository) HEAD

func (r *Repository) HEAD() (*Reference, error)

HEAD returns the HEAD reference for a repository.

func (*Repository) Name

func (r *Repository) Name() string

Name returns the name of the repository.

func (*Repository) Patch

func (r *Repository) Patch(commit *Commit) (string, error)

Patch returns the patch for the given reference.

func (*Repository) References

func (r *Repository) References() ([]*Reference, error)

References returns the references for a repository.

func (*Repository) Tree

func (r *Repository) Tree(ref *Reference) (*Tree, error)

Tree returns the tree for the given reference.

func (*Repository) TreePath

func (r *Repository) TreePath(ref *Reference, path string) (*Tree, error)

TreePath returns the tree for the given path.

func (*Repository) UpdateServerInfo

func (r *Repository) UpdateServerInfo() error

UpdateServerInfo updates the repository server info.

type Tree

type Tree struct {
	*git.Tree
	Path       string
	Repository *Repository
}

Tree is a wrapper around git.Tree with helper methods.

func (*Tree) Entries

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

Entries returns the entries in the tree.

func (*Tree) SubTree

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

SubTree returns the sub-tree at the given path.

func (*Tree) TreeEntry

func (t *Tree) TreeEntry(path string) (*TreeEntry, error)

TreeEntry returns the TreeEntry for the file path.

type TreeEntry

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

TreeEntry is a wrapper around git.TreeEntry with helper methods.

func (*TreeEntry) Contents

func (e *TreeEntry) Contents() ([]byte, error)

Contents returns the contents of the file.

func (*TreeEntry) File

func (e *TreeEntry) File() *File

File returns the file for the TreeEntry.

func (*TreeEntry) Mode

func (e *TreeEntry) Mode() fs.FileMode

Mode returns the mode of the file in fs.FileMode format.

Jump to

Keyboard shortcuts

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