Documentation
¶
Index ¶
- Constants
- func CountHunksInDiff(diffOutput string) (map[string]string, error)
- func ParseHunkSpec(spec string) (filePath string, hunkNumbers []int, err error)
- type ActionCategory
- type DefaultGitStatusReader
- type DefaultPatchAnalyzer
- type ErrorType
- type FileMove
- type FileStatus
- type GitStatusInfo
- type GitStatusReader
- type HunkInfo
- type PatchAnalysisResult
- type PatchAnalyzer
- type RecommendedAction
- type SafetyChecker
- func (s *SafetyChecker) CheckActualStagingArea() (*StagingAreaEvaluation, error)
- func (s *SafetyChecker) EvaluatePatchContent(patchContent string) (*StagingAreaEvaluation, error)
- func (s *SafetyChecker) EvaluateWithFallback(patchContent string) (*StagingAreaEvaluation, error)
- func (s *SafetyChecker) EvaluateWithFallbackAndTargets(patchContent string, targetFiles map[string]bool) (*StagingAreaEvaluation, error)
- type SafetyError
- type SafetyErrorType
- type Stager
- type StagerError
- func NewDependencyMissingError(dependency string) *StagerError
- func NewFileNotFoundError(filename string, err error) *StagerError
- func NewGitCommandError(command string, err error) *StagerError
- func NewHunkCountExceededError(filePath string, maxHunks int, invalidHunks []int) *StagerError
- func NewHunkNotFoundError(description string, err error) *StagerError
- func NewIOError(operation string, err error) *StagerError
- func NewInvalidArgumentError(description string, err error) *StagerError
- func NewParsingError(what string, err error) *StagerError
- func NewPatchApplicationError(patchID string, err error) *StagerError
- func NewStagerError(errType ErrorType, message string, err error) *StagerError
- type StagingAreaEvaluation
Constants ¶
const ( GitStatusCodeModified = 'M' GitStatusCodeAdded = 'A' GitStatusCodeDeleted = 'D' GitStatusCodeRenamed = 'R' GitStatusCodeCopied = 'C' GitStatusCodeUnmerged = 'U' GitStatusCodeUntracked = '?' GitStatusCodeIgnored = '!' GitStatusCodeSpace = ' ' )
Git status codes from git status --porcelain These are the character codes used in git status output
Variables ¶
This section is empty.
Functions ¶
func CountHunksInDiff ¶
CountHunksInDiff counts the number of hunks per file in the given diff output. It parses the diff using ParsePatchFileWithGitDiff and returns a map of file paths to hunk counts. For binary files, returns "*" to indicate wildcard staging is required. For text files, returns the hunk count as a string. Returns an empty map if diffOutput is empty.
Types ¶
type ActionCategory ¶
type ActionCategory int
ActionCategory represents the category of a recommended action
const ( ActionCategoryInfo ActionCategory = iota ActionCategoryCommit ActionCategoryUnstage ActionCategoryReset )
func (ActionCategory) String ¶
func (ac ActionCategory) String() string
String returns the string representation of ActionCategory
type DefaultGitStatusReader ¶
type DefaultGitStatusReader struct {
// contains filtered or unexported fields
}
DefaultGitStatusReader implements GitStatusReader using go-git
func (*DefaultGitStatusReader) ReadStatus ¶
func (r *DefaultGitStatusReader) ReadStatus() (*GitStatusInfo, error)
ReadStatus implements GitStatusReader.ReadStatus
type DefaultPatchAnalyzer ¶
type DefaultPatchAnalyzer struct{}
DefaultPatchAnalyzer implements PatchAnalyzer using go-gitdiff
func (*DefaultPatchAnalyzer) AnalyzePatch ¶
func (a *DefaultPatchAnalyzer) AnalyzePatch(patchContent string) (*PatchAnalysisResult, error)
AnalyzePatch implements PatchAnalyzer.AnalyzePatch
type ErrorType ¶
type ErrorType int
ErrorType represents the type of error that occurred
const ( // ErrorTypeUnknown is for unknown errors ErrorTypeUnknown ErrorType = iota // ErrorTypeFileNotFound is when a file cannot be found ErrorTypeFileNotFound // ErrorTypeParsing is for parsing errors ErrorTypeParsing // ErrorTypeGitCommand is for git command failures ErrorTypeGitCommand // ErrorTypeHunkNotFound is when a hunk cannot be found ErrorTypeHunkNotFound // ErrorTypeInvalidArgument is for invalid arguments ErrorTypeInvalidArgument // ErrorTypeDependencyMissing is when a required dependency is missing ErrorTypeDependencyMissing // ErrorTypeIO is for I/O errors ErrorTypeIO // ErrorTypePatchApplication is when applying a patch fails ErrorTypePatchApplication // ErrorTypeHunkCountExceeded is when requested hunk numbers exceed available hunks ErrorTypeHunkCountExceeded )
type FileStatus ¶
type FileStatus int
FileStatus represents the modification status of a file
const ( FileStatusModified FileStatus = iota FileStatusAdded FileStatusDeleted FileStatusRenamed FileStatusCopied FileStatusBinary )
func (FileStatus) String ¶
func (fs FileStatus) String() string
String returns the string representation of FileStatus
type GitStatusInfo ¶
type GitStatusInfo struct {
FilesByStatus map[FileStatus][]string
StagedFiles []string
IntentToAddFiles []string
}
GitStatusInfo contains parsed git status information
type GitStatusReader ¶
type GitStatusReader interface {
// ReadStatus reads the current git status and returns parsed file information
ReadStatus() (*GitStatusInfo, error)
}
GitStatusReader is responsible for reading and parsing git status information
func NewGitStatusReader ¶
func NewGitStatusReader(repoPath string) GitStatusReader
NewGitStatusReader creates a new GitStatusReader instance
type HunkInfo ¶
type HunkInfo struct {
GlobalIndex int // Global hunk number in the patch file (1, 2, 3, ...)
FilePath string // File path this hunk belongs to (new path for renames)
OldFilePath string // Old file path (for renames)
IndexInFile int // Hunk number within the file (1, 2, 3, ...)
PatchID string // Unique patch ID calculated using git patch-id
IsBinary bool // Whether this is a binary file
Fragment *gitdiff.TextFragment // Original fragment from go-gitdiff
File *gitdiff.File // Original file from go-gitdiff
}
HunkInfo represents information about a single hunk
func ParsePatchFileWithGitDiff ¶
ParsePatchFileWithGitDiff parses a patch file using go-gitdiff library
type PatchAnalysisResult ¶
type PatchAnalysisResult struct {
FilesByStatus map[FileStatus][]string
AllFiles []string
IntentToAddFiles []string
}
PatchAnalysisResult contains the result of patch analysis
type PatchAnalyzer ¶
type PatchAnalyzer interface {
// AnalyzePatch analyzes patch content and returns file status information
AnalyzePatch(patchContent string) (*PatchAnalysisResult, error)
}
PatchAnalyzer is responsible for analyzing patch content and extracting file information
func NewPatchAnalyzer ¶
func NewPatchAnalyzer() PatchAnalyzer
NewPatchAnalyzer creates a new PatchAnalyzer instance
type RecommendedAction ¶
type RecommendedAction struct {
Description string // アクションの説明
Commands []string // 実行すべきコマンドのリスト
Priority int // 優先度(1が最高)
Category ActionCategory // アクションのカテゴリ
}
RecommendedAction represents an action that can be taken to resolve a staging issue
type SafetyChecker ¶
type SafetyChecker struct {
// contains filtered or unexported fields
}
SafetyChecker provides functionality to check the safety of staging operations Uses a hybrid approach: patch-based analysis with git command fallback when necessary
func NewSafetyChecker ¶
func NewSafetyChecker(repoPath string) *SafetyChecker
NewSafetyChecker creates a new SafetyChecker instance Accepts an optional repoPath for hybrid approach ("" = patch-only mode)
func (*SafetyChecker) CheckActualStagingArea ¶
func (s *SafetyChecker) CheckActualStagingArea() (*StagingAreaEvaluation, error)
CheckActualStagingArea checks the actual staging area using git commands This method is more accurate but requires git command execution
func (*SafetyChecker) EvaluatePatchContent ¶
func (s *SafetyChecker) EvaluatePatchContent(patchContent string) (*StagingAreaEvaluation, error)
EvaluatePatchContent evaluates safety from patch content (git-command-free analysis)
func (*SafetyChecker) EvaluateWithFallback ¶
func (s *SafetyChecker) EvaluateWithFallback(patchContent string) (*StagingAreaEvaluation, error)
EvaluateWithFallback performs hybrid evaluation: patch-first with git command fallback This is the recommended API for safety checking
func (*SafetyChecker) EvaluateWithFallbackAndTargets ¶
func (s *SafetyChecker) EvaluateWithFallbackAndTargets(patchContent string, targetFiles map[string]bool) (*StagingAreaEvaluation, error)
EvaluateWithFallbackAndTargets performs hybrid evaluation with target files consideration When targetFiles is provided, intent-to-add files in the target list are allowed to have staged hunks
type SafetyError ¶
type SafetyError struct {
Type SafetyErrorType
Message string
Advice string
Underlying error
}
SafetyError represents a safety-related error with detailed context
func NewSafetyError ¶
func NewSafetyError(errorType SafetyErrorType, message, advice string, underlying error) *SafetyError
NewSafetyError creates a new SafetyError
func (*SafetyError) Error ¶
func (e *SafetyError) Error() string
Error returns the formatted error message
func (*SafetyError) Is ¶
func (e *SafetyError) Is(target error) bool
Is implements error comparison for errors.Is
func (*SafetyError) Unwrap ¶
func (e *SafetyError) Unwrap() error
Unwrap returns the underlying error
type SafetyErrorType ¶
type SafetyErrorType int
SafetyErrorType represents the type of safety-related error
const ( // StagingAreaNotClean indicates the staging area has existing staged files StagingAreaNotClean SafetyErrorType = iota // NewFileConflict indicates a new file is already staged NewFileConflict // DeletedFileConflict indicates a deleted file conflict DeletedFileConflict // RenamedFileConflict indicates a renamed file conflict RenamedFileConflict // GitOperationFailed indicates a git operation failed GitOperationFailed // IntentToAddProcessing indicates an error during intent-to-add file processing IntentToAddProcessing )
func (SafetyErrorType) String ¶
func (t SafetyErrorType) String() string
String returns a string representation of the error type
type Stager ¶
type Stager struct {
// contains filtered or unexported fields
}
Stager handles the sequential staging of hunks from Git patch files. It provides functionality to selectively stage specific hunks identified by patch IDs, solving the "hunk number drift" problem that occurs with dependent changes.
func NewStager ¶
func NewStager(exec executor.CommandExecutor) *Stager
NewStager creates a new Stager instance with the provided command executor. The executor is used to run Git commands.
func (*Stager) StageFiles ¶
StageFiles stages entire files directly using git add. This is used for wildcard specifications (file:*).
func (*Stager) StageHunks ¶
StageHunks stages the specified hunks from a patch file to Git's staging area. hunkSpecs should be in the format "file:hunk_numbers" (e.g., "main.go:1,3"). The function uses patch IDs to track hunks across changes, solving the drift problem.
type StagerError ¶
StagerError represents a custom error with type classification
func NewDependencyMissingError ¶
func NewDependencyMissingError(dependency string) *StagerError
NewDependencyMissingError creates a dependency missing error
func NewFileNotFoundError ¶
func NewFileNotFoundError(filename string, err error) *StagerError
NewFileNotFoundError creates a file not found error
func NewGitCommandError ¶
func NewGitCommandError(command string, err error) *StagerError
NewGitCommandError creates a git command error
func NewHunkCountExceededError ¶
func NewHunkCountExceededError(filePath string, maxHunks int, invalidHunks []int) *StagerError
NewHunkCountExceededError creates an error when requested hunk numbers exceed available hunks
func NewHunkNotFoundError ¶
func NewHunkNotFoundError(description string, err error) *StagerError
NewHunkNotFoundError creates a hunk not found error
func NewIOError ¶
func NewIOError(operation string, err error) *StagerError
NewIOError creates an I/O error
func NewInvalidArgumentError ¶
func NewInvalidArgumentError(description string, err error) *StagerError
NewInvalidArgumentError creates an invalid argument error
func NewParsingError ¶
func NewParsingError(what string, err error) *StagerError
NewParsingError creates a parsing error
func NewPatchApplicationError ¶
func NewPatchApplicationError(patchID string, err error) *StagerError
NewPatchApplicationError creates a patch application error
func NewStagerError ¶
func NewStagerError(errType ErrorType, message string, err error) *StagerError
NewStagerError creates a new StagerError
func (*StagerError) Error ¶
func (e *StagerError) Error() string
Error implements the error interface
func (*StagerError) Is ¶
func (e *StagerError) Is(target error) bool
Is allows comparison with error types
func (*StagerError) Unwrap ¶
func (e *StagerError) Unwrap() error
Unwrap allows errors.Is and errors.As to work
type StagingAreaEvaluation ¶
type StagingAreaEvaluation struct {
IsClean bool
StagedFiles []string
IntentToAddFiles []string
ErrorMessage string
AllowContinue bool
RecommendedActions []RecommendedAction
FilesByStatus map[FileStatus][]string
}
StagingAreaEvaluation contains the result of evaluating the staging area