gitsettings

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitsettings audits and applies the git configuration settings that make a multi-device, multi-agent workflow safe.

The recommended set is intentionally small and opinionated: each setting removes a class of mistake that shows up when the same branch is worked on from more than one machine (accidental merge commits from pull, stale remote branch references, missing upstream on first push, repeated conflict resolution).

Values are read with "git config --get" so unset and mismatched settings are distinguished; settings that need a newer git than the one installed are reported as unsupported rather than silently skipped.

Usage:

statuses, err := gitsettings.Inspect(ctx, exec, gitsettings.ScopeGlobal, "")
applied, err := gitsettings.Apply(ctx, exec, gitsettings.ScopeGlobal, "", statuses)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Report

type Report struct {
	Scope      Scope    `json:"scope"`
	GitVersion string   `json:"gitVersion"` //nolint:tagliatelle // wire name is part of the existing JSON schema.
	Statuses   []Status `json:"statuses"`
}

Report is the outcome of inspecting a scope.

func Inspect

func Inspect(ctx context.Context, executor *gitcmd.Executor, scope Scope, dir string) (*Report, error)

Inspect reads the current value of every recommended setting in the given scope and compares it against the recommendation.

dir is the repository directory for ScopeLocal and is ignored for ScopeGlobal.

func (*Report) Pending

func (r *Report) Pending() []Status

Pending returns the statuses that would be changed by Apply.

func (*Report) Unsupported

func (r *Report) Unsupported() []Status

Unsupported returns the statuses skipped because git is too old.

type Scope

type Scope string

Scope selects which git configuration file is inspected or written.

const (
	// ScopeGlobal targets the per-user config (~/.gitconfig).
	ScopeGlobal Scope = "global"
	// ScopeLocal targets the per-repository config (.git/config).
	ScopeLocal Scope = "local"
)

func (Scope) Flag

func (s Scope) Flag() string

Flag returns the git command-line flag for the scope.

type Setting

type Setting struct {
	// Key is the git config key, e.g. "pull.rebase".
	Key string `json:"key"`
	// Want is the recommended value.
	Want string `json:"want"`
	// Why explains, in one line, the failure mode the setting prevents.
	Why string `json:"why"`
	// MinGit is the minimum git version required, empty when any version works.
	MinGit string `json:"minGit,omitempty"` //nolint:tagliatelle // wire name is part of the existing JSON schema.
}

Setting is a single recommended git configuration key.

func Recommended() []Setting

Recommended returns a copy of the recommended settings.

type State

type State string

State describes how a repository's current value relates to the recommended one.

const (
	// StateOK means the current value already matches the recommendation.
	StateOK State = "ok"
	// StateUnset means the setting has no value in the inspected scope.
	StateUnset State = "unset"
	// StateMismatch means the setting is present but holds a different value.
	StateMismatch State = "mismatch"
	// StateUnsupported means the installed git is older than the setting requires.
	StateUnsupported State = "unsupported"
)

type Status

type Status struct {
	// Setting is embedded so its fields are flattened into the JSON object.
	Setting
	// Current is the value read from the inspected scope, empty when unset.
	Current string `json:"current,omitempty"`
	// State is the comparison outcome.
	State State `json:"state"`
}

Status pairs a recommended setting with the value found on this machine.

func Apply

func Apply(
	ctx context.Context,
	executor *gitcmd.Executor,
	scope Scope,
	dir string,
	statuses []Status,
) ([]Status, error)

Apply writes the recommended value for every status that needs a change. Statuses that already match, or that the installed git does not support, are left untouched. It returns the statuses that were written.

func (Status) NeedsChange

func (s Status) NeedsChange() bool

NeedsChange reports whether applying the recommendation would modify config.

Jump to

Keyboard shortcuts

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