Documentation
¶
Overview ¶
Package merge provides merge conflict detection and analysis.
This package detects potential merge conflicts between branches before attempting the actual merge operation. Merge/rebase execution is intentionally out of scope (use plain git); gz-git's value is bulk-first diagnostics via ConflictDetector.
Features ¶
- Conflict detection between branches
- Conflict file listing
- Merge base calculation
- Fast-forward checks and merge previews
Usage ¶
detector := merge.NewConflictDetector(gitcmd.NewExecutor())
report, err := detector.Detect(ctx, repo, merge.DetectOptions{
Source: "feature",
Target: "main",
})
if err != nil {
// handle
}
if report.TotalConflicts > 0 {
// inspect report.Conflicts
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidBranch indicates an invalid branch reference. ErrInvalidBranch = errors.New("invalid branch reference") // ErrBranchNotFound indicates the specified branch does not exist. ErrBranchNotFound = errors.New("branch not found") // ErrNoMergeBase indicates no common ancestor found. ErrNoMergeBase = errors.New("no merge base found between branches") )
Functions ¶
This section is empty.
Types ¶
type ChangeType ¶
type ChangeType string
ChangeType defines the type of change.
const ( ChangeAdded ChangeType = "added" ChangeModified ChangeType = "modified" ChangeDeleted ChangeType = "deleted" ChangeRenamed ChangeType = "renamed" ChangeCopied ChangeType = "copied" )
ChangeType values describe how a file was modified.
type Conflict ¶
type Conflict struct {
FilePath string
ConflictType ConflictType
SourceChange ChangeType
TargetChange ChangeType
Severity ConflictSeverity
AutoResolvable bool
Description string
}
Conflict represents a single merge conflict.
type ConflictDetector ¶
type ConflictDetector interface {
// Detect analyzes potential conflicts between source and target
Detect(ctx context.Context, repo *repository.Repository, opts DetectOptions) (*ConflictReport, error)
// Preview shows what will happen during merge
Preview(ctx context.Context, repo *repository.Repository, source, target string) (*MergePreview, error)
// CanFastForward checks if fast-forward merge is possible
CanFastForward(ctx context.Context, repo *repository.Repository, source, target string) (bool, error)
}
ConflictDetector analyzes potential merge conflicts.
func NewConflictDetector ¶
func NewConflictDetector(executor GitExecutor) ConflictDetector
NewConflictDetector creates a new conflict detector.
type ConflictReport ¶
type ConflictReport struct {
Source string
Target string
MergeBase string
TotalConflicts int
Conflicts []*Conflict
CanAutoResolve int
Difficulty MergeDifficulty
}
ConflictReport contains detected conflicts from merge analysis.
type ConflictSeverity ¶
type ConflictSeverity string
ConflictSeverity indicates conflict severity.
const ( SeverityLow ConflictSeverity = "low" SeverityMedium ConflictSeverity = "medium" SeverityHigh ConflictSeverity = "high" )
ConflictSeverity values rank how serious a conflict is.
type ConflictType ¶
type ConflictType string
ConflictType defines the type of conflict.
const ( ConflictContent ConflictType = "content" // Content conflicts ConflictRename ConflictType = "rename" // Rename conflicts ConflictDelete ConflictType = "delete" // Delete/modify conflicts ConflictBinary ConflictType = "binary" // Binary file conflicts )
ConflictType values classify the nature of a merge conflict.
type DetectOptions ¶
DetectOptions configures conflict detection.
type FileChange ¶
type FileChange struct {
Path string
ChangeType ChangeType
OldPath string // For renames
}
FileChange represents a change to a file.
type GitExecutor ¶
type GitExecutor interface {
Run(ctx context.Context, repoPath string, args ...string) (*gitcmd.Result, error)
}
GitExecutor defines the interface for running git commands.
type MergeDifficulty ¶
type MergeDifficulty string
MergeDifficulty indicates merge complexity.
const ( DifficultyTrivial MergeDifficulty = "trivial" // No conflicts DifficultyEasy MergeDifficulty = "easy" // Auto-resolvable DifficultyMedium MergeDifficulty = "medium" // Some manual work DifficultyHard MergeDifficulty = "hard" // Many conflicts )
MergeDifficulty values estimate the effort required to complete a merge.
type MergePreview ¶
type MergePreview struct {
Source string
Target string
CanFastForward bool
FilesToChange int
FilesToAdd int
FilesToDelete int
Conflicts []*Conflict
Difficulty MergeDifficulty
}
MergePreview shows what will happen during merge.