git

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseGitRange

func ParseGitRange(rangeStr string) (base, head string)

ParseGitRange parses a Git range specification into base and head references. Supports formats like "main..feature", "HEAD~1", or single references. Returns "HEAD~1" and "HEAD" as defaults for empty input.

Types

type DiffData

type DiffData struct {
	FilePath    string     `json:"file_path"`
	OldFilePath string     `json:"old_file_path,omitempty"`
	NewFilePath string     `json:"new_file_path,omitempty"`
	IsNew       bool       `json:"is_new"`
	IsDeleted   bool       `json:"is_deleted"`
	IsRenamed   bool       `json:"is_renamed"`
	Hunks       []DiffHunk `json:"hunks"`
}

DiffData represents structured information about a file diff. It contains metadata about the file changes and parsed diff hunks.

func ParseDiff

func ParseDiff(diffText, filePath string) (*DiffData, error)

ParseDiff parses a unified diff string into structured DiffData. The input should be in standard unified diff format with @@ hunk headers.

func (*DiffData) FormatForReview

func (d *DiffData) FormatForReview() string

FormatForReview formats the diff data into a human-readable string for code review. The output includes file status, change summary, and formatted diff hunks.

func (*DiffData) GetAddedLines

func (d *DiffData) GetAddedLines() []DiffLine

GetAddedLines returns all lines that were added in this diff. Useful for analyzing what new code was introduced.

func (*DiffData) GetContextLines

func (d *DiffData) GetContextLines() []DiffLine

GetContextLines returns all unchanged context lines from the diff. Context lines provide surrounding code for better understanding.

func (*DiffData) GetRemovedLines

func (d *DiffData) GetRemovedLines() []DiffLine

GetRemovedLines returns all lines that were removed in this diff. Useful for analyzing what code was deleted.

type DiffHunk

type DiffHunk struct {
	OldStart int        `json:"old_start"`
	OldCount int        `json:"old_count"`
	NewStart int        `json:"new_start"`
	NewCount int        `json:"new_count"`
	Header   string     `json:"header"`
	Lines    []DiffLine `json:"lines"`
}

DiffHunk represents a contiguous section of changes in a diff. Each hunk contains line-by-line changes with context.

type DiffLine

type DiffLine struct {
	Type    DiffLineType `json:"type"`
	Content string       `json:"content"`
	OldNum  int          `json:"old_num,omitempty"`
	NewNum  int          `json:"new_num,omitempty"`
}

DiffLine represents a single line in a diff with its type and position. Lines can be added, removed, context, or metadata.

type DiffLineType

type DiffLineType string

DiffLineType represents the type of a diff line (added, removed, context, etc.).

const (
	DiffLineAdded     DiffLineType = "added"
	DiffLineRemoved   DiffLineType = "removed"
	DiffLineContext   DiffLineType = "context"
	DiffLineNoNewline DiffLineType = "no_newline"
)

type GitClient

type GitClient struct {
	// contains filtered or unexported fields
}

GitClient provides an interface for Git operations needed for code review. It wraps go-git functionality to provide diff and commit information.

func NewGitClient

func NewGitClient() (*GitClient, error)

NewGitClient creates a new GitClient instance for the current directory. Returns an error if the current directory is not a Git repository.

func (*GitClient) GetChangedFiles

func (g *GitClient) GetChangedFiles(baseRef, headRef string) ([]string, error)

GetChangedFiles returns a list of files that changed between two Git references. References can be commit hashes, branch names, or symbolic refs like HEAD.

func (*GitClient) GetFileDiff

func (g *GitClient) GetFileDiff(baseRef, headRef, filePath string) (string, error)

GetFileDiff returns the raw diff text for a specific file between two references. The returned string contains the unified diff format suitable for review.

func (*GitClient) GetFileDiffData

func (g *GitClient) GetFileDiffData(baseRef, headRef, filePath string) (*DiffData, error)

GetFileDiffData returns structured diff information for a specific file. The returned DiffData contains parsed hunks, line changes, and metadata.

Jump to

Keyboard shortcuts

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