git

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommitHashLen = 40
	Zero          = "0000000000000000000000000000000000000000"
)

Variables

This section is empty.

Functions

func Fetch

func Fetch(gitDir, from, to string) error

Fetch does git fetch origin from:to

func GetTreeSHA1

func GetTreeSHA1(catter *ObjectCatter, commitSHA1 string) (string, error)

GetTreeSHA1 returns SHA1 of tree object for the commit

func LineRangesIntersect

func LineRangesIntersect(elem LineRange, list []LineRange) bool

LineRangesIntersect checks if provided elem line range intersects and of provided ranges from the list.

func MergeBase

func MergeBase(gitDir string, one, two string) (res string, err error)

MergeBase computes merge base between commits one and two

func UntrackedFiles

func UntrackedFiles(gitDir string) ([]string, error)

UntrackedFiles returns filenames of untracked files obtained with git ls-files command.

Types

type BlameResult

type BlameResult struct {
	Lines map[int]string // map from line number to SHA1 commit
}

BlameResult is the result of git blame operation

func Blame

func Blame(gitDir string, refspec []string, filename string) (BlameResult, error)

Blame returns lines that have changed in commit range specified by refSpec with respected commits and line numbers

type Change

type Change struct {
	Type                      ChangeType
	OldName, NewName          string
	OldLineRanges, LineRanges []LineRange
	Valid                     bool
}

Change describes what happened to the file

func Diff

func Diff(gitDir, workTreeDir string, refspec []string) ([]Change, error)

Diff computes diff given the refspec (e.g. {"php7_more_fixes", "^php7_testing", "^master"}) and returns changed lines in the final version. Set workTreeDir to "" if you compute changes only between branches without working copy.

type ChangeType

type ChangeType int

ChangeType describes what happened to the file: it has been deleted, modified, etc.

const (
	Deleted ChangeType = iota
	Added
	Changed
)

func (ChangeType) String

func (c ChangeType) String() string

type Commit

type Commit struct {
	Hash    string
	Author  string
	Message string
}

Commit represents git commit :)

func Log

func Log(gitDir string, refspec []string) (res []Commit, err error)

Log computes log in refspec

type LineRange

type LineRange struct {
	From      int
	To        int
	HaveRange bool
	Range     int
}

LineRange is range of line numbers that have been changed

func (LineRange) HasPoint

func (r LineRange) HasPoint(point int) bool

HasPoint checks whether specified point is contained in range [r.From, r.To].

type Object

type Object struct {
	Type     string
	Contents []byte
}

Object is a type of object and it's contents

type ObjectCatter

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

ObjectCatter is used to get objects from git, fast

func NewCatter

func NewCatter(gitDir string) (*ObjectCatter, error)

NewCatter spawns git so that we can do "cat-file" for objects pretty fast.

func (*ObjectCatter) Error

func (o *ObjectCatter) Error() error

func (*ObjectCatter) Get

func (o *ObjectCatter) Get(sha1 string) (*Object, error)

Get returns object with its type and contents.

<sha1> SP <type> SP <size> LF <contents> LF

func (*ObjectCatter) Walk

func (o *ObjectCatter) Walk(dir string, treeSHA1 string, filenameFilter func(filename []byte) bool, cb func(filename string, contents []byte)) error

Walk traverses tree object treeSHA1 and calls cb() upon encountering any blob that matches filenameFilter()

Jump to

Keyboard shortcuts

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