gitism

package
v0.0.0-...-6f0424a Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ChangeHashMissing = "0000000000000000000000000000000000000000"

ChangeHashMissing is used by git to represent when a file cannot have a hash defined. The logic for when this is used is defined in https://git-scm.com/docs/git-diff-tree#_raw_output_format.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Type               ChangeType
	PreviousHash, Hash string // The previous hash of the file and the new hash of the file.
	PreviousMode, Mode FileMode
	Path               string
}

Change describes a modification to a single file. Refer to git's documentation about what is possible to include: https://git-scm.com/docs/git-diff-tree#_raw_output_format

type ChangeType

type ChangeType uint8

ChangeType describes the type of modification done to the file in the git index. A full enumerations of types can be found on git's docs: https://git-scm.com/docs/git-diff-tree#:~:text=Possible%20status%20letters%20are

const (
	// ChangeUnknown represents X the change type from git-diff-tree.
	ChangeUnknown ChangeType = iota
	// ChangeAddition represents A the change type from git-diff-tree.
	ChangeAddition
	// ChangeCopy represents C the change type from git-diff-tree.
	ChangeCopy
	// ChangeDeletion represents D the change type from git-diff-tree.
	ChangeDeletion
	// ChangeModification represents M the change type from git-diff-tree.
	ChangeModification
	// ChangeRename represents R the change type from git-diff-tree.
	ChangeRename
	// ChangeFileType represents T the change type from git-diff-tree.
	ChangeFileType
	// ChangeUnmerged represents U the change type from git-diff-tree.
	ChangeUnmerged
)

type Command

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

func NewCommand

func NewCommand(directory string) (Command, error)

func (*Command) CatFile

func (c *Command) CatFile(objectType string, hash string) ([]byte, error)

CatFile is a wrapper around the git cat-file command. Read more here: https://git-scm.com/docs/git-cat-file.

func (*Command) ListBranches

func (c *Command) ListBranches(handler func(branch string) error) error

ListBranches calls handler for with the name of every branch in the git repo.

func (*Command) ListCommits

func (c *Command) ListCommits(ref string, handler func(branch string) error) error

ListCommits calls handler for with the hash of every commit in the history of ref.

func (*Command) ListTags

func (c *Command) ListTags(handler func(branch string) error) error

ListTags calls handler for with the name of every tag in the git repo.

func (*Command) LsTree

func (c *Command) LsTree(reference string, path string, handler func(entry TreeEntry) error) error

LsTree lists a tree-like object from git.

type Commit

type Commit struct {
	Hash    string
	Changes []Change
}

type FileMode

type FileMode struct {
	Type  FileType
	Perms PermissionMask
}

FileMode is a struct representing the "type" of a file in the git repo. This is a tuple of FileType and PermissionMask.

func NewFileMode

func NewFileMode(gitMode uint16) FileMode

NewFileMode takes a git file mode oct and turns it into fs.FileMode objects. It performs other fixes to the file mode to hack around edge cases in git. More details are available here: https://unix.stackexchange.com/a/450488

type FileType

type FileType uint8
const (
	RegularFile FileType = iota
	Directory
	Symlink
)

type ObjectType

type ObjectType uint8
const (
	UnknownObjectType ObjectType = iota
	BlobObject
	TreeObject
)

func NewObjectType

func NewObjectType(name string) ObjectType

func (ObjectType) String

func (t ObjectType) String() string

type PermissionMask

type PermissionMask uint16

PermissionMask represents the underlying representation git uses for defining permissions. This format is described in this stackoverflow post: https://unix.stackexchange.com/a/450488

func (PermissionMask) String

func (mask PermissionMask) String() string

type TreeEntry

type TreeEntry struct {
	Mode   FileMode
	Object ObjectType
	Hash   string
	Size   string
	Path   string
}

func NewTreeEntry

func NewTreeEntry(lsTreeLine string) (TreeEntry, error)

Jump to

Keyboard shortcuts

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