Documentation
¶
Overview ¶
Package githook manages roborev's git hook installation, upgrade, and removal. It supports both standalone hooks (fresh installs) and embedded snippets that coexist with existing hook scripts.
Index ¶
- Constants
- Variables
- func GeneratePostCommit() string
- func GeneratePostRewrite() string
- func HasRealErrors(err error) bool
- func Install(hooksDir, hookName string, force bool) error
- func InstallAll(hooksDir string, force bool) error
- func Missing(repoPath, hookName string) bool
- func NeedsUpgrade(repoPath, hookName, versionMarker string) bool
- func NotInstalled(repoPath, hookName string) bool
- func Uninstall(hookPath string) error
- func VersionMarker(hookName string) string
Constants ¶
const PostCommitVersionMarker = "post-commit hook v4"
Version markers identify the current hook template version. Bump these when the hook template changes to trigger upgrade warnings and auto-upgrades.
const PostRewriteVersionMarker = "post-rewrite hook v2"
Variables ¶
var ErrNonShellHook = errors.New("non-shell interpreter")
ErrNonShellHook is returned when a hook uses a non-shell interpreter and cannot be safely modified.
var ReadFile = os.ReadFile
ReadFile is the function used to re-read a hook file after cleanup during upgrade. Replaceable in tests to simulate read failures.
Functions ¶
func GeneratePostCommit ¶
func GeneratePostCommit() string
GeneratePostCommit returns a standalone post-commit hook (with shebang, suitable for fresh installs).
func GeneratePostRewrite ¶
func GeneratePostRewrite() string
GeneratePostRewrite returns a standalone post-rewrite hook (with shebang, suitable for fresh installs).
func HasRealErrors ¶
HasRealErrors returns true if err contains any error that is not ErrNonShellHook. Use this instead of errors.Is when checking joined errors that may contain both non-shell warnings and real failures.
func Install ¶
Install installs or upgrades a single hook. It handles:
- No existing hook: write standalone content
- Existing without roborev: embed snippet after shebang
- Existing with current version: skip (no-op)
- Existing with old version: remove old, embed new
- force=true: overwrite unconditionally
func InstallAll ¶
InstallAll installs both post-commit and post-rewrite hooks. It attempts all hooks and returns a joined error if any fail.
func Missing ¶
Missing checks whether a repo has roborev installed (post-commit hook present) but is missing the named hook.
func NeedsUpgrade ¶
NeedsUpgrade checks whether a repo's named hook contains roborev but is outdated (missing the given version marker).
func NotInstalled ¶
NotInstalled checks whether the named hook file is absent or does not contain any roborev content.
func Uninstall ¶
Uninstall removes the roborev block from a hook file, or deletes it entirely if nothing else remains.
func VersionMarker ¶
VersionMarker returns the current version marker for a hook.
Types ¶
This section is empty.