Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Name     string
	FullName string
	Hash     string

	Head     bool
	Ahead    int
	Behind   int
	Upstream *Branch
	// contains filtered or unexported fields
}

Branch is a wrapper of lib.Branch object

func (*Branch) IsRemote

func (b *Branch) IsRemote() bool

IsRemote returns false if it is a local branch

func (*Branch) String added in v0.2.3

func (b *Branch) String() string

func (*Branch) Target added in v0.1.6

func (b *Branch) Target() *Commit

Target is the hash of targeted commit

func (*Branch) Type added in v0.1.6

func (b *Branch) Type() RefType

Type is the reference type of this ref

type Commit

type Commit struct {
	Author  *Signature
	Message string
	Summary string
	Hash    string
	// contains filtered or unexported fields
}

Commit is the wrapper of actual lib.Commit object

func (*Commit) Amend added in v0.2.3

func (c *Commit) Amend(message string, author ...*Signature) (*Commit, error)

Amend updates the commit and returns NEW commit pointer

func (*Commit) Diff added in v0.2.3

func (c *Commit) Diff() (*Diff, error)

Diff has similar behavior to "git diff <commit>"

func (*Commit) ParentID added in v0.2.3

func (c *Commit) ParentID() (string, error)

ParentID returns the commits parent hash.

func (*Commit) String

func (c *Commit) String() string

type DeltaStatus added in v0.2.3

type DeltaStatus int

DeltaStatus ondicates a files status in a diff

const (
	DeltaUnmodified DeltaStatus = iota
	DeltaAdded
	DeltaDeleted
	DeltaModified
	DeltaRenamed
	DeltaCopied
	DeltaIgnored
	DeltaUntracked
	DeltaTypeChange
	DeltaUnreadable
	DeltaConflicted
)

Delta status of a file e.g. on a commit

type Diff

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

Diff is the wrapper for a diff content acquired from repo

func (*Diff) Deltas

func (d *Diff) Deltas() []*DiffDelta

Deltas returns the actual changes with file info

type DiffDelta

type DiffDelta struct {
	Status  DeltaStatus
	OldFile *DiffFile
	NewFile *DiffFile
	Patch   string
	Commit  *Commit
}

DiffDelta holds delta status, file changes and the actual patchs

func (*DiffDelta) DeltaStatusString added in v0.2.3

func (d *DiffDelta) DeltaStatusString() string

DeltaStatusString retruns delta status as string

func (*DiffDelta) String

func (d *DiffDelta) String() string

type DiffFile

type DiffFile struct {
	Path string
	Hash string
}

DiffFile the file that has been changed

type Error added in v0.2.5

type Error string

Error is the errors from the git package

var (
	// ErrAuthenticationRequired as the name implies
	ErrAuthenticationRequired Error = "authentication required"
	// ErrAuthenticationType means that given credentials cannot be used for given repository url
	ErrAuthenticationType Error = "authentication method is not valid"
	// ErrClone is a generic clone error
	ErrClone Error = "cannot clone repo"
	// ErrCannotOpenRepo is returned when the repo couldn't be loaded from filesystem
	ErrCannotOpenRepo Error = "cannot load repository"
	// ErrCreateCallbackFail is returned when an error occurred while creating callbacks
	ErrCreateCallbackFail Error = "cannot create default callbacks"
	// ErrNoRemoteName if the remote name is empty while fetching
	ErrNoRemoteName Error = "remote name not specified"
	// ErrNotValidRemoteName is returned if the given remote name is not found
	ErrNotValidRemoteName Error = "not a valid remote name"
	// ErrAlreadyUpToDate if the repo is up-to-date
	ErrAlreadyUpToDate Error = "already up-to-date"
	// ErrFastForwardOnly if the merge can be made by fast-forward
	ErrFastForwardOnly Error = "fast-forward only"
	// ErrBranchNotFound is returned when the given ref can't found
	ErrBranchNotFound Error = "cannot locate remote-tracking branch"
	// ErrEntryNotIndexed is returned when the entry is not indexed
	ErrEntryNotIndexed Error = "entry is not indexed"
)

func (Error) Error added in v0.2.5

func (e Error) Error() string

type IndexType

type IndexType int

IndexType describes the different stages a status entry can be in

