func (r *Repository) AddToIndex(e *StatusEntry) error {
	index, err := r.essence.Index()
	if err != nil {
		return err
	}
	if err := index.AddByPath(e.diffDelta.OldFile.Path); err != nil {
		return err
	}
	defer index.Free()
	return index.Write()
}
AddToIndex is the wrapper of "git add /path/to/file" command
package git
import (
	lib "github.com/libgit2/git2go/v30"
)
type State int
const (
	StateUnknown State = iota
	StateNone
	StateMerge
	StateRevert
	StateCherrypick
	StateBisect
	StateRebase
	StateRebaseInteractive
	StateRebaseMerge
	StateApplyMailbox
	StateApplyMailboxOrRebase
)
type DeltaStatus int
const (
	DeltaUnmodified DeltaStatus = iota
	DeltaAdded
	DeltaDeleted
	DeltaModified
	DeltaRenamed
	DeltaCopied
	DeltaIgnored
	DeltaUntracked
	DeltaTypeChange
	DeltaUnreadable
	DeltaConflicted
)
type IndexType int
const (
	IndexTypeStaged IndexType = iota
	IndexTypeUnstaged
	IndexTypeUntracked
	IndexTypeConflicted
)
type StatusEntryType int
const (
	StatusEntryTypeNew StatusEntryType = iota
	StatusEntryTypeModified
	StatusEntryTypeDeleted
	StatusEntryTypeRenamed
	StatusEntryTypeUntracked
	StatusEntryTypeTypeChange
	StatusEntryTypeConflicted
)
var indexTypeMap = map[lib.Status]IndexType{
	lib.StatusIndexNew | lib.StatusIndexModified | lib.StatusIndexDeleted | lib.StatusIndexRenamed | lib.StatusIndexTypeChange: IndexTypeStaged,
	lib.StatusWtModified | lib.StatusWtDeleted | lib.StatusWtTypeChange | lib.StatusWtRenamed:                                  IndexTypeUnstaged,
	lib.StatusWtNew:      IndexTypeUntracked,
	lib.StatusConflicted: IndexTypeConflicted,
}
var statusEntryTypeMap = map[lib.Status]StatusEntryType{
	lib.StatusIndexNew:        StatusEntryTypeNew,
	lib.StatusIndexModified:   StatusEntryTypeModified,
	lib.StatusWtModified:      StatusEntryTypeModified,
	lib.StatusIndexDeleted:    StatusEntryTypeDeleted,
	lib.StatusWtDeleted:       StatusEntryTypeDeleted,
	lib.StatusIndexRenamed:    StatusEntryTypeRenamed,
	lib.StatusWtRenamed:       StatusEntryTypeRenamed,
	lib.StatusIndexTypeChange: StatusEntryTypeTypeChange,
	lib.StatusWtTypeChange:    StatusEntryTypeTypeChange,
	lib.StatusWtNew:           StatusEntryTypeUntracked,
	lib.StatusConflicted:      StatusEntryTypeConflicted,
}
type StatusEntry struct {
	index     IndexType
	EntryType StatusEntryType
	diffDelta *DiffDelta
}
type Status struct {
	State    State
	Entities []*StatusEntry
}
type Diff struct {
	deltas []*DiffDelta
	stats  []string
	patchs []string
}
func (d *Diff) Deltas() []*DiffDelta {
	return d.deltas
}
type DiffDelta struct {
	Status  DeltaStatus
	OldFile *DiffFile
	NewFile *DiffFile
	Patch   string
	Commit  *Commit
}
type DiffFile struct {
	Path string
	Hash string
}
func (d *DiffDelta) String() string {
	return d.OldFile.Path
}
func (r *Repository) LoadStatus() (*Status, error) {
	statusOptions := &lib.StatusOptions{
		Show:  lib.StatusShowIndexAndWorkdir,
		Flags: lib.StatusOptIncludeUntracked,
	}
	statusList, err := r.essence.StatusList(statusOptions)
	if err != nil {
		return nil, err
	}
	defer statusList.Free()
	count, err := statusList.EntryCount()
	if err != nil {
		return nil, err
	}
	entities := make([]*StatusEntry, 0)
	s := &Status{
		State:    State(r.essence.State()),
		Entities: entities,
	}
	for i := 0; i < count; i++ {
		statusEntry, err := statusList.ByIndex(i)
		if err != nil {
			return nil, err
		}
		if statusEntry.Status <= 0 {
			continue
		}
		s.addToStatus(statusEntry)
	}
	return s, nil
}
func (s *Status) addToStatus(raw lib.StatusEntry) {
	for rawStatus, indexType := range indexTypeMap {
		set := raw.Status & rawStatus
		if set > 0 {
			var dd lib.DiffDelta
			if indexType == IndexTypeStaged {
				dd = raw.HeadToIndex
			} else {
				dd = raw.IndexToWorkdir
			}
			d := &DiffDelta{
				Status: DeltaStatus(dd.Status),
				NewFile: &DiffFile{
					Path: dd.NewFile.Path,
				},
				OldFile: &DiffFile{
					Path: dd.OldFile.Path,
				},
			}
			e := &StatusEntry{
				index:     indexType,
				EntryType: statusEntryTypeMap[set],
				diffDelta: d,
			}
			s.Entities = append(s.Entities, e)
		}
	}
}
func (e *StatusEntry) String() string {
	return e.diffDelta.OldFile.Path
}
func (e *StatusEntry) Indexed() bool {
	return e.index == IndexTypeStaged
}
func (e *StatusEntry) StatusEntryString() string {
	switch e.EntryType {
	case StatusEntryTypeNew:
		return "Added"
	case StatusEntryTypeDeleted:
		return "Deleted"
	case StatusEntryTypeModified:
		return "Modified"
	case StatusEntryTypeRenamed:
		return "Renamed"
	case StatusEntryTypeUntracked:
		return "Untracked"
	case StatusEntryTypeTypeChange:
		return "Type change"
	case StatusEntryTypeConflicted:
		return "Conflicted"
	default:
		return "Unknown"
	}
}