git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

type Logger interface {
	Printf(format string, args ...any) (int, error)
}

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

func NewService(path string, log Logger, vcsCmd ...string) (*Service, error)

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

func (s *Service) CommitIgnoreChanges() error

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

func (s *Service) CommitPlanFile(planFile, mainRepoRoot string) error

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

func (s *Service) CreateBranch(name string) error

CreateBranch creates a new branch and switches to it.

func (*Service) CreateBranchForPlan

func (s *Service) CreateBranchForPlan(planFile, defaultBranch string) error

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

func (s *Service) CreateWorktreeForPlan(planFile, defaultBranch string) (string, bool, error)

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

func (s *Service) CurrentBranch() (string, error)

CurrentBranch returns the name of the current branch, or empty string for detached HEAD state.

func (*Service) DiffFingerprint

func (s *Service) DiffFingerprint() (string, error)

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

func (s *Service) DiffStats(baseBranch string) (DiffStats, error)

DiffStats returns change statistics between baseBranch and HEAD. returns zero stats if baseBranch doesn't exist or HEAD equals baseBranch.

func (*Service) EnsureHasCommits

func (s *Service) EnsureHasCommits(promptFn func() bool) error

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

func (s *Service) EnsureIgnored(pattern, probePath string) error

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

func (s *Service) FileHasChanges(path string) (bool, error)

FileHasChanges returns true if the given file has uncommitted changes (staged or unstaged).

func (*Service) GetDefaultBranch

func (s *Service) GetDefaultBranch() string

GetDefaultBranch returns the default branch name. detects from origin/HEAD or common branch names (main, master, trunk, develop).

func (*Service) HasCommits

func (s *Service) HasCommits() (bool, error)

HasCommits returns true if the repository has at least one commit.

func (*Service) HeadHash

func (s *Service) HeadHash() (string, error)

HeadHash returns the current HEAD commit hash as a hex string.

func (*Service) IsDefaultBranch

func (s *Service) IsDefaultBranch(defaultBranch string) (bool, error)

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

func (s *Service) MovePlanToCompleted(planFile string) error

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

func (s *Service) RemoveWorktree(path string) error

RemoveWorktree removes a git worktree at the given path. no-op if the worktree directory doesn't exist or was already removed.

func (*Service) Root

func (s *Service) Root() string

Root returns the absolute path to the repository root.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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