git

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyMessage is returned when commit message is empty
	ErrEmptyMessage = errors.New("commit message is empty")
	// ErrCommitNotFound is returned when commit file is not found
	ErrCommitNotFound = errors.New("commit file is not found")
)
View Source
var ErrBranchNotFound = errors.New("HEAD is not on a branch")

ErrBranchNotFound is returned when repository HEAD is in detached state

View Source
var ErrCommandFailed = fmt.Errorf("command failed")

ErrCommandFailed is returned when git command execution fails

View Source
var ErrHeadNotFound = errors.New("HEAD file is not found")

ErrHeadNotFound is returned when HEAD file is not found

Functions

func BranchNameFromHead added in v0.1.4

func BranchNameFromHead(head string) (string, error)

BranchNameFromHead extracts branch name from raw HEAD content

func FindRoot added in v0.1.4

func FindRoot(path string) (string, error)

FindRoot returns root of git repository

func IsAvailable

func IsAvailable() bool

IsAvailable returns true if git is available in PATH

Types

type Cmd added in v0.1.4

type Cmd struct {
	// Cmd is native git command instance
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd represents git command

func Command added in v0.1.4

func Command(args ...string) *Cmd

Command returns new git command

func (*Cmd) Execute added in v0.1.4

func (c *Cmd) Execute() (string, error)

Execute executes git command

func (*Cmd) ExecuteAt added in v0.1.4

func (c *Cmd) ExecuteAt(path string) (string, error)

ExecuteAt executes git command at given path

type CommitMessage

type CommitMessage struct {
	Title string
	Body  string
}

CommitMessage represents commit message

func ParseCommitMessage

func ParseCommitMessage(text string) (CommitMessage, error)

ParseCommitMessage parses commit message to parts

func (CommitMessage) Bytes added in v0.1.4

func (m CommitMessage) Bytes() []byte

Bytes returns byte representation of commit message

func (CommitMessage) String

func (m CommitMessage) String() string

String returns string representation of commit message

type Repository

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

Repository represents git repository

func NewRepository

func NewRepository(root string) *Repository

NewRepository returns a new Repository instance

func OpenRepository

func OpenRepository(path string) (*Repository, error)

OpenRepository returns a new Repository instance with root of git repository.

func (*Repository) BranchName added in v0.1.4

func (r *Repository) BranchName() (string, error)

BranchName returns current branch name. If repository is in detached state, returns error

func (*Repository) CommitMessage added in v0.1.4

func (r *Repository) CommitMessage() (CommitMessage, error)

CommitMessage reads current commit message and parses it to title and body.

func (*Repository) HooksDir added in v0.1.4

func (r *Repository) HooksDir() (string, error)

HooksDir returns path to the repo hooks directory

func (*Repository) Path

func (r *Repository) Path() string

Path returns path to the git repository

func (*Repository) SetCommitMessage added in v0.1.4

func (r *Repository) SetCommitMessage(m CommitMessage) error

SetCommitMessage writes commit message to the repository.

Jump to

Keyboard shortcuts

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