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) Unsupported ¶
Unsupported returns the statuses skipped because git is too old.
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 ¶
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 ¶
NeedsChange reports whether applying the recommendation would modify config.