Documentation
¶
Overview ¶
Package gitutil wraps the git CLI for checkout inspection, status and diffs (DBX-43).
Index ¶
- Constants
- Variables
- func Base(ctx context.Context, dir string, base devboxv1.ChangesBase) (ref, sha string, workTree bool, err error)
- func Changes(ctx context.Context, dir string, opts ChangesOptions) (*devboxv1.RepositoryChanges, error)
- func DefaultBranch(ctx context.Context, dir string) string
- func IgnoredFilter(ctx context.Context, dir string, paths []string) map[string]bool
- func Inspect(ctx context.Context, dir string) (*devboxv1.Checkout, error)
- func IsRepo(dir string) bool
- func Run(ctx context.Context, dir string, args ...string) ([]byte, error)
- func RunEnv(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)
- type ChangesOptions
- type DiffStat
- type Error
- type StatusEntry
Constants ¶
const DefaultMaxDiffBytes = 256 << 10
DefaultMaxDiffBytes caps one file's diff.
const EmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
EmptyTree is git's empty tree object, the base for repositories without commits.
Variables ¶
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 ¶
func Changes(ctx context.Context, dir string, opts ChangesOptions) (*devboxv1.RepositoryChanges, error)
Changes lists a checkout's changed files against a base, with line counts and optional diffs.
func DefaultBranch ¶
DefaultBranch is origin's default branch (origin/HEAD), falling back to main/master.
func IgnoredFilter ¶
IgnoredFilter returns which of the given paths (relative to dir) git ignores.
func IsRepo ¶
IsRepo reports whether dir is the top level of a git work tree (a checkout or a linked worktree).
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 ¶
DiffStat sizes a branch the way its pull request will: head against its merge base with base.
func BranchDiffStat ¶
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.