gitutils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gitutils provides Git repository operations for Syncwright

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupBackups

func CleanupBackups(repoPath string, filePaths []string) error

CleanupBackups removes backup files

func CommitChanges

func CommitChanges(message string) error

CommitChanges creates a commit with the provided message

func CreateBackup

func CreateBackup(repoPath, filePath string) error

CreateBackup creates a backup of the file before applying resolutions

func ExtractConflictContent

func ExtractConflictContent(filePath, repoPath string) (map[int]ConflictContent, error)

ExtractConflictContent extracts the content of conflict markers

func ExtractFileContext

func ExtractFileContext(filePath, repoPath string, contextLines int) ([]string, error)

ExtractFileContext extracts surrounding context lines for AI processing

func GetAllTrackedFiles

func GetAllTrackedFiles(repoPath string) ([]string, error)

GetAllTrackedFiles returns all files tracked by git

func GetConflictVersions

func GetConflictVersions(repoPath, filePath string) (ours, theirs, base []string, err error)

GetConflictVersions retrieves all versions of a conflicted file

func GetConflictedFiles

func GetConflictedFiles() ([]string, error)

GetConflictedFiles returns a list of files with merge conflicts

func GetFileAtRevision

func GetFileAtRevision(repoPath, filePath, revision string) ([]string, error)

GetFileAtRevision retrieves file content at a specific git revision

func GetRecentlyModifiedFiles

func GetRecentlyModifiedFiles(repoPath string, days int) ([]string, error)

GetRecentlyModifiedFiles returns files modified within the specified number of days

func IsGitRepository

func IsGitRepository() (bool, error)

IsGitRepository checks if the current directory is a Git repository

func IsGitRepositoryPath

func IsGitRepositoryPath(repoPath string) bool

IsGitRepositoryPath checks if the specified path is a Git repository

func IsInMergeState

func IsInMergeState(repoPath string) (bool, error)

IsInMergeState checks if the repository is currently in a merge state

func IsTextFile

func IsTextFile(filePath string) bool

IsTextFile checks if a file is likely to be a text file (not binary)

func RestoreBackup

func RestoreBackup(repoPath, filePath string) error

RestoreBackup restores a file from its backup

func ValidateResolution

func ValidateResolution(resolution ConflictResolution) error

ValidateResolution performs basic validation on a resolution

Types

type ConflictContent

type ConflictContent struct {
	StartLine    int      `json:"start_line"`
	EndLine      int      `json:"end_line"`
	StartMarker  string   `json:"start_marker"`
	MiddleMarker string   `json:"middle_marker"`
	EndMarker    string   `json:"end_marker"`
	BaseMarker   string   `json:"base_marker,omitempty"`
	OursLines    []string `json:"ours_lines"`
	TheirsLines  []string `json:"theirs_lines"`
	BaseLines    []string `json:"base_lines,omitempty"`
}

ConflictContent represents the detailed content of a conflict

type ConflictFile

type ConflictFile struct {
	Path    string         `json:"path"`
	Hunks   []ConflictHunk `json:"hunks"`
	Context []string       `json:"context,omitempty"` // Surrounding lines for AI context
}

ConflictFile represents a file with merge conflicts

type ConflictHunk

type ConflictHunk struct {
	StartLine   int      `json:"start_line"`
	EndLine     int      `json:"end_line"`
	OursLines   []string `json:"ours_lines"`
	TheirsLines []string `json:"theirs_lines"`
	BaseLines   []string `json:"base_lines,omitempty"` // For diff3 style conflicts
}

ConflictHunk represents a single conflict region in a file

func ParseConflictHunks

func ParseConflictHunks(filePath, repoPath string) ([]ConflictHunk, error)

ParseConflictHunks extracts conflict hunks from a file's content

type ConflictReport

type ConflictReport struct {
	ConflictedFiles []ConflictFile `json:"conflicted_files"`
	TotalConflicts  int            `json:"total_conflicts"`
	RepoPath        string         `json:"repo_path"`
}

ConflictReport represents the overall conflict detection report

func GetConflictReport

func GetConflictReport(repoPath string) (*ConflictReport, error)

GetConflictReport generates a comprehensive conflict report

type ConflictResolution

type ConflictResolution struct {
	FilePath      string   `json:"file_path"`
	StartLine     int      `json:"start_line"`
	EndLine       int      `json:"end_line"`
	ResolvedLines []string `json:"resolved_lines"`
	Confidence    float64  `json:"confidence"`
	Reasoning     string   `json:"reasoning,omitempty"`
}

ConflictResolution represents a resolved conflict hunk

type ConflictStatus

type ConflictStatus struct {
	FilePath string
	Status   string // "UU" for both modified, "AA" for both added, etc.
}

ConflictStatus represents the status of a conflicted file

func DetectConflicts

func DetectConflicts(repoPath string) ([]ConflictStatus, error)

DetectConflicts identifies files with merge conflicts from git status

type DiffFile

type DiffFile struct {
	OldPath string     `json:"old_path"`
	NewPath string     `json:"new_path"`
	Hunks   []DiffHunk `json:"hunks"`
}

DiffFile represents a file in git diff output

func GetConflictDiff

func GetConflictDiff(repoPath string, filePaths []string) ([]DiffFile, error)

GetConflictDiff retrieves the git diff for conflicted files

func GetMergeBaseDiff

func GetMergeBaseDiff(repoPath, filePath string) (*DiffFile, error)

GetMergeBaseDiff gets the diff between merge base and current state

type DiffHunk

type DiffHunk struct {
	OldStart int      `json:"old_start"`
	OldLines int      `json:"old_lines"`
	NewStart int      `json:"new_start"`
	NewLines int      `json:"new_lines"`
	Lines    []string `json:"lines"`
	Header   string   `json:"header"`
}

DiffHunk represents a single hunk from git diff output

type ResolutionResult

type ResolutionResult struct {
	Success       bool     `json:"success"`
	AppliedCount  int      `json:"applied_count"`
	FailedCount   int      `json:"failed_count"`
	Errors        []string `json:"errors,omitempty"`
	ModifiedFiles []string `json:"modified_files"`
}

ResolutionResult represents the result of applying resolutions

func ApplyResolutions

func ApplyResolutions(repoPath string, resolutions []ConflictResolution) (*ResolutionResult, error)

ApplyResolutions applies conflict resolutions to files

Jump to

Keyboard shortcuts

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