const (
	IndexTypeStaged IndexType = iota
	IndexTypeUnstaged
	IndexTypeUntracked
	IndexTypeConflicted
)

The different status stages

type Ref added in v0.1.6

type Ref interface {
	Type() RefType
	Target() *Commit
	String() string
}

Ref is the wrapper of lib.Ref

type RefType added in v0.1.6

type RefType uint8

RefType defines the ref types

const (
	RefTypeTag RefType = iota
	RefTypeBranch
	RefTypeHEAD
)

These types are used for mapping references

type Repository

type Repository struct {
	RefMap map[string][]Ref
	Head   *Branch
	// contains filtered or unexported fields
}

Repository is the wrapper and main interface to git repository

func Open

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

Open load the repository from the filesystem

func (*Repository) AddToIndex added in v0.2.3

func (r *Repository) AddToIndex(e *StatusEntry) error

AddToIndex is the wrapper of "git add /path/to/file" command

func (*Repository) Branches

func (r *Repository) Branches() ([]*Branch, error)

Branches loads branches with the lib's branch iterator loads both remote and local branches

func (*Repository) Commit added in v0.2.3

func (r *Repository) Commit(message string, author ...*Signature) (*Commit, error)

Commit adds a new commit onject to repository warning: this function does not check if the changes are indexed

func (*Repository) Commits

func (r *Repository) Commits() ([]*Commit, error)

Commits returns all of the commits of the repository

func (*Repository) CommitsChan added in v0.3.0

func (r *Repository) CommitsChan(size int) (chan *Commit, error)

Commits returns commits as channel with given size

func (*Repository) LoadHead added in v0.2.3

func (r *Repository) LoadHead() error

LoadHead can be used to refresh HEAD ref

func (*Repository) LoadStatus added in v0.2.3

func (r *Repository) LoadStatus() (*Status, error)

LoadStatus simply emulates a "git status" and returns the result

func (*Repository) Path added in v0.2.3

func (r *Repository) Path() string

Path returns the filesystem location of the repository

func (*Repository) RemoveFromIndex added in v0.2.3

func (r *Repository) RemoveFromIndex(e *StatusEntry) error

RemoveFromIndex is the wrapper of "git reset path/to/file" command

func (*Repository) Tags

func (r *Repository) Tags() ([]*Tag, error)

Tags loads tags from the refs

type Signature added in v0.2.3

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

Signature is the person who signs a commit

type State

type State int

State is the current state of the repository

const (
	StateUnknown State = iota
	StateNone
	StateMerge
	StateRevert
	StateCherrypick
	StateBisect
	StateRebase
	StateRebaseInteractive
	StateRebaseMerge
	StateApplyMailbox
	StateApplyMailboxOrRebase
)

The different states for a repo

type Status

type Status struct {
	State    State
	Entities []*StatusEntry
}

Status contains all git status data

type StatusEntry

type StatusEntry struct {
	EntryType StatusEntryType
	// contains filtered or unexported fields
}

StatusEntry contains data for a single status entry

func (*StatusEntry) Indexed

func (e *StatusEntry) Indexed() bool

Indexed true if entry added to index

func (*StatusEntry) StatusEntryString

func (e *StatusEntry) StatusEntryString() string

StatusEntryString returns entry status in pretty format

func (*StatusEntry) String

func (e *StatusEntry) String() string

Indexed true if entry added to index

type StatusEntryType

type StatusEntryType int

StatusEntryType describes the type of change a status entry has undergone

const (
	StatusEntryTypeNew StatusEntryType = iota
	StatusEntryTypeModified
	StatusEntryTypeDeleted
	StatusEntryTypeRenamed
	StatusEntryTypeUntracked
	StatusEntryTypeTypeChange
	StatusEntryTypeConflicted
)

The set of supported StatusEntryTypes

type Tag

type Tag struct {
	Hash      string
	Shorthand string
	Name      string
	// contains filtered or unexported fields
}

Tag is used to label and mark a specific commit in the history.

func (*Tag) String added in v0.2.3

func (t *Tag) String() string

func (*Tag) Target

func (t *Tag) Target() *Commit

Target is the hash of targeted commit

func (*Tag) Type added in v0.1.6

func (t *Tag) Type() RefType

Type is the reference type of this ref

Jump to

Keyboard shortcuts

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