git

package
v0.0.0-...-aba8a4d Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute
View Source
const RequiredVersion = ">=1.8.x"

Variables

This section is empty.

Functions

func Executable

func Executable(gitBinPath *string) string

func IsGitErrorCode

func IsGitErrorCode(err error, codes ...string) bool

func ParseGitConfig

func ParseGitConfig(text string) map[string]string

func ParseGitStatusNumstat

func ParseGitStatusNumstat(text string) map[string]NumStat

func ParseGitSubmodule

func ParseGitSubmodule(text string) []map[string]string

func ParseGitTags

func ParseGitTags(text string) []string

func ParseInt

func ParseInt(value string, fallback int) (int, error)

func ParsePatchDiffResult

func ParsePatchDiffResult(patchLineList []bool, text string) string

ParsePatchDiffResult reproduces Ungit-compatible partial-staging transformation. Each boolean corresponds, in order, to a +/- line in the diff. Selected changes are retained while unselected additions are removed and unselected deletions become context lines. Hunk headers are adjusted to keep the resulting patch valid for git apply --cached.

Types

type Branch

type Branch struct {
	Name    string `json:"name"`
	Current bool   `json:"current,omitempty"`
}

func ParseGitBranches

func ParseGitBranches(text string) []Branch

type Command

type Command struct {
	RepoPath   string
	Args       []string
	AllowError bool
	Stdin      []byte
	Timeout    time.Duration
	Stdout     io.Writer
	Env        []string
}

type Commit

type Commit struct {
	Refs              []string       `json:"refs"`
	FileLineDiffs     []FileLineDiff `json:"fileLineDiffs"`
	Additions         int            `json:"additions"`
	Deletions         int            `json:"deletions"`
	SHA1              string         `json:"sha1"`
	Parents           []string       `json:"parents"`
	IsHead            bool           `json:"isHead"`
	AuthorName        string         `json:"authorName,omitempty"`
	AuthorEmail       string         `json:"authorEmail,omitempty"`
	CommitterName     string         `json:"committerName,omitempty"`
	CommitterEmail    string         `json:"committerEmail,omitempty"`
	AuthorDate        string         `json:"authorDate,omitempty"`
	CommitDate        string         `json:"commitDate,omitempty"`
	ReflogID          string         `json:"reflogId,omitempty"`
	ReflogName        string         `json:"reflogName,omitempty"`
	ReflogAuthorName  string         `json:"reflogAuthorName,omitempty"`
	ReflogAuthorEmail string         `json:"reflogAuthorEmail,omitempty"`
	SignatureDate     string         `json:"signatureDate,omitempty"`
	SignatureMade     string         `json:"signatureMade,omitempty"`
	Message           string         `json:"message"`
}

func ParseGitLog

func ParseGitLog(data string) ([]Commit, bool)

type CommitFile

type CommitFile struct {
	Name          string `json:"name"`
	PatchLineList []bool `json:"patchLineList"`
}

type Error

type Error struct {
	IsGitError       bool   `json:"isGitError"`
	ErrorCode        string `json:"errorCode"`
	Command          string `json:"command"`
	WorkingDirectory string `json:"workingDirectory"`
	ErrorText        string `json:"error"`
	Message          string `json:"message"`
	Stderr           string `json:"stderr"`
	Stdout           string `json:"stdout"`
	StdoutLower      string `json:"stdoutLower"`
	StderrLower      string `json:"stderrLower"`
}

func NewError

