githook

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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.

View Source
const PostRewriteVersionMarker = "post-rewrite hook v2"

Variables

View Source
var ErrNonShellHook = errors.New("non-shell interpreter")

ErrNonShellHook is returned when a hook uses a non-shell interpreter and cannot be safely modified.

View Source
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

func HasRealErrors(err error) bool

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

func Install(hooksDir, hookName string, force bool) error

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

func InstallAll(hooksDir string, force bool) error

InstallAll installs both post-commit and post-rewrite hooks. It attempts all hooks and returns a joined error if any fail.

func Missing

func Missing(repoPath, hookName string) bool

Missing checks whether a repo has roborev installed (post-commit hook present) but is missing the named hook.

func NeedsUpgrade

func NeedsUpgrade(repoPath, hookName, versionMarker string) bool

NeedsUpgrade checks whether a repo's named hook contains roborev but is outdated (missing the given version marker).

func NotInstalled

func NotInstalled(repoPath, hookName string) bool

NotInstalled checks whether the named hook file is absent or does not contain any roborev content.

func Uninstall

func Uninstall(hookPath string) error

Uninstall removes the roborev block from a hook file, or deletes it entirely if nothing else remains.

func VersionMarker

func VersionMarker(hookName string) string

VersionMarker returns the current version marker for a hook.

Types

This section is empty.

Jump to

Keyboard shortcuts

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