gitseal

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitseal seals a test binary's process environment against the developer's ambient git configuration.

It exists because #170's seal was written as unexported lines inside `package hooks_test`, which put it out of reach of every other package in the module — and internal/vcs, internal/cli and internal/repoproof build the same throwaway repositories against the same assumption that no machine-wide `core.hooksPath` is answering for them (#295). A seal that only one package can call is a seal the next package silently does without.

The entry point is Run, wired from a TestMain:

func TestMain(m *testing.M) { os.Exit(gitseal.Run(m)) }

THE SEAL IS ON THE PROCESS, NOT ON THE REPO BUILDER, and that is the altitude decision. Each caller has an obvious per-repository place to put this — a `repo()` or `initRepo()` helper — and it is the wrong one: fixtures reach linked worktrees through `git worktree add`, build repositories with a bare `git init` of their own, and run git at paths the helper never saw, and the next fixture written in those files starts by calling `exec.Command("git", ...)` because that is what the file above it does. A seal applied per repository is a seal each of those bypasses. git reads its configuration from the ENVIRONMENT of the process that runs it, so the environment is where the invariant lives, and TestMain is the only seam in a test binary that owns it before the first test runs.

WHAT IS SEALED, AND WHY IT IS A PREFIX SWEEP RATHER THAN A LIST. Every variable named GIT_*, plus FORMWORK_GIT_ENV, is removed. internal/hooks's gitenv.go records why a list is the wrong shape — git's documentation does not name GIT_CONFIG_PARAMETERS anywhere, so no reading of it produces the variable that mattered — and the same argument applies to a test seal: GIT_TEMPLATE_DIR changes what `git init` writes into .git/hooks, GIT_CEILING_DIRECTORIES changes which repository git discovers, and neither is in the family the production guards measure. No caller needs a GIT_* variable inherited from the developer, so removing all of them costs nothing and bounds the hostile set by a rule rather than by whoever last read githooks(5). A test that wants one sets it for itself with t.Setenv, which runs long after this does.

GLOBAL CONFIG IS SEALED THROUGH HOME, NOT GIT_CONFIG_GLOBAL. Pointing that variable at an empty file is the usual move and it cannot be used here: #146 R7 refuses to certify a repository whenever the ambient environment moves git's answer, and #167 D9 extended the same refusal to install, so the fixture would trip the guard it exists to neutralise. A private HOME with no .gitconfig in it is what a machine-wide hook runner actually installs into, and it reaches git's global scope while setting no variable any guard measures. XDG_CONFIG_HOME moves with it because git reads $XDG_CONFIG_HOME/git/config as well — the same pairing internal/hooks's preflight_test.go globalHooksPath and internal/vcs's configenv_test.go globalGitConfig make, for the same reason.

SYSTEM CONFIG IS NOT SEALED, AND THAT IS A DECISION RATHER THAN AN OVERSIGHT. /etc/gitconfig has exactly two overrides, GIT_CONFIG_SYSTEM and GIT_CONFIG_NOSYSTEM, and both are members of the family above: setting either would put every test in the calling package under a variable several of those tests exist to distinguish the presence of. So the seal cannot reach it, and the answer is to say so LOUDLY instead of running the suite and watching it fail one test at a time with no shared cause — see systemConfigRefusal below.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(m *testing.M) int

Run applies the seal and runs the suite, returning the code TestMain exits with.

The suite is run from here rather than from the caller's TestMain so the temporary HOME can be removed on a defer — os.Exit runs none, and a caller that took a seal and then called m.Run() itself would leak one directory per package per run.

A failure to seal returns 2 rather than running: the exit code this repo reserves for "the run could not be performed", as against 1 for a run that found something. Every fixture below the seal assumes a repository with no ambient wiring, so an unsealed run reports defects it invented.

Types

This section is empty.

Jump to

Keyboard shortcuts

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