func NewError(repoPath string, args []string, stderr, stdout string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

type FileLineDiff

type FileLineDiff struct {
	Additions   any    `json:"additions"`
	Deletions   any    `json:"deletions"`
	FileName    string `json:"fileName"`
	OldFileName string `json:"oldFileName"`
	DisplayName string `json:"displayName"`
	Type        string `json:"type"`
}

type FileStatus

type FileStatus struct {
	FileName    string `json:"fileName"`
	OldFileName string `json:"oldFileName"`
	DisplayName string `json:"displayName"`
	Staged      bool   `json:"staged"`
	Removed     bool   `json:"removed"`
	IsNew       bool   `json:"isNew"`
	Conflict    bool   `json:"conflict"`
	Renamed     bool   `json:"renamed"`
	Type        string `json:"type"`
	Additions   any    `json:"additions"`
	Deletions   any    `json:"deletions"`
}

type LogResult

type LogResult struct {
	Limit       int      `json:"limit"`
	Skip        int      `json:"skip"`
	Nodes       []Commit `json:"nodes"`
	IsHeadExist *bool    `json:"isHeadExist,omitempty"`
}

type NumStat

type NumStat struct {
	Additions string `json:"additions"`
	Deletions string `json:"deletions"`
}

type Remote

type Remote struct {
	Name     string `json:"name"`
	FetchURL string `json:"fetchUrl,omitempty"`
	PushURL  string `json:"pushUrl,omitempty"`
	URL      string `json:"url,omitempty"`
}

func ParseGitRemotes

func ParseGitRemotes(text string) []Remote

type Result

type Result struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

type RevParseResult

type RevParseResult struct {
	Type        string    `json:"type"`
	GitRootPath string    `json:"gitRootPath"`
	SubRepos    *[]string `json:"subRepos,omitempty"`
}

type Runner

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

func NewRunner

func NewRunner(cfg config.Config) *Runner

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, c Command) (Result, error)

func (*Runner) RunText

func (r *Runner) RunText(ctx context.Context, repoPath string, args ...string) (string, error)

type Service

type Service struct {
	Runner *Runner
	// contains filtered or unexported fields
}

func NewService

func NewService(cfg config.Config) *Service

func (*Service) AutoStashExecuteAndPop

func (s *Service) AutoStashExecuteAndPop(ctx context.Context, repoPath string, args []string, timeout time.Duration) (string, error)

AutoStashExecuteAndPop matches Ungit-compatible autoStashExecuteAndPop wrapper. It intentionally uses plain `git stash` just like the Node implementation.

func (*Service) Commit

func (s *Service) Commit(ctx context.Context, repoPath string, amend, emptyCommit bool, message *string, files []CommitFile) (string, error)

func (*Service) CurrentBranch

func (s *Service) CurrentBranch(ctx context.Context, repoPath string) (string, error)

func (*Service) DiffFile

func (s *Service) DiffFile(ctx context.Context, repoPath, filename, oldFilename, sha1 string, ignoreWhitespace bool) (string, error)

func (*Service) DiscardAllChanges

func (s *Service) DiscardAllChanges(ctx context.Context, repoPath string) (string, error)

func (*Service) DiscardChangesInFile

func (s *Service) DiscardChangesInFile(ctx context.Context, repoPath, filename string) (string, error)

func (*Service) Head

func (s *Service) Head(ctx context.Context, repoPath string) ([]Commit, error)

func (*Service) Log

func (s *Service) Log(ctx context.Context, repoPath string, limit, skip, maxActiveBranchSearchIteration int) (LogResult, error)

func (*Service) ResolveConflicts

func (s *Service) ResolveConflicts(ctx context.Context, repoPath string, files []string) (string, error)

func (*Service) RevParse

func (s *Service) RevParse(ctx context.Context, repoPath string) RevParseResult

func (*Service) RunMutation

func (s *Service) RunMutation(ctx context.Context, repoPath string, args ...string) (string, error)

func (*Service) Status

func (s *Service) Status(ctx context.Context, repoPath, file string) (Status, error)

type SimpleError

type SimpleError struct {
	ErrorCode string `json:"errorCode"`
	ErrorText string `json:"error"`
}

func (*SimpleError) Error

func (e *SimpleError) Error() string

type Status

type Status struct {
	Branch        string                `json:"branch"`
	Files         map[string]FileStatus `json:"files"`
	InRebase      bool                  `json:"inRebase"`
	InMerge       bool                  `json:"inMerge"`
	InCherry      bool                  `json:"inCherry"`
	CommitMessage string                `json:"commitMessage,omitempty"`
	InConflict    bool                  `json:"inConflict"`
}

func ParseGitStatus

func ParseGitStatus(text string) Status

type VersionInfo

type VersionInfo struct {
	RequiredVersion string `json:"requiredVersion"`
	Version         string `json:"version"`
	Satisfied       bool   `json:"satisfied"`
	Error           string `json:"error,omitempty"`
}

func GetVersionInfo

func GetVersionInfo(ctx context.Context, gitBinPath *string) VersionInfo

Jump to

Keyboard shortcuts

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