git

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCommit

func CreateCommit(repoPath, message string) (string, error)

CreateCommit stages all changes and creates a commit with the given message Returns the SHA of the new commit

func GetBranchName

func GetBranchName(repoPath, sha string) string

GetBranchName returns a human-readable branch reference for a commit. Returns something like "main", "feature/foo", or "main~3" depending on where the commit is relative to branch heads. Returns empty string on error or timeout (2 second limit to avoid blocking UI).

func GetCommitsSince

func GetCommitsSince(repoPath, mergeBase string) ([]string, error)

GetCommitsSince returns all commits from mergeBase to HEAD (exclusive of mergeBase) Returns commits in chronological order (oldest first)

func GetCurrentBranch

func GetCurrentBranch(repoPath string) string

GetCurrentBranch returns the current branch name, or empty string if detached HEAD

func GetDefaultBranch

func GetDefaultBranch(repoPath string) (string, error)

GetDefaultBranch detects the default branch (from origin/HEAD, or main/master locally)

func GetDiff

func GetDiff(repoPath, sha string) (string, error)

GetDiff returns the full diff for a commit, excluding generated files like lock files

func GetDirtyDiff

func GetDirtyDiff(repoPath string) (string, error)

GetDirtyDiff returns a diff of all uncommitted changes including untracked files. The diff includes both tracked file changes (via git diff HEAD) and untracked files formatted as new-file diff entries. Excludes generated files like lock files.

func GetFilesChanged

func GetFilesChanged(repoPath, sha string) ([]string, error)

GetFilesChanged returns the list of files changed in a commit

func GetHooksPath

func GetHooksPath(repoPath string) (string, error)

GetHooksPath returns the path to the hooks directory, respecting core.hooksPath

func GetMainRepoRoot

func GetMainRepoRoot(path string) (string, error)

GetMainRepoRoot returns the main repository root, resolving through worktrees. For a regular repository or submodule, this returns the same as GetRepoRoot. For a worktree, this returns the main repository's root path.

func GetMergeBase

func GetMergeBase(repoPath, ref1, ref2 string) (string, error)

GetMergeBase returns the merge-base (common ancestor) between two refs

func GetParentCommits

func GetParentCommits(repoPath, sha string, count int) ([]string, error)

GetParentCommits returns the N commits before the given commit (not including it) Returns commits in reverse chronological order (most recent parent first)

func GetRangeCommits

func GetRangeCommits(repoPath, rangeRef string) ([]string, error)

GetRangeCommits returns all commits in a range (oldest first)

func GetRangeDiff

func GetRangeDiff(repoPath, rangeRef string) (string, error)

GetRangeDiff returns the combined diff for a range, excluding generated files like lock files

func GetRangeStart

func GetRangeStart(repoPath, rangeRef string) (string, error)

GetRangeStart returns the start commit (first parent before range) for context lookup

func GetRemoteURL

func GetRemoteURL(repoPath, remoteName string) string

GetRemoteURL returns the URL for a git remote. If remoteName is empty, tries "origin" first, then any other remote. Returns empty string if no remotes exist.

func GetRepoRoot

func GetRepoRoot(path string) (string, error)

GetRepoRoot returns the root directory of the git repository

func GetStat

func GetStat(repoPath, sha string) (string, error)

GetStat returns the stat summary for a commit

func HasUncommittedChanges

func HasUncommittedChanges(repoPath string) (bool, error)

HasUncommittedChanges returns true if there are uncommitted changes (staged, unstaged, or untracked files)

func IsAncestor

func IsAncestor(repoPath, ancestor, descendant string) (bool, error)

IsAncestor checks if ancestor is an ancestor of descendant. Returns (true, nil) if ancestor is reachable from descendant via the commit graph. Returns (false, nil) if ancestor is not an ancestor (git exits with status 1). Returns (false, error) for git errors (e.g., bad object, repo issues).

func IsRange

func IsRange(ref string) bool

IsRange returns true if the ref is a range (contains "..")

func IsRebaseInProgress

func IsRebaseInProgress(repoPath string) bool

IsRebaseInProgress returns true if a rebase operation is in progress

func IsWorkingTreeClean

func IsWorkingTreeClean(repoPath string) bool

IsWorkingTreeClean returns true if the working tree has no uncommitted or untracked changes

func LocalBranchName

func LocalBranchName(branch string) string

LocalBranchName strips the "origin/" prefix from a branch name if present. This normalizes branch names for comparison since GetDefaultBranch may return "origin/main" while GetCurrentBranch returns "main".

func ParseRange

func ParseRange(ref string) (start, end string, ok bool)

ParseRange splits a range ref into start and end

func ReadFile

func ReadFile(repoPath, sha, filePath string) ([]byte, error)

ReadFile reads a file at a specific commit

func ResetWorkingTree

func ResetWorkingTree(repoPath string) error

ResetWorkingTree discards all uncommitted changes (staged and unstaged)

func ResolveSHA

func ResolveSHA(repoPath, ref string) (string, error)

ResolveSHA resolves a ref (like HEAD) to a full SHA

Types

type CommitInfo

type CommitInfo struct {
	SHA       string
	Author    string
	Subject   string
	Body      string // Full commit message body (excluding subject)
	Timestamp time.Time
}

CommitInfo holds metadata about a commit

func GetCommitInfo

func GetCommitInfo(repoPath, sha string) (*CommitInfo, error)

GetCommitInfo retrieves commit metadata

Jump to

Keyboard shortcuts

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