git

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package git provides easy execution of git commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit(msg string) error

Commit performs a commit with the given message.

func CoreEditorValue added in v0.2.0

func CoreEditorValue() (string, error)

CoreEditorValue returns the currently set local editor for git Can be used to direclty open files.

func CoreGlobalEditorValue added in v0.2.0

func CoreGlobalEditorValue() (string, error)

CoreEditorValue returns the currently set global editor for git Can be used to direclty open files.

func CurrentBranch

func CurrentBranch() (string, error)

CurrentBranch returns the name of the current current branch or an error.

func Diff

func Diff(opt DiffOptions) (string, error)

Diff performs a `git diff“ with the given options.

func IsInWorkTree added in v0.4.0

func IsInWorkTree() bool

func MergeMsg added in v0.4.0

func MergeMsg() (string, error)

MergeMsg returns the content of the file .git/MERGE_MSG

func ResetFile

func ResetFile(filePath string, isUntracked bool) error

ResetFile either resets the file to the index or deletes it in case it is untracked.

func RootFolder added in v0.4.0

func RootFolder() (string, error)

RootFolder returns the git root folder.

func StageAll

func StageAll() error

StageAll stages all files in the work tree

func StageFile

func StageFile(path string) error

StageFile stages a file at the given path.

func UnstageAll

func UnstageAll() error

UnstageAll unstages all staged files in the work tree.

func UnstageFile

func UnstageFile(path string) error

UnstageFile unstages a file at the given path.

Types

type DiffOptions

type DiffOptions struct {
	FilePath         string
	IsStaged         bool
	IsNameStatusOnly bool
	IsUntracked      bool
}

type FileStatus

type FileStatus struct {
	Path               string     // The Path of the file
	Extra              string     // Contains extra information, e.g. old name
	UnstagedStatusCode StatusCode // Working tree status
	StagedStatusCode   StatusCode // Index status
}

FileStatus represents the git status of a file. It shows the status in the working tree and in the index.

func (FileStatus) HasStagedChanges

func (fs FileStatus) HasStagedChanges() bool

func (FileStatus) HasUnstagedChanges

func (fs FileStatus) HasUnstagedChanges() bool

func (FileStatus) IsRenamed

func (fs FileStatus) IsRenamed() bool

func (FileStatus) IsUnmodified

func (fs FileStatus) IsUnmodified() bool

func (FileStatus) IsUntracked

func (fs FileStatus) IsUntracked() bool

type FileStatusList

type FileStatusList []FileStatus

func (FileStatusList) Filter

func (fl FileStatusList) Filter(isIncluded func(FileStatus) bool) FileStatusList

Filter returns a new FileStatusList that only includes elements accepted by the passed filter.

func (FileStatusList) StagedFiles

func (fl FileStatusList) StagedFiles() FileStatusList

StagedFiles returns all files that have staged changes.

func (FileStatusList) UnstagedFiles

func (fl FileStatusList) UnstagedFiles() FileStatusList

UnstagedFiles returns all files that have unstaged changes.

type StatusCode

type StatusCode byte

StatusCode of a file.

const (
	Unmodified         StatusCode = ' '
	Modified           StatusCode = 'M'
	TypeChanged        StatusCode = 'T'
	Added              StatusCode = 'A'
	Deleted            StatusCode = 'D'
	Renamed            StatusCode = 'R'
	Copied             StatusCode = 'C'
	UpdatedButUnmerged StatusCode = 'U'
	Untracked          StatusCode = '?'
	Ignored            StatusCode = '!'
)

type WorkTreeStatus

type WorkTreeStatus struct {
	// The branch at the time of creation.
	// Can be empty if not requested.
	Branch            string
	CleanedBranchName string
	// List of staged and unstaged files
	FileStatusList
}

WorkTreeStatus represents the current status of the git work tree.

func Status

func Status() (WorkTreeStatus, error)

Status retrieves the current `git status` represented by WorkTreeStatus object.

Jump to

Keyboard shortcuts

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