Documentation
¶
Index ¶
- type DiffStats
- type Logger
- type Service
- func (s *Service) CommitIgnoreChanges() error
- func (s *Service) CommitPlanFile(planFile, mainRepoRoot string) error
- func (s *Service) CreateBranch(name string) error
- func (s *Service) CreateBranchForPlan(planFile, defaultBranch string) error
- func (s *Service) CreateWorktreeForPlan(planFile, defaultBranch string) (string, bool, error)
- func (s *Service) CurrentBranch() (string, error)
- func (s *Service) DiffFingerprint() (string, error)
- func (s *Service) DiffStats(baseBranch string) (DiffStats, error)
- func (s *Service) EnsureHasCommits(promptFn func() bool) error
- func (s *Service) EnsureIgnored(pattern, probePath string) error
- func (s *Service) FileHasChanges(path string) (bool, error)
- func (s *Service) GetDefaultBranch() string
- func (s *Service) HasCommits() (bool, error)
- func (s *Service) HeadHash() (string, error)
- func (s *Service) IsDefaultBranch(defaultBranch string) (bool, error)
- func (s *Service) MovePlanToCompleted(planFile string) error
- func (s *Service) RemoveWorktree(path string) error
- func (s *Service) Root() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffStats ¶
type DiffStats struct {
Files int // number of files changed
Additions int // lines added
Deletions int // lines deleted
}
DiffStats holds statistics about changes between two commits.
type Logger ¶
Logger provides logging for git operations output. Compatible with *color.Color and standard log.Logger. The return values from Printf are ignored by Service methods.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides git operations for ralphex workflows. It is the single public API for the git package.
func NewService ¶
NewService opens a git repository and returns a Service. path is the path to the repository (use "." for current directory). log is used for progress output during operations. vcsCmd optionally specifies the vcs command to use (default: "git").
func (*Service) CommitIgnoreChanges ¶
CommitIgnoreChanges stages and commits .gitignore if it has uncommitted changes. no-op if .gitignore is clean. used to prevent dirty state from blocking branch/worktree creation after EnsureIgnored has modified .gitignore.
func (*Service) CommitPlanFile ¶
CommitPlanFile stages and commits a plan file on the current branch. mainRepoRoot is the root of the main repository, used to compute the plan file's relative path when the service operates inside a worktree.
func (*Service) CreateBranch ¶
CreateBranch creates a new branch and switches to it.
func (*Service) CreateBranchForPlan ¶
CreateBranchForPlan creates or switches to a feature branch for plan execution. If already on a feature branch (not the default branch), returns nil immediately. If on the default branch, extracts branch name from plan file and creates/switches to it. If plan file has uncommitted changes and is the only dirty file, auto-commits it. defaultBranch is the resolved default branch name (e.g. "main", "develop").
func (*Service) CreateWorktreeForPlan ¶
CreateWorktreeForPlan creates an isolated git worktree for plan execution. must be called from the default branch (same guard as CreateBranchForPlan). derives branch name from plan file, creates worktree at .ralphex/worktrees/<branch>. returns (worktree path, planNeedsCommit, error). when planNeedsCommit is true the caller must commit the plan file in the worktree context (via CommitPlanFile on the worktree's git service) so the commit lands on the feature branch rather than the default branch. defaultBranch is the resolved default branch name (e.g. "main", "develop").
func (*Service) CurrentBranch ¶
CurrentBranch returns the name of the current branch, or empty string for detached HEAD state.
func (*Service) DiffFingerprint ¶
DiffFingerprint returns a hash of the current working tree state (tracked diffs + untracked file content). used for stalemate detection - if the fingerprint changes between rounds, Claude made edits.
func (*Service) DiffStats ¶
DiffStats returns change statistics between baseBranch and HEAD. returns zero stats if baseBranch doesn't exist or HEAD equals baseBranch.
func (*Service) EnsureHasCommits ¶
EnsureHasCommits checks that the repository has at least one commit. If the repository is empty, calls promptFn to ask user whether to create initial commit. promptFn should return true to create the commit, false to abort. Returns error if repo is empty and user declined or promptFn returned false.
func (*Service) EnsureIgnored ¶
EnsureIgnored ensures a pattern is in .gitignore. uses probePath to check if pattern is already ignored before adding. if pattern is already ignored, does nothing. if pattern is not ignored, appends it to .gitignore with comment.
func (*Service) FileHasChanges ¶
FileHasChanges returns true if the given file has uncommitted changes (staged or unstaged).
func (*Service) GetDefaultBranch ¶
GetDefaultBranch returns the default branch name. detects from origin/HEAD or common branch names (main, master, trunk, develop).
func (*Service) HasCommits ¶
HasCommits returns true if the repository has at least one commit.
func (*Service) IsDefaultBranch ¶
IsDefaultBranch returns true if the current branch matches the given default branch. strips "origin/" prefix from defaultBranch for comparison (auto-detect may return "origin/main"). when defaultBranch is empty, falls back to checking "main" and "master".
func (*Service) MovePlanToCompleted ¶
MovePlanToCompleted moves a plan file to the completed/ subdirectory and commits. Creates the completed/ directory if it doesn't exist. Uses git mv if the file is tracked, falls back to os.Rename for untracked files. If the source file doesn't exist but the destination does, logs a message and returns nil.
func (*Service) RemoveWorktree ¶
RemoveWorktree removes a git worktree at the given path. no-op if the worktree directory doesn't exist or was already removed.