git

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLockTimeout = 30 * time.Second

DefaultLockTimeout is the maximum time to wait for a lock before giving up.

Variables

This section is empty.

Functions

func IsInstalled added in v0.3.0

func IsInstalled() bool

IsInstalled checks if git is available in the system PATH.

Types

type Client

type Client struct {
	WorkDir string
	Logger  *slog.Logger
	// contains filtered or unexported fields
}

Client wraps git command execution with a global file-based lock for process safety.

func NewClient

func NewClient(workDir string, lockFile string, logger *slog.Logger) *Client

NewClient creates a new git client for the given working directory.

func (*Client) Add

func (c *Client) Add(files ...string) error

Add adds files to the stage.

func (*Client) Clean added in v0.2.0

func (c *Client) Clean(files ...string) error

Clean removes untracked files from the working tree.

func (*Client) Commit

func (c *Client) Commit(msg string) error

Commit records changes to the repository.

func (*Client) HasRemote

func (c *Client) HasRemote() bool

HasRemote checks if there is a 'origin' remote configured. For now, we hardcode 'origin' as the default remote to check.

func (*Client) Init

func (c *Client) Init() error

Init initializes a new git repository if one doesn't exist.

func (*Client) IsRepo added in v0.3.0

func (c *Client) IsRepo() bool

IsRepo checks if the current working directory is a valid git repository.

func (*Client) Lock

func (c *Client) Lock() (func(), error)

Lock acquires a file-based lock. It blocks until the lock is acquired.

func (*Client) Restore added in v0.2.0

func (c *Client) Restore(files ...string) error

Restore restores working tree files (discards changes in working directory). Use with caution.

func (*Client) Rm

func (c *Client) Rm(files ...string) error

Rm removes files from the working tree and from the index.

func (*Client) Run

func (c *Client) Run(args ...string) (string, error)

Run executes a raw git command in the working directory. NOTE: It does NOT acquire the lock automatically. The caller must manage transaction safety via Client.Lock().

func (*Client) Status

func (c *Client) Status() (string, error)

Status returns the porcelain status of the repo.

func (*Client) Sync

func (c *Client) Sync() error

Sync performs a pull --rebase and then a push. It assumes the caller handles locking if necessary, though git operations themselves are somewhat atomic, coordinating multiple git commands usually requires a lock to prevent state changes in between.

Jump to

Keyboard shortcuts

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