gitutil

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gitutil wraps the git CLI for checkout inspection, status and diffs (DBX-43).

Index

Constants

View Source
const DefaultMaxDiffBytes = 256 << 10

DefaultMaxDiffBytes caps one file's diff.

View Source
const EmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"

EmptyTree is git's empty tree object, the base for repositories without commits.

Variables

View Source
var Env = []string{"GIT_TERMINAL_PROMPT=0", "GIT_OPTIONAL_LOCKS=0", "LC_ALL=C"}

Env is added to every git invocation (credential helpers etc. come from the environment / gitconfig).

Functions

func Base

func Base(ctx context.Context, dir string, base devboxv1.ChangesBase) (ref, sha string, workTree bool, err error)

Base resolves a ChangesBase to a ref name and commit (EmptyTree when there is nothing to compare against). workTree reports whether the comparison includes the working tree (HEAD, DEFAULT_BRANCH) or is commit-to-commit (LAST_COMMIT).

func Changes

Changes lists a checkout's changed files against a base, with line counts and optional diffs.

func DefaultBranch

func DefaultBranch(ctx context.Context, dir string) string

DefaultBranch is origin's default branch (origin/HEAD), falling back to main/master.

func IgnoredFilter

func IgnoredFilter(ctx context.Context, dir string, paths []string) map[string]bool

IgnoredFilter returns which of the given paths (relative to dir) git ignores.

func Inspect

func Inspect(ctx context.Context, dir string) (*devboxv1.Checkout, error)

Inspect describes a checkout.

func IsRepo

func IsRepo(dir string) bool

IsRepo reports whether dir is the top level of a git work tree (a checkout or a linked worktree).

func Run

func Run(ctx context.Context, dir string, args ...string) ([]byte, error)

Run runs git in dir and returns stdout.

func RunEnv

func RunEnv(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)

RunEnv runs git with extra environment.

Types

type ChangesOptions

type ChangesOptions struct {
	Base         devboxv1.ChangesBase
	IncludeDiff  bool
	MaxDiffBytes int
	// Path restricts to one path (relative to the checkout).
	Path string
}

ChangesOptions select what Changes returns.

type DiffStat

type DiffStat struct {
	Additions, Deletions, Files int
	BaseSHA, HeadSHA            string
}

DiffStat sizes a branch the way its pull request will: head against its merge base with base.

func BranchDiffStat

func BranchDiffStat(ctx context.Context, dir, base, head string) (*DiffStat, error)

BranchDiffStat diffs head against its merge base with base. The remote's base is preferred, since a local base branch may be stale; head resolves locally first, as it's the branch the agent just pushed.

type Error

type Error struct {
	Args   []string
	Stderr string
	Code   int
	// contains filtered or unexported fields
}

Error is a failed git command with its stderr.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type StatusEntry

type StatusEntry struct {
	XY      string
	Path    string
	OldPath string
}

StatusEntry is one `git status --porcelain` entry.

func Status

func Status(ctx context.Context, dir string) ([]StatusEntry, error)

Status returns porcelain status entries (paths relative to the checkout).

Jump to

Keyboard shortcuts

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