githelpers

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CustomCommandUndo = "undo"
	CustomCommandBack = "back"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BehaviorType added in v0.2.0

type BehaviorType int

BehaviorType describes how a git command behaves in terms of state changes and logging.

const (
	UnknownBehavior BehaviorType = iota
	// Mutating commands create or modify repository state and can be undone with git-undo.
	Mutating
	// Navigating commands move between states without creating/modifying and can be undone with git-back.
	Navigating
	// ReadOnly commands just read information and should not be logged.
	ReadOnly
)

func (BehaviorType) String added in v0.2.0

func (bt BehaviorType) String() string

type CommandType

type CommandType int

CommandType is the type of a git command.

const (
	UnknownCommand CommandType = iota
	Porcelain
	Plumbing
	Custom
)

func (CommandType) String

func (ct CommandType) String() string

type GitCommand

type GitCommand struct {
	Name         string       // e.g. "branch"
	Args         []string     // flags and operands
	Supported    bool         // was Name in our lookup?
	Type         CommandType  // Porcelain, Plumbing, or Unknown
	BehaviorType BehaviorType // Mutating, Navigating, or ReadOnly
}

GitCommand represents a parsed "git …" invocation.

func ParseGitCommand

func ParseGitCommand(raw string) (*GitCommand, error)

ParseGitCommand parses a git command string into a GitCommand struct.

func (*GitCommand) IsMutating added in v0.2.0

func (c *GitCommand) IsMutating() bool

IsMutating returns true if the command mutates repository state.

func (*GitCommand) IsNavigating added in v0.2.0

func (c *GitCommand) IsNavigating() bool

IsNavigating returns true if the command navigates between states.

func (*GitCommand) IsReadOnly

func (c *GitCommand) IsReadOnly() bool

IsReadOnly returns true if the command is read-only (for backward compatibility).

func (*GitCommand) Normalize added in v0.2.0

func (c *GitCommand) Normalize() (*GitCommand, error)

Normalize normalizes the command to a canonical form.

func (*GitCommand) NormalizedString added in v0.2.0

func (c *GitCommand) NormalizedString() (string, error)

NormalizedString returns the normalized command as a string.

func (*GitCommand) String added in v0.2.0

func (c *GitCommand) String() string

String returns a human-readable representation of the command.

type H

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

H is the struct for wrapping git helper functions It holds repoDir where commands are executed.

func NewGitHelper

func NewGitHelper(repoDirArg ...string) *H

NewGitHelper creates a new GitHelper instance.

func (*H) GetCurrentGitRef

func (h *H) GetCurrentGitRef() (string, error)

GetCurrentGitRef returns the current ref (branch, tag, commit hash) in the repository.

func (*H) GetRepoGitDir

func (h *H) GetRepoGitDir() (string, error)

GetRepoGitDir returns the path to the .git directory of current repository.

func (*H) GitOutput

func (h *H) GitOutput(subCmd string, args ...string) (string, error)

GitOutput executes a git command and returns its output as string.

func (*H) GitRun

func (h *H) GitRun(subCmd string, args ...string) error

GitRun executes a git command without output (via Run).

Jump to

Keyboard shortcuts

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