Documentation
¶
Overview ¶
Package git provides an abstraction layer for git operations. This enables testing without actual git repositories.
Index ¶
- type Executor
- type FileStatus
- type RepoStatus
- type ShellExecutor
- func (e *ShellExecutor) ApplyPatch(ctx context.Context, patch io.Reader) error
- func (e *ShellExecutor) Commit(ctx context.Context, message string) error
- func (e *ShellExecutor) Diff(ctx context.Context, paths ...string) (string, error)
- func (e *ShellExecutor) DiffCached(ctx context.Context, paths ...string) (string, error)
- func (e *ShellExecutor) Reset(ctx context.Context) error
- func (e *ShellExecutor) ResetPath(ctx context.Context, path string) error
- func (e *ShellExecutor) Root(ctx context.Context) (string, error)
- func (e *ShellExecutor) Status(ctx context.Context) (*RepoStatus, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
// Diff returns the unified diff for unstaged changes.
// If paths is non-empty, limits to those paths.
Diff(ctx context.Context, paths ...string) (string, error)
// DiffCached returns the unified diff for staged changes.
DiffCached(ctx context.Context, paths ...string) (string, error)
// ApplyPatch applies a patch to the staging area.
// The patch is read from the provided reader.
ApplyPatch(ctx context.Context, patch io.Reader) error
// Commit creates a commit with the given message.
Commit(ctx context.Context, message string) error
// Reset unstages all staged changes.
Reset(ctx context.Context) error
// ResetPath unstages changes for a specific path.
ResetPath(ctx context.Context, path string) error
// Status returns the current repository status.
Status(ctx context.Context) (*RepoStatus, error)
// Root returns the repository root directory.
Root(ctx context.Context) (string, error)
}
Executor abstracts git operations for testability.
type FileStatus ¶
type FileStatus struct {
// Path is the file path relative to repo root.
Path string
// Staged indicates if the file has staged changes.
Staged bool
// Unstaged indicates if the file has unstaged changes.
Unstaged bool
// Untracked indicates if the file is untracked.
Untracked bool
}
FileStatus represents the status of a single file.
type RepoStatus ¶
type RepoStatus struct {
// StagedFiles lists files with staged changes.
StagedFiles []string
// UnstagedFiles lists files with unstaged changes.
UnstagedFiles []string
// UntrackedFiles lists untracked files.
UntrackedFiles []string
}
RepoStatus represents the current state of the repository.
type ShellExecutor ¶
type ShellExecutor struct {
// WorkDir is the working directory for git commands.
// If empty, uses current directory.
WorkDir string
}
ShellExecutor implements Executor by shelling out to git.
func NewShellExecutor ¶
func NewShellExecutor(workDir string) *ShellExecutor
NewShellExecutor creates a new ShellExecutor.
func (*ShellExecutor) ApplyPatch ¶
ApplyPatch applies a patch to the staging area.
func (*ShellExecutor) Commit ¶
func (e *ShellExecutor) Commit(ctx context.Context, message string) error
Commit creates a commit with the given message.
func (*ShellExecutor) DiffCached ¶
DiffCached returns the unified diff for staged changes.
func (*ShellExecutor) Reset ¶
func (e *ShellExecutor) Reset(ctx context.Context) error
Reset unstages all staged changes.
func (*ShellExecutor) ResetPath ¶
func (e *ShellExecutor) ResetPath(ctx context.Context, path string) error
ResetPath unstages changes for a specific path.
func (*ShellExecutor) Root ¶
func (e *ShellExecutor) Root(ctx context.Context) (string, error)
Root returns the repository root directory.
func (*ShellExecutor) Status ¶
func (e *ShellExecutor) Status(ctx context.Context) (*RepoStatus, error)
Status returns the current repository status.