git

package
v2.0.5 Latest Latest
Warning

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

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

Documentation

Overview

Package git provides interoperability with the local git binary: listing staged files and retrieving their diff content as it will be committed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStagedContent

func GetStagedContent(path string) ([]byte, error)

GetStagedContent returns the full staged blob content for a file. This is used for newly added files (status "A") where there is no base to diff against.

func GetStagedDiff

func GetStagedDiff(path string) ([]byte, error)

GetStagedDiff returns the unified diff of staged changes for the given path. Only the added lines (lines beginning with '+') are returned, because those represent new content being introduced into the repository.

func IsInsideWorkTree

func IsInsideWorkTree() bool

IsInsideWorkTree returns true when the current directory is inside a git repo.

func RepoRoot

func RepoRoot() (string, error)

RepoRoot returns the absolute path to the top-level repository directory.

Types

type StagedFile

type StagedFile struct {
	// Path is the repo-relative path of the file.
	Path string

	// Status is the single-letter git status code: A (added), M (modified),
	// D (deleted), R (renamed), C (copied), etc.
	Status string
}

StagedFile represents a single file that has changes staged for commit.

func ListStagedFiles

func ListStagedFiles() ([]StagedFile, error)

ListStagedFiles returns all files currently staged for the next commit. It runs `git diff --cached --name-status` and parses the output. Files with status "D" (deleted) are excluded — there is nothing to scan.

Jump to

Keyboard shortcuts

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