scm

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHeadUnborn is raised when there are no commits yet in the git repo
	ErrHeadUnborn = errors.New("Head commit not found")
)

Functions

func CommitIDs

func CommitIDs(limiter CommitLimiter, wd ...string) ([]string, error)

CommitIDs returns commit SHA1 IDs starting from the head up to the limit

func ConfigRemove

func ConfigRemove(settings map[string]string, wd ...string) error

ConfigRemove removes git configuration settings

func ConfigSet

func ConfigSet(settings map[string]string, wd ...string) error

ConfigSet persists git configuration settings

func CreateNote

func CreateNote(noteTxt, nameSpace, commitHash string, wd ...string) error

CreateNote creates a git note associated with the head commit

func CurrentBranch added in v1.0.0

func CurrentBranch(wd ...string) string

CurrentBranch return current git branch name

func FetchRemotesAddRefSpecs

func FetchRemotesAddRefSpecs(refSpecs []string, wd ...string) error

func FetchRemotesRemoveRefSpecs

func FetchRemotesRemoveRefSpecs(refSpecs []string, wd ...string) error

func GitRepoPath

func GitRepoPath(path ...string) (string, error)

GitRepoPath discovers .git directory for a repo

func IgnoreRemove

func IgnoreRemove(ignore string, wd ...string) error

IgnoreRemove removes paths/files ignored for a git repo

func IgnoreSet

func IgnoreSet(ignore string, wd ...string) error

IgnoreSet persists paths/files to ignore for a git repo

func RemoveHooks

func RemoveHooks(hooks map[string]GitHook, p string) error

RemoveHooks remove matching git hook commands

func RemoveNote added in v1.0.1

func RemoveNote(nameSpace, commitHash string, wd ...string) error

func RewriteNote added in v1.0.1

func RewriteNote(oldHash, newHash, nameSpace string, wd ...string) error

func SetHooks

func SetHooks(hooks map[string]GitHook, wd ...string) error

SetHooks creates git hooks

func Workdir

func Workdir(gitRepoPath string) (string, error)

Workdir returns the working directory for a repo

Types

type Commit

type Commit struct {
	ID      string
	OID     *git.Oid
	Summary string
	Message string
	Author  string
	Email   string
	When    time.Time
	Files   []string
	Stats   CommitStats
}

Commit contains commit details

func HeadCommit

func HeadCommit(wd ...string) (Commit, error)

HeadCommit returns the latest commit

type CommitLimiter

type CommitLimiter struct {
	Max        int
	DateRange  util.DateRange
	Before     time.Time
	After      time.Time
	Author     string
	Message    string
	Subdir     string
	HasMax     bool
	HasBefore  bool
	HasAfter   bool
	HasAuthor  bool
	HasMessage bool
	HasSubdir  bool
}

CommitLimiter struct filter commits by criteria

func NewCommitLimiter

func NewCommitLimiter(
	max int, fromDateStr, toDateStr, author, message string,
	today, yesterday, thisWeek, lastWeek,
	thisMonth, lastMonth, thisYear, lastYear bool) (CommitLimiter, error)

NewCommitLimiter returns a new initialize CommitLimiter struct

type CommitNote

type CommitNote struct {
	ID      string
	OID     *git.Oid
	Summary string
	Message string
	Author  string
	Email   string
	When    time.Time
	Note    string
	Stats   CommitStats
}

CommitNote contains a git note's details

func ReadNote

func ReadNote(commitID string, nameSpace string, calcStats bool, wd ...string) (CommitNote, error)

ReadNote returns a commit note for the SHA1 commit id, tries to fetch squashed commits notes as well by message

type CommitStats

type CommitStats struct {
	Files        []string
	Insertions   int
	Deletions    int
	FilesChanged int
}

CommitStats contains the files changed and their stats

func DiffParentCommit

func DiffParentCommit(childCommit *git.Commit) (CommitStats, error)

DiffParentCommit compares commit to it's parent and returns their stats

func (CommitStats) ChangeRatePerHour

func (c CommitStats) ChangeRatePerHour(seconds int) float64

ChangeRatePerHour calculates the rate change per hour

type GitHook

type GitHook struct {
	Exe     string
	Command string
	RE      *regexp.Regexp
}

GitHook is the Command with options to be added/removed from a git hook Exe is the executable file name for Linux/MacOS RE is the regex to match on for the command

type Status

type Status struct {
	Files []fileStatus
}

Status contains the git file statuses

func NewStatus

func NewStatus(wd ...string) (Status, error)

NewStatus create a Status struct for a git repo

func (*Status) AddFile

func (s *Status) AddFile(e git.StatusEntry)

AddFile adds a StatusEntry for each file in working and staging directories

func (*Status) HasStaged

func (s *Status) HasStaged() bool

HasStaged returns true if there are any files in staging

func (*Status) IsModified

func (s *Status) IsModified(path string, staging bool) bool

IsModified returns true if the file is modified in either working or staging

func (*Status) IsTracked

func (s *Status) IsTracked(path string) bool

IsTracked returns true if file is tracked by the git repo

Jump to

Keyboard shortcuts

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