git

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff() ([]byte, error)

Diff executes `git diff` and returns the raw command output. Callers are responsible for parsing or rendering the returned bytes.

func GetBranches added in v0.5.0

func GetBranches() ([]string, error)

GetBranches returns a list of all available branches (local and remote).

func GetCommitStats added in v0.6.0

func GetCommitStats(commitHash string) (int, int, error)

GetCommitStats retrieves additions and deletions for a specific commit. Returns (additions, deletions, error).

func GetCurrentBranch added in v0.5.0

func GetCurrentBranch() (string, error)

GetCurrentBranch returns the name of the current branch. Returns empty string if in detached HEAD state.

func GetFileDiff

func GetFileDiff(filepath string, contextLines int, mode DiffMode, compareBranch string) ([]byte, error)

GetFileDiff returns the unified diff for a specific file. contextLines specifies how many context lines to show (0 for default, -1 for full file) mode specifies which changes to show (staged, unstaged, or all) compareBranch specifies the target branch for comparison (only used when mode is DiffBranch)

func GetMainBranch added in v0.6.0

func GetMainBranch() (string, error)

GetMainBranch returns the name of the main branch (main or master). Tries common main branch names and returns the first one found.

func GetUpstreamBranch added in v0.6.0

func GetUpstreamBranch() (string, error)

GetUpstreamBranch returns the remote tracking branch for the current branch. Returns empty string if no upstream is configured.

func ValidateBranch added in v0.5.0

func ValidateBranch(branch string) error

ValidateBranch checks if a branch exists.

Types

type CommitInfo added in v0.6.0

type CommitInfo struct {
	Hash      string    // Short hash (7 chars)
	Message   string    // First line of commit message
	Author    string    // Author name
	Date      time.Time // Commit date
	DateStr   string    // Relative date string (e.g., "2 hours ago")
	Additions int       // Total lines added in commit
	Deletions int       // Total lines deleted in commit
}

CommitInfo represents metadata about a single commit.

func GetBranchCommits added in v0.6.0

func GetBranchCommits(n int, baseBranch string) ([]CommitInfo, error)

GetBranchCommits retrieves commits in current branch that are not in baseBranch. Uses git log baseBranch...HEAD to get commits unique to current branch. Returns empty slice if no commits found (not an error).

type DiffMode

type DiffMode int

DiffMode represents which changes to show

const (
	DiffAll      DiffMode = iota // Both staged and unstaged (default)
	DiffStaged                   // Only staged changes (--cached)
	DiffUnstaged                 // Only unstaged changes
	DiffBranch                   // Compare current branch to target branch
)

type FileStat

type FileStat struct {
	Path      string
	Status    FileStatus
	Additions int
	Deletions int
}

FileStat contains metadata about a changed file.

func GetModifiedFiles

func GetModifiedFiles(mode DiffMode, compareBranch string, includeUntracked bool) ([]FileStat, error)

GetModifiedFiles returns a list of all files with changes and their stats.

type FileStatus

type FileStatus int

FileStatus represents the status of a modified file.

const (
	StatusModified FileStatus = iota
	StatusAdded
	StatusDeleted
	StatusRenamed
	StatusUntracked
	StatusUnknown
)

Jump to

Keyboard shortcuts

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