gitguard

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 18 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 gitguard finds what git on this machine runs, or reads, from the folders a VM can write: hooks, and commands its config names. The VM can write the project and the writable volumes; git runs hooks and commands from paths anywhere, in the repository's own share, in another share (core.hooksPath into a volume), or from git's own config kept in one. Each path is followed through every symlink on the way, and checked against every share.

Index

Constants

View Source
const (
	BareOK    = "ok"
	BareUnset = "unset"
	BareOld   = "old" // git before 2.38, which ignores the setting
	BareNoGit = "nogit"
)

Bare-repository states.

View Source
const BareHint = `Git treats any folder with HEAD, objects/ and refs/ as a repository, even without .git, and runs commands its config names (on ` + "`git log`" + `, for one). A VM could create one in your projects, and the .git protection does not cover it.

This makes git ignore such folders unless named with --git-dir:
  git config --global safe.bareRepository explicit
`

BareHint is why the setting matters and how to set it, one paragraph per line.

Variables

This section is empty.

Functions

func BareState

func BareState(ctx context.Context) string

BareState is whether git on this machine ignores bare repositories it is not told about. Read from /, outside any repository: git only honours the setting from the system and global config.

func HooksName

func HooksName(rel string) (string, bool)

HooksName is the name that keeps the hooks folder rel read-only: its first component, which covers the folder and what it calls next to it (husky's hooks call .husky/<hook>). False for the project itself, and for a name the shares cannot carry.

func NamesWith

func NamesWith(hooks []string) []string

NamesWith is the names always listed, then hooks, each once.

func Shares

func Shares(project string, rwVolumes []string) []string

Shares are the folders the VM can write, in git's spelling, each once: the project first, then its writable volumes.

func Spelling

func Spelling(dir string) (string, bool)

Spelling is dir as git spells it: the physical path, C:/... on Windows.

Types

type Result

type Result struct {
	// Hooks are the hooks folders, or links on the way to them, in a share
	// and outside the names always listed, each once: where (relative to
	// the project when it is there, else absolute), a tab, then what names
	// it (see HooksName): relative to the top of its repository when that
	// is in a share, else to the share; "." when no name covers it (a share
	// itself, or a name at or above the root of the share holding it),
	// empty for a name no share can carry.
	Hooks []string
	// contains filtered or unexported fields
}

Result is what git on this machine runs, or reads, from the shares.

func Scan

func Scan(ctx context.Context, shares []string, home string) *Result

Scan is what git on this machine runs, or reads, from the shares (see Shares; the project first). home is the user's home folder.

func (*Result) Lines

func (r *Result) Lines() []string

Lines are the hooks folders and the risks, every hooks name accepted, as 0.2 printed them: "H\t" or "R\t" and the rest.

func (*Result) Names

func (r *Result) Names() []string

Names are the names always listed, then those keeping every hooks folder read-only, each once: the names when every one is accepted.

func (*Result) Risks

func (r *Result) Risks(names []string) []string

Risks are the risks to accept, as text, each once, when the shares get names (the names always listed, and the hooks names accepted): a config file in a share, a setting whose command is in one, a hook linked to a file in one, a share with more repositories than are checked, something git could not be asked about (an error, no answer in time). What a name keeps read-only is no risk; a declined hooks name keeps nothing.

Jump to

Keyboard shortcuts

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