hooks

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package hooks installs workline's git hooks.

Global mode takes core.hooksPath, which git honours for one folder only. So, like the forbidden-terms and git-identity-guard tools, it records whatever held core.hooksPath before and every hook hands over to it afterwards, then to the repository's own hooks. Nothing that ran before stops running.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Approve

func Approve(p Push, errOut io.Writer) bool

Approve asks a person whether the push goes, on the first channel that reaches one (ADR-0008): the terminal the hook opens; else the editor window the push came from; else a desktop dialog. None given by the pushing process: without any, no person can answer, and the push does not go.

func HandsOver added in v0.17.0

func HandsOver(dir, name string, p Paths) bool

HandsOver says whether git, running the hook name from dir, reaches workline: the file is executable and is workline's dispatcher, or runs `workline hook <name>` or workline's global hook of that name as a command, before any line that exits. A comment, an echo or a line after `exit` is not a hand-over.

func InstallGlobal

func InstallGlobal(p Paths, bin string) (string, error)

InstallGlobal writes the dispatchers and points the global core.hooksPath at them, recording what was there before. Running it twice changes nothing.

func InstallRepo

func InstallRepo(repo, bin string) (string, error)

InstallRepo writes a commit-msg dispatcher in the repository's .githooks/, where it can be committed for the whole team.

func PushRanges

func PushRanges(repo, remote string, stdin io.Reader) ([]string, error)

PushRanges turns what git gives a pre-push hook on its standard input — "<local ref> <local sha> <remote ref> <remote sha>" per ref — into the ranges of commits the push sends, as `git log` reads them. A deleted ref sends nothing; a branch, new or not, sends the commits no ref of that remote holds.

func UninstallGlobal

func UninstallGlobal(p Paths) (string, error)

UninstallGlobal gives core.hooksPath back to whatever held it before.

Types

type Paths

type Paths struct {
	Hooks string // folder core.hooksPath points to
	Next  string // file recording the previous core.hooksPath
}

Paths used by global mode.

func DefaultPaths

func DefaultPaths() (Paths, error)

DefaultPaths returns the folders under the user's config.

type Push

type Push struct {
	Repo, Remote string
	Refs         []Ref
	// Via names the channels the person allows, among terminal, editor and
	// dialog, in the order to try them; empty, all of them, in that order.
	Via []string
}

Push is what the person is asked to approve.

type Ref

type Ref struct {
	Local, Remote string // the ref names
	Range         string // the commits it sends, as `git log` reads them; empty when it sends none
	Delete        bool   // the push deletes the remote ref
}

Ref is one ref a push updates, as git gives it to a pre-push hook.

func PushedRefs

func PushedRefs(repo, remote string, stdin io.Reader) ([]Ref, error)

PushedRefs reads what git gives a pre-push hook on its standard input.

Jump to

Keyboard shortcuts

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