git

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package git implements the "safe git" wrapper: it parses a git argv and reports known-dangerous invocations so the command layer can refuse them.

Index

Constants

View Source
const RealBinary = "realgit"

RealBinary is the second command name the profile binds to the actual git binary, reachable only from this wrapper.

It is deliberately not "git": nono puts its shim directory first on PATH, so the wrapper is bound to the name "git" itself. If this wrapper resolved "git" (e.g. via exec.LookPath("git")) to find the real binary, that lookup would land back on the wrapper's own shim, argv_prepend would fire again, and it would recurse without bound — measured four levels deep before the probe that found this was killed. The profile instead gives the real git binary this second name, resolvable only from this wrapper, so looking it up here reaches the real binary through its own shim with no recursion.

It is also deliberately not "git-real", or anything else starting with "git-": git's own multi-call dispatch treats an argv[0] of the shape "git-<word>" as an attempt to run "<word>" as a builtin directly, ignoring the rest of argv. Measured: invoking the real git binary with argv[0] "git-real" and args ["config","--get","alias.x"] fails with "fatal: cannot handle real as a builtin" and never looks at "config --get" at all. A name with no "git-" prefix cannot collide with this. Do not change this back to "git", and do not give it a "git-" prefix either.

Variables

This section is empty.

Functions

func Check

func Check(argv []string) []safe.Violation

Check parses argv and returns a safe.Violation for every matched rule, in Rules() order, plus anything caught by expanding an unrecognized first token as a configured git alias (see checkAlias). A nil/empty result means the invocation is allowed. (internal/safe/git imports internal/safe; safe does not import git, so there is no package cycle.)

Types

type GlobalOpt

type GlobalOpt struct {
	Name  string
	Value string
}

GlobalOpt is a git global option appearing before the subcommand, e.g. {Name: "-c", Value: "core.hooksPath=/dev/null"} or {Name: "-p"}.

type Invocation

type Invocation struct {
	Global     []GlobalOpt
	Subcommand string
	Args       []string
}

Invocation is a git command line split into its global options, the subcommand, and the subcommand's own arguments (flags and positionals).

func Parse

func Parse(argv []string) Invocation

Parse splits argv into global options followed by the first non-global token (the subcommand) and its remaining args.

type Rule

type Rule struct {
	ID      string
	Message string
	Match   func(inv Invocation) bool
}

Rule is one entry in the semantic denylist. Match reports whether the parsed invocation is refused; Message is the human-readable reason surfaced to the user; ID is a stable key for tests and diagnostics.

func Rules

func Rules() []Rule

Rules returns the semantic denylist, a port of the agent-sandbox.toml git drop patterns with two deliberate differences: --force-with-lease is allowed, and -c hook/signature bypasses are detected.

Jump to

Keyboard shortcuts

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