Documentation
¶
Overview ¶
Package git provides git repository operations via a pluggable backend. the default backend uses go-git library; an alternative external backend shells out to the git CLI.
Index ¶
- type DiffStats
- type Logger
- type Option
- type Service
- func (s *Service) CreateBranch(name string) error
- func (s *Service) CreateBranchForPlan(planFile string) error
- func (s *Service) CurrentBranch() (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) GetDefaultBranch() string
- func (s *Service) HasCommits() (bool, error)
- func (s *Service) HeadHash() (string, error)
- func (s *Service) IsMainBranch() (bool, error)
- func (s *Service) MovePlanToCompleted(planFile 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 ¶ added in v0.8.0
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 ¶ added in v0.6.0
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 Option ¶ added in v0.10.0
type Option func(*serviceConfig)
Option configures NewService behavior.
func WithExternalGit ¶ added in v0.10.0
func WithExternalGit() Option
WithExternalGit configures the service to use the external git CLI backend instead of the default go-git library.
type Service ¶ added in v0.6.0
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 ¶ added in v0.6.0
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. opts can include WithExternalGit() to use the git CLI instead of go-git.
func (*Service) CreateBranch ¶ added in v0.6.0
CreateBranch creates a new branch and switches to it.
func (*Service) CreateBranchForPlan ¶ added in v0.6.0
CreateBranchForPlan creates or switches to a feature branch for plan execution. If already on a feature branch (not main/master), returns nil immediately. If on main/master, 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.
func (*Service) CurrentBranch ¶ added in v0.6.0
CurrentBranch returns the name of the current branch, or empty string for detached HEAD state.
func (*Service) DiffStats ¶ added in v0.8.0
DiffStats returns change statistics between baseBranch and HEAD. returns zero stats if baseBranch doesn't exist or HEAD equals baseBranch.
func (*Service) EnsureHasCommits ¶ added in v0.6.0
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 ¶ added in v0.6.0
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) GetDefaultBranch ¶ added in v0.6.0
GetDefaultBranch returns the default branch name. detects from origin/HEAD or common branch names (main, master, trunk, develop).
func (*Service) HasCommits ¶ added in v0.6.0
HasCommits returns true if the repository has at least one commit.
func (*Service) HeadHash ¶ added in v0.9.0
HeadHash returns the current HEAD commit hash as a hex string.
func (*Service) IsMainBranch ¶ added in v0.6.0
IsMainBranch returns true if the current branch is "main" or "master".
func (*Service) MovePlanToCompleted ¶ added in v0.6.0
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.