git

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists added in v0.14.0

func FileExists(path string) (bool, error)

FileExists checks whether a file exists on disk.

func GetCommitDartFiles

func GetCommitDartFiles(repoPath, commitID string) ([]string, error)

GetCommitDartFiles finds all files that were changed in a specific commit. Returns absolute paths to all files added, modified, or renamed in the commit.

func GetCommitFileDiffs added in v0.22.0

func GetCommitFileDiffs(repoPath, commitID string) (map[string]vcs.FileDiff, error)

GetCommitFileDiffs returns per-line additions and deletions for files modified in a single commit, computed against that commit's first parent. Line numbers in Additions reference the commit's post-image; line numbers in Deletions reference the parent's content.

func GetCommitFileStats

func GetCommitFileStats(repoPath, commitID string) (map[string]vcs.FileStats, error)

GetCommitFileStats returns statistics (additions/deletions) for files in a specific commit Returns a map from absolute file paths to their FileStats

func GetCommitRangeFileDiffs added in v0.22.0

func GetCommitRangeFileDiffs(repoPath, fromCommit, toCommit string) (map[string]vcs.FileDiff, error)

GetCommitRangeFileDiffs returns per-line additions and deletions for files changed between two commits. Inputs are the same as `git diff from..to`.

func GetCommitRangeFileStats

func GetCommitRangeFileStats(repoPath, fromCommit, toCommit string) (map[string]vcs.FileStats, error)

GetCommitRangeFileStats returns statistics (additions/deletions) for files changed between two commits. Returns a map from absolute file paths to their FileStats.

func GetCommitRangeFiles

func GetCommitRangeFiles(repoPath, fromCommit, toCommit string) ([]string, error)

GetCommitRangeFiles finds all files changed between two commits. Uses: git diff --name-only --diff-filter=d <from> <to> Returns absolute paths to all files added, modified, or renamed between the commits.

func GetCommitRangeLabel

func GetCommitRangeLabel(repoPath, fromCommit, toCommit string) (string, error)

GetCommitRangeLabel returns a label like "abc123...def456" for display

func GetCommitTreeFiles

func GetCommitTreeFiles(repoPath, commitID string) ([]string, error)

GetCommitTreeFiles returns all files that exist in a commit's tree. Unlike GetCommitDartFiles which only returns files changed in a commit, this returns all files that existed at that point in time. Returns absolute paths to all files in the commit tree.

func GetCommonDir added in v0.24.0

func GetCommonDir(path string) (string, error)

GetCommonDir returns the absolute path to the common git directory — the primary repository's `.git`. Identical for the primary and every linked worktree of the same repository.

func GetCurrentCommitHash

func GetCurrentCommitHash(repoPath string) (string, error)

GetCurrentCommitHash returns the current commit hash (HEAD)

func GetFileContentFromCommit

func GetFileContentFromCommit(repoPath, commitID, filePath string) ([]byte, error)

GetFileContentFromCommit reads the content of a file at a specific commit using 'git show commit:path'. The filePath should be relative to the repository root.

func GetGitDir added in v0.24.0

func GetGitDir(path string) (string, error)

GetGitDir returns the absolute path to the git directory for `path`. For the primary worktree this equals GetCommonDir; for a linked worktree this is the per-worktree gitdir under `<common>/worktrees/<name>`.

func GetRepositoryRoot

func GetRepositoryRoot(repoPath string) (string, error)

GetRepositoryRoot returns the absolute path to the repository root

func GetRepositoryStateSignature added in v0.15.0

func GetRepositoryStateSignature(repoPath string) (string, error)

GetRepositoryStateSignature returns a compact signature of repository state. It includes HEAD and porcelain status so callers can detect commit/index/worktree transitions.

func GetShortCommitHash

func GetShortCommitHash(repoPath, commitID string) (string, error)

GetShortCommitHash returns the short version of a given commit hash

func GetUncommittedFileDiffs added in v0.22.0

func GetUncommittedFileDiffs(repoPath string) (map[string]vcs.FileDiff, error)

GetUncommittedFileDiffs returns per-line additions and deletions for files with uncommitted changes (staged + unstaged). Line numbers in Additions reference the working-tree (post-image); line numbers in Deletions reference HEAD (pre-image). Both are 1-indexed.

func GetUncommittedFileStats

func GetUncommittedFileStats(repoPath string) (map[string]vcs.FileStats, error)

GetUncommittedFileStats returns statistics (additions/deletions) for uncommitted files Returns a map from relative file paths to their FileStats

func GetUncommittedFiles

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

GetUncommittedFiles finds all uncommitted files in a git repository. Returns absolute paths to all uncommitted files (staged, unstaged, and untracked).

func GitCommitContentReader

func GitCommitContentReader(repoPath, commitID string) vcs.ContentReader

GitCommitContentReader returns a ContentReader that reads file content from a specific git commit.

func HasUncommittedChanges

func HasUncommittedChanges(repoPath string) (bool, error)

HasUncommittedChanges checks if there are any uncommitted changes in the repository

func IsPrimaryWorktree added in v0.24.0

func IsPrimaryWorktree(path string) (bool, error)

IsPrimaryWorktree reports whether `path` is inside the primary worktree of its repository. True iff the git dir equals the common dir.

func ListTrackedFiles added in v0.14.0

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

ListTrackedFiles returns absolute paths for files tracked in the git index.

func ListUntrackedFiles added in v0.14.0

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

ListUntrackedFiles returns absolute paths for non-ignored untracked files.

func NormalizeCommitRange

func NormalizeCommitRange(repoPath, from, to string) (string, string, bool, error)

NormalizeCommitRange ensures commits are in chronological order (older first). If the commits are reversed (newer...older), it swaps them. Returns (olderCommit, newerCommit, swapped, error)

func ParseCommitRange

func ParseCommitRange(commitSpec string) (string, string, bool)

ParseCommitRange parses a commit specification and returns the from/to commits. Supports formats: "abc...def", "abc..def", or single commit "abc" Returns (from, to, isRange)

func ResolveFirstParent added in v0.14.0

func ResolveFirstParent(repoPath, commitID string) (parent string, hasParent bool, err error)

ResolveFirstParent resolves the first parent of a commit. Returns hasParent=false for root commits.

func ValidateCommit added in v0.14.0

func ValidateCommit(repoPath, commitID string) error

ValidateCommit validates that a commit reference resolves in the given repository.

Types

type Worktree added in v0.24.0

type Worktree struct {
	// Path is the absolute path to the working tree on disk.
	Path string
	// Head is the SHA at HEAD, or empty for an unborn branch.
	Head string
	// Branch is the full ref name (e.g. "refs/heads/main"), empty for detached.
	Branch string
	// IsPrimary is true for the primary worktree of the repository.
	// Per git's `worktree list --porcelain` contract, the primary is always first.
	IsPrimary bool
}

Worktree describes a single working tree registered with a repository.

func ListWorktrees added in v0.24.0

func ListWorktrees(path string) ([]Worktree, error)

ListWorktrees enumerates all worktrees registered with the repository containing `path`. The primary worktree is always the first entry.

Jump to

Keyboard shortcuts

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