Documentation
¶
Overview ¶
Package githooks installs baum's Git hook dispatchers into a clone, so Git reports the commits made there to the daemon without parsing anything.
A dispatcher runs baum's hook, then the hooks the clone had before, which install moved to <hook>.pre-baum. A hook baum cannot preserve is reported and left as it is, never replaced. `git config baum.hooks false` opts a clone out: Ensure then takes the dispatchers out again.
Index ¶
Constants ¶
const (
// Marker identifies a dispatcher baum wrote.
Marker = "# Managed by the baum desktop app."
)
Variables ¶
var Hooks = []string{"post-commit", "post-rewrite", "pre-push"}
Hooks are the Git hooks baum installs a dispatcher for.
Functions ¶
func Dispatcher ¶
Dispatcher is the script installed for hook. Hooks whose input Git feeds on standard input buffer it, so baum and the chained hooks each read all of it; when it cannot be buffered, baum is not run and the chained hooks read the original input. Baum never fails a hook; only a chained pre-push hook can stop a push.
Types ¶
type Clone ¶
type Clone struct {
ID, Path, CommonDir string
}
Clone is a registered clone as the service needs it.
type HookResult ¶
HookResult is the outcome for one hook.
type Options ¶
type Options struct {
// Baum is the absolute path of the baum binary a dispatcher falls back to
// when none is on PATH; empty for none.
Baum string
// Env is added to the environment of the git commands.
Env []string
}
Options adjust Ensure and Restore.
type Outcome ¶
type Outcome string
Outcome is what Ensure did for one hook.
const ( // Installed means the clone had no hook and now has the dispatcher. Installed Outcome = "installed" // Current means the dispatcher was already in place. Current Outcome = "current" // Repaired means an outdated or legacy dispatcher was replaced. Repaired Outcome = "repaired" // Chained means another tool's hook was moved to <hook>.pre-baum, which // the dispatcher runs after baum's. Chained Outcome = "chained" // Unclaimed means the hook was left as it is; Reason says why. Unclaimed Outcome = "unclaimed" // Restored means the clone opted out and its own hook is back in place. Restored Outcome = "restored" // Removed means the clone opted out and the dispatcher, which had no hook // to restore, is gone. Removed Outcome = "removed" // Absent means the clone opted out and has no dispatcher of baum's. Absent Outcome = "absent" )
type Report ¶
type Report struct {
// Skipped is why the clone got no hooks at all, empty when it was
// examined.
Skipped string
Hooks []HookResult
}
Report is what Ensure did for one clone.
func Ensure ¶
Ensure installs the dispatchers into the clone at root, repairing outdated ones, or takes them out when the clone opted out. It is idempotent and never deletes or follows a file it did not write. It goes on past a hook it cannot handle and returns what failed, joined.
func EnsureWith ¶
EnsureWith is Ensure with options.
type Service ¶
type Service struct {
// Clones lists the available registered clones.
Clones func(ctx context.Context) ([]Clone, error)
// Registered lists every registered clone, available or not; Removed uses
// it to leave hooks that another clone of the same repository shares.
Registered func(ctx context.Context) ([]Clone, error)
// Ensure and Restore act on one clone; nil are EnsureWith and Restore.
Ensure func(ctx context.Context, root string) (Report, error)
Restore func(ctx context.Context, root string) (Report, error)
// Options are passed to the default Ensure and Restore.
Options Options
Log *slog.Logger
// Every is the period of the sweep; zero is a day.
Every time.Duration
// contains filtered or unexported fields
}
Service keeps the dispatchers installed in the registered clones: for a clone as it is registered, and for every available clone at start and daily after, which repairs dispatchers an update outdated or a tool replaced. A clone that is no longer registered gets its own hooks back.
func (*Service) Added ¶
Added ensures a clone just registered, in the background; it never blocks the registration or fails it.