Documentation
¶
Overview ¶
Package git provides an abstraction layer for git operations. This enables testing without actual git repositories.
Index ¶
- type CommitInfo
- type ConflictInfo
- type Executor
- type FileStatus
- type RebaseState
- type RebaseStateType
- 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) RebaseAbort(ctx context.Context) error
- func (e *ShellExecutor) RebaseContinue(ctx context.Context) error
- func (e *ShellExecutor) RebaseList(ctx context.Context, base string) ([]CommitInfo, error)
- func (e *ShellExecutor) RebaseSkip(ctx context.Context) error
- func (e *ShellExecutor) RebaseStart(ctx context.Context, base, editor string) error
- func (e *ShellExecutor) RebaseStatus(ctx context.Context) (*RebaseState, 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 CommitInfo ¶ added in v1.0.1
type CommitInfo struct {
// Hash is the full commit hash.
Hash string
// ShortHash is the abbreviated commit hash (7 characters).
ShortHash string
// Subject is the first line of the commit message.
Subject string
// Author is the commit author in "Name <email>" format.
Author string
// Date is when the commit was authored.
Date time.Time
}
CommitInfo contains metadata about a commit.
type ConflictInfo ¶ added in v1.0.1
type ConflictInfo struct {
// Path is the file path relative to repo root.
Path string
// ConflictType describes the type of conflict (content, delete, etc.).
ConflictType string
}
ConflictInfo describes a file with merge conflicts.
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)
// RebaseList returns commits that would be rebased onto the given base.
RebaseList(ctx context.Context, base string) ([]CommitInfo, error)
// RebaseStart begins an interactive rebase with a custom sequence editor.
// The editor command is invoked by git to modify the todo file.
RebaseStart(ctx context.Context, base, editor string) error
// RebaseStatus returns the current rebase state.
RebaseStatus(ctx context.Context) (*RebaseState, error)
// RebaseContinue continues an in-progress rebase.
RebaseContinue(ctx context.Context) error
// RebaseAbort aborts an in-progress rebase.
RebaseAbort(ctx context.Context) error
// RebaseSkip skips the current commit during rebase.
RebaseSkip(ctx context.Context) 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 RebaseState ¶ added in v1.0.1
type RebaseState struct {
// InProgress is true if a rebase operation is active.
InProgress bool
// State indicates the current rebase state.
State RebaseStateType
// CurrentCommit is the commit currently being rebased (if any).
CurrentCommit *CommitInfo
// CurrentAction is the action being performed (pick, squash, etc.).
CurrentAction string
// TotalCount is the total number of commits to rebase.
TotalCount int
// RemainingCount is the number of commits remaining.
RemainingCount int
// CompletedCount is the number of commits already rebased.
CompletedCount int
// Conflicts lists any files with conflicts.
Conflicts []ConflictInfo
// OriginalBranch is the branch being rebased.
OriginalBranch string
// OntoRef is the target base reference.
OntoRef string
}
RebaseState represents the current state of an interactive rebase.
type RebaseStateType ¶ added in v1.0.1
type RebaseStateType string
RebaseStateType indicates the current state of a rebase operation.
const ( // RebaseStateNone indicates no rebase is in progress. RebaseStateNone RebaseStateType = "none" // RebaseStateNormal indicates rebase is progressing normally. RebaseStateNormal RebaseStateType = "normal" // RebaseStateConflict indicates rebase has stopped due to conflicts. RebaseStateConflict RebaseStateType = "conflict" // RebaseStateEdit indicates rebase has stopped for commit editing. RebaseStateEdit RebaseStateType = "edit" )
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) RebaseAbort ¶ added in v1.0.1
func (e *ShellExecutor) RebaseAbort(ctx context.Context) error
RebaseAbort aborts an in-progress rebase.
func (*ShellExecutor) RebaseContinue ¶ added in v1.0.1
func (e *ShellExecutor) RebaseContinue(ctx context.Context) error
RebaseContinue continues an in-progress rebase.
func (*ShellExecutor) RebaseList ¶ added in v1.0.1
func (e *ShellExecutor) RebaseList( ctx context.Context, base string, ) ([]CommitInfo, error)
RebaseList returns commits that would be rebased onto the given base.
func (*ShellExecutor) RebaseSkip ¶ added in v1.0.1
func (e *ShellExecutor) RebaseSkip(ctx context.Context) error
RebaseSkip skips the current commit during rebase.
func (*ShellExecutor) RebaseStart ¶ added in v1.0.1
func (e *ShellExecutor) RebaseStart( ctx context.Context, base, editor string, ) error
RebaseStart begins an interactive rebase with a custom sequence editor.
func (*ShellExecutor) RebaseStatus ¶ added in v1.0.1
func (e *ShellExecutor) RebaseStatus(ctx context.Context) (*RebaseState, error)
RebaseStatus returns the current rebase state.
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.