git

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package git provides repository checkouts for scanners that operate on source trees.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checkout

func Checkout(ctx context.Context, url, revision string, scope Scope) (dir string, cleanup func(), err error)

Checkout clones url into a fresh temporary directory, materialising only what scope allows. With an empty revision it does a shallow clone of the default branch; otherwise it clones and checks out revision. The returned cleanup removes the directory (call it even on error paths that returned a dir).

Types

type Scope added in v0.52.0

type Scope struct {
	// Paths restricts the checkout to these directories. Empty means the whole repository.
	//
	// Directory prefixes, not general globs: `services/web` and `services/web/**` both mean the
	// same subtree. That is what sparse checkout can express, and expressing it any other way
	// would mean downloading the repository to throw most of it away.
	Paths []string

	// Ignore removes matching paths after checkout, applied last so it can carve out of Paths.
	// Gitignore-style: a trailing `/` matches a directory and everything under it, `*` matches
	// within a path segment, `**` matches across them.
	Ignore []string
}

Scope restricts which of a repository's files a checkout materialises.

Shaping the tree rather than passing flags to each tool is deliberate. Every repository scanner is handed the checkout directory and points its tool at it — Trivy, Semgrep, Gitleaks and gosec all take a root and walk it. Translating a descriptor's scope into each tool's own include and exclude syntax would be a mapping per tool, wrong in a different way for each, and absent for the next scanner someone adds. A tree that already contains what was asked for needs no translation and cannot be forgotten.

func (Scope) Empty added in v0.52.0

func (s Scope) Empty() bool

Empty reports whether the scope restricts anything.

func (Scope) Key added in v0.52.0

func (s Scope) Key() string

Key renders the scope for a cache or dedup identity. Two components scoped to different subtrees of one repository are different scans, and a key that cannot tell them apart lets the second silently receive the first's findings.

Jump to

Keyboard shortcuts

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