Documentation ¶
Index ¶
- Constants
- Variables
- func AuthorEmail() string
- func AuthorName() string
- func CommitterEmail() string
- func CommitterName() string
- func Configure(opts ...Opt) error
- func CreateBranch(name string) error
- func CurrentBranch() (string, error)
- func DefaultBranch() string
- func DeleteBranch(name string) error
- func Editor() (string, []string)
- func EditorFile() string
- func GitHeadPath() string
- func GitPath() string
- func IndexFilePath() string
- func Init() error
- func IsIgnored(path string, rules [][]byte) bool
- func ListBranches() ([]string, error)
- func ObjectPackfileDirectory() string
- func ObjectPath() string
- func ObjectReadCloser(sha []byte) func() (io.ReadCloser, error)
- func PackedRefsFile() string
- func Pager() (string, []string)
- func Path() string
- func ReadHeadBytes(r io.ReadCloser, obj *Object) error
- func RefsDirectory() string
- func RefsHeadPrefix() string
- func RefsHeadsDirectory() string
- func Restore(path string, staged bool) error
- func RestoreStaged(path string) error
- func SwitchBranch(name string) ([]string, error)
- func UpdateBranchHead(branch string, sha Sha) error
- func UpdateHead(branch string) error
- func WorkingDirectory() string
- type Cnf
- type Commit
- type FfileSet
- type FileStatus
- type Finfo
- type Index
- type IndexStatus
- type Mtime
- type Object
- type Opt
- type PackObjectType
- type Sha
- func CreateCommit(commit *Commit) (Sha, error)
- func CurrentCommit() (Sha, error)
- func HeadSHA(currentBranch string) (Sha, error)
- func NewSha(b []byte) (Sha, error)
- func PreviousCommits() ([]Sha, error)
- func ShaFromHexString(s string) (Sha, error)
- func WriteObject(header []byte, content []byte, contentFile string, path string) (Sha, error)
- type Tree
- type TreeItem
- type WDStatus
Constants ¶
const ( DefaultGitDirectory = ".git" DefaultPath = "." DefaultHeadFile = "HEAD" DefaultIndexFile = "index" DefaultObjectsDirectory = "objects" DefaultRefsDirectory = "refs" DefaultRefsHeadsDirectory = "heads" DefaultBranchName = "main" DefaultEditor = "vim" DefaultPackedRefsFile = "info/refs" DefaultPackfileDirectory = "pack" DefaultGitIgnoreFileName = ".gitignore" )
const ( ObjectTypeInvalid objectType = iota ObjectTypeBlob ObjectTypeTree ObjectTypeCommit )
Variables ¶
var PackFileReadCloser = func(path string, offset int64) func() (io.ReadCloser, error) { return func() (io.ReadCloser, error) { fh, err := os.Open(path) if err != nil { return nil, err } defer func() { _ = fh.Close() }() _, err = fh.Seek(offset, io.SeekStart) if err != nil { return nil, err } return zlib.NewReader(fh) } }
PackFileReadCloser is a Factory that creates a ReadCloser for reading Object content from a Pack File that is Not Deltified.
var PackFileReadCloserOfsDelta = func(path string, offset int64) func() (io.ReadCloser, error) { return func() (io.ReadCloser, error) { return nil, errors.New("not implemented") } }
var PackFileReadCloserRefDelta = func(path string, offset int64) func() (io.ReadCloser, error) { return func() (io.ReadCloser, error) { return nil, errors.New("not implemented") } }
Functions ¶
func AuthorEmail ¶
func AuthorEmail() string
func AuthorName ¶
func AuthorName() string
func CommitterEmail ¶
func CommitterEmail() string
func CommitterName ¶
func CommitterName() string
func CreateBranch ¶
func CurrentBranch ¶
CurrentBranch returns the name of the current branch
func DefaultBranch ¶
func DefaultBranch() string
func DeleteBranch ¶
func EditorFile ¶
func EditorFile() string
func GitHeadPath ¶
func GitHeadPath() string
func IndexFilePath ¶
func IndexFilePath() string
func ListBranches ¶
ListBranches lists Git branches from refs/heads and info/refs It does not currently allow listing remote tracking branches
func ObjectPackfileDirectory ¶
func ObjectPackfileDirectory() string
func ObjectPath ¶
func ObjectPath() string
func ObjectReadCloser ¶
func ObjectReadCloser(sha []byte) func() (io.ReadCloser, error)
func PackedRefsFile ¶
func PackedRefsFile() string
func ReadHeadBytes ¶
func ReadHeadBytes(r io.ReadCloser, obj *Object) error
func RefsDirectory ¶
func RefsDirectory() string
func RefsHeadPrefix ¶
func RefsHeadPrefix() string
func RefsHeadsDirectory ¶
func RefsHeadsDirectory() string
func RestoreStaged ¶
RestoreStaged removes a staged change from the index. If the file is in the previous commit, removing it from the index means updating the index to specify the commit sha. The timestamp for which would be the same as when the files were originally switched to.
If the file is not in a previous commit, removing it from the index means simply removing it from the index.
func SwitchBranch ¶
func UpdateBranchHead ¶
UpdateBranchHead updates the sha hash pointed to by a branch
func UpdateHead ¶
UpdateHead writes branch name as a reference in the Git HEAD file
func WorkingDirectory ¶
func WorkingDirectory() string
Types ¶
type Cnf ¶
type Cnf struct { // GitDirector configures where the name of the git directory // This is usually .git GitDirectory string // Path configures where the Git Directory to interact with is // relative to the present working directory. This is usually . Path string HeadFile string IndexFile string ObjectsDirectory string RefsDirectory string RefsHeadsDirectory string PackedRefsFile string PackfileDirectory string DefaultBranch string GitIgnore [][]byte Editor string EditorArgs []string GitIgnoreFileName string }
type Commit ¶
type Commit struct { Sha Sha Tree Sha Parents []Sha Author string AuthorEmail string AuthoredTime time.Time Committer string CommitterEmail string CommittedTime time.Time Sig []byte Message []byte }
func ReadCommit ¶
type FfileSet ¶
type FfileSet struct {
// contains filtered or unexported fields
}
func CurrentStatus ¶
func FsStatus ¶
FsStatus returns a FfileSet containing all files from the index and working directory with the corresponding status.
func NewFfileSet ¶
func NewFfileSet(c []*FileStatus, i []*FileStatus, w []*FileStatus) (*FfileSet, error)
func Status ¶
Status returns a FfileSet containing all files from commit, index and working directory with the corresponding status.
func (*FfileSet) Files ¶
func (f *FfileSet) Files() []*FileStatus
type FileStatus ¶
type FileStatus struct {
// contains filtered or unexported fields
}
func CommittedFiles ¶
func CommittedFiles(sha Sha) ([]*FileStatus, error)
func Ls ¶
func Ls(path string) ([]*FileStatus, error)
Ls recursively lists files in path that are not ignored
func (FileStatus) IndexStatus ¶
func (f FileStatus) IndexStatus() IndexStatus
func (FileStatus) Path ¶
func (f FileStatus) Path() string
func (FileStatus) WorkingDirectoryStatus ¶
func (f FileStatus) WorkingDirectoryStatus() WDStatus
type Finfo ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index represents the Git Index
func (*Index) Add ¶
func (idx *Index) Add(f *FileStatus) error
Add adds a fs.FileStatus to the Index Struct. A call to idx.Write is required to flush the changes to the filesystem.
func (*Index) File ¶
func (idx *Index) File(path string) *FileStatus
type IndexStatus ¶
type IndexStatus uint8
const ( // NotUpdated means that the modification time of the file in the // commit is the same as the one in the index. NotUpdated IndexStatus = iota // UpdatedInIndex means that the modification time of the file in the // index is newer than that of the commit UpdatedInIndex // TypeChangedInIndex mentioned in the Git docs but not implemented // here - file type changed (regular file, symbolic link or submodule) TypeChangedInIndex // AddedInIndex means that the file is in the index but not in the // commit. AddedInIndex // DeletedInIndex means that the file has been removed from the index DeletedInIndex // RenamedInIndex - @todo I do not understand how to implement this RenamedInIndex // CopiedInIndex - @todo not sure about this one either // - copied (if config option status.renames is set to "copies") CopiedInIndex // UntrackedInIndex means that the file is not in the Index UntrackedInIndex )
func (IndexStatus) StatusString ¶
func (is IndexStatus) StatusString() string
func (IndexStatus) String ¶
func (is IndexStatus) String() string
type Object ¶
type Object struct { Path string Typ objectType Sha Sha Objects []*Object Length int HeaderLength int ReadCloser func() (io.ReadCloser, error) }
func ObjectTree ¶
func ObjectTree(files []*FileStatus) *Object
ObjectTree creates a Tree Object with child Objects representing the files and paths in the provided files.
func ReadObject ¶
func ReadObjectTree ¶
ReadObjectTree reads an object from the object store
func WriteBlob ¶
WriteBlob writes a file to the object store as a blob and returns a Blob Object representation.
func (*Object) FlattenTree ¶
func (o *Object) FlattenTree() []*FileStatus
FlattenTree turns a TreeObject structure into a flat list of file paths
type Opt ¶
func WithGitDirectory ¶
type PackObjectType ¶
type PackObjectType uint8
const ( ObjCommit PackObjectType ObjTree ObjBlob ObjTag ObjOfsDelta ObjRefDelta )
type Sha ¶
type Sha struct {
// contains filtered or unexported fields
}
func CreateCommit ¶
CreateCommit writes the Commit provided in the Object Store
func CurrentCommit ¶
CurrentCommit return the current commit SHA @todo this probably breaks in detached head...
func PreviousCommits ¶
func ShaFromHexString ¶
func WriteObject ¶
WriteObject writes an object to the object store
func (Sha) AsByteSlice ¶
AsByteSlice returns a Sha as a byte slice
func (Sha) AsHexBytes ¶
func (Sha) AsHexString ¶
type WDStatus ¶
type WDStatus uint8
const ( // IndexAndWorkingTreeMatch means the file modification time in the // working directory is the same as in the index IndexAndWorkingTreeMatch WDStatus = iota // WorktreeChangedSinceIndex means the file in the working directory has // a newer modification time than the file in the index WorktreeChangedSinceIndex // TypeChangedInWorktreeSinceIndex is not implemented TypeChangedInWorktreeSinceIndex // DeletedInWorktree means that the file has been removed from the working // directory but exists in the commit DeletedInWorktree // RenamedInWorktree not implemented RenamedInWorktree // CopiedInWorktree not implemented CopiedInWorktree // Untracked means that the file is in the working directory but not in // the index or commit Untracked )