git

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 22 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
)
View Source
const ZeroID = git.EmptyID

ZeroID is the zero hash.

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")
	// ErrReferenceNotExist is returned when a reference does not exist.
	ErrReferenceNotExist = git.ErrReferenceNotExist
	// 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

func IsZeroHash added in v0.7.0

func IsZeroHash(h string) bool

IsZeroHash returns whether the hash is a zero hash.

func LatestFile added in v0.5.0

func LatestFile(repo *Repository, ref *Reference, pattern string) (string, string, error)

LatestFile returns the contents of the first file at the specified path pattern in the repository and its file path.

func NewCommand added in v0.5.0

func NewCommand(args ...string) *git.Command

NewCommand creates a new git command.

func UpdateServerInfo added in v0.6.0

func UpdateServerInfo(ctx context.Context, path string) error

UpdateServerInfo updates the server info file for the given repo path.

Types

type Attribute added in v0.6.0

type Attribute struct {
	Name  string
	Value string
}

Attribute represents a Git attribute.

type CloneOptions added in v0.5.0

type CloneOptions = git.CloneOptions

CloneOptions contain options for cloning a repository.

type CommandOptions added in v0.5.0

type CommandOptions = git.CommandOptions

CommandOptions contain options for running a git command.

type Commit

type Commit = git.Commit

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 Reference

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

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

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.

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) CheckAttributes added in v0.6.0

func (r *Repository) CheckAttributes(ref *Reference, path string) ([]Attribute, error)

CheckAttributes checks the attributes of the given ref and 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) Config added in v0.5.0

func (r *Repository) Config() (*gcfg.Config, error)

Config returns the repository Git configuration.

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) LsTree added in v0.5.0

func (r *Repository) LsTree(ref string) (*Tree, error)

LsTree returns the tree for the given reference.

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) SetConfig added in v0.5.0

func (r *Repository) SetConfig(cfg *gcfg.Config) error

SetConfig sets the repository Git configuration.

func (*Repository) StashDiff added in v0.7.0

func (r *Repository) StashDiff(index int) (*Diff, error)

StashDiff returns the diff of the given stash index.

func (*Repository) SymbolicRef added in v0.5.0

func (r *Repository) SymbolicRef(name string, ref string, opts ...git.SymbolicRefOptions) (string, error)

SymbolicRef returns or updates the symbolic reference for the given name. Both name and ref can be empty.

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.

type RunInDirOptions added in v0.5.0

type RunInDirOptions = git.RunInDirOptions

RunInDirOptions are options for RunInDir.

type Tag added in v0.7.0

type Tag = git.Tag

Tag is a git tag.

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