hooks

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitCKInstallDir = "githooks.installDir"
	GitCKRunner     = "githooks.runner"
	GitCKDialog     = "githooks.dialog"

	GitCKDisable = "githooks.disable"

	GitCKMaintainOnlyServerHooks = "githooks.maintainOnlyServerHooks"

	GitCKAutoUpdateEnabled        = "githooks.autoUpdateEnabled"
	GitCKAutoUpdateCheckTimestamp = "githooks.autoUpdateCheckTimestamp"
	GitCKAutoUpdateUsePrerelease  = "githooks.autoUpdateUsePrerelease"

	GitCKBugReportInfo = "githooks.bugReportInfo"

	GitCKChecksumCacheDir = "githooks.checksumCacheDir"

	GitCKCloneBranch     = "githooks.cloneBranch"
	GitCKCloneURL        = "githooks.cloneUrl"
	GitCKBuildFromSource = "githooks.buildFromSource"
	GitCKGoExecutable    = "githooks.goExecutable"

	GitCKDeleteDetectedLFSHooksAnswer = "githooks.deleteDetectedLFSHooks"

	GitCKUseCoreHooksPath        = "githooks.useCoreHooksPath"
	GitCKPathForUseCoreHooksPath = "githooks.pathForUseCoreHooksPath"

	GitCKPreviousSearchDir = "githooks.previousSearchDir"
	GitCKNumThreads        = "githooks.numThreads"

	GitCKAliasHooks = "alias.hooks"
)

Git config keys for globals config.

View Source
const (
	GitCKRegistered = "githooks.registered"
	GitCKTrustAll   = "githooks.trustAll"
)

Git config keys for local config.

View Source
const (
	GitCKShared                        = "githooks.shared"
	GitCKSharedUpdateTriggers          = "githooks.sharedHooksUpdateTriggers"
	GitCKAutoUpdateSharedHooksDisabled = "githooks.autoUpdateSharedHooksDisabled"

	GitCKSkipNonExistingSharedHooks = "githooks.skipNonExistingSharedHooks"
	GitCKSkipUntrustedHooks         = "githooks.skipUntrustedHooks"

	GitCKRunnerIsNonInteractive = "githooks.runnerIsNonInteractive"
)

Git config keys for local/global config.

View Source
const (
	// TagNameReplaced is the hook tag for replaced hooks.
	TagNameReplaced = "replaced"
	// TagNameRepository is the hook tag for repository hooks.
	TagNameRepository = "repo"
	// TagNameSharedRepo is the hook tag for shared hooks inside the repository.
	TagNameSharedRepo = "shared:repo"
	// TagNameSharedLocal is the hook tag for shared hooks in the local Git config.
	TagNameSharedLocal = "shared:local"
	// TagNameSharedGLobal is the hook tag for shared hooks in the global Git config.
	TagNameSharedGLobal = "shared:global"
)
View Source
const (
	// NamespaceRepositoryHook is the namespace for repository hooks.
	NamespaceRepositoryHook = ""
	// NamespaceReplacedHook is the namespace for replace hooks.
	NamespaceReplacedHook = "hooks"
)
View Source
const DefaultBugReportingURL = "https://github.com/gabyx/githooks/issues"

DefaultBugReportingURL is the default url to report errors.

View Source
const EnvVariableArch = "GITHOOKS_ARCH"

EnvVariableArch is the environment variable which holds runtime architecture name.

View Source
const EnvVariableOs = "GITHOOKS_OS"

EnvVariableOs is the environment variable which holds runtime operating system name.

View Source
const EnvVariableStagedFiles = "STAGED_FILES"

EnvVariableStagedFiles is the environment variable which holds the staged files.

View Source
const GithooksWebpage = "https://github.com/gabyx/githooks"

GithooksWebpage is the main Githooks webpage.

View Source
const HooksDirName = ".githooks"

HooksDirName denotes the directory name used for repository specific hooks.

View Source
const (
	// SHA1Length is the string length of a SHA1 hash.
	SHA1Length = 40
)
View Source
const (
	// UseThreadPool defines if a threadpool is used to execute the hooks.
	UseThreadPool = true
)

Variables

View Source
var LFSHookNames = [4]string{
	"post-checkout",
	"post-commit",
	"post-merge",
	"pre-push"}

LFSHookNames are the hook names of all Large File System (LFS) hooks.

View Source
var ManagedHookNames = []string{
	"applypatch-msg",
	"pre-applypatch",
	"post-applypatch",
	"pre-commit",
	"pre-merge-commit",
	"prepare-commit-msg",
	"commit-msg",
	"post-commit",
	"pre-rebase",
	"post-checkout",
	"post-merge",
	"pre-push",
	"pre-receive",
	"update",
	"post-receive",
	"post-update",
	"reference-transaction",
	"push-to-checkout",
	"pre-auto-gc",
	"post-rewrite",
	"sendemail-validate",
	"post-index-change"}

ManagedHookNames are hook names managed by Githooks for normal repositories.

View Source
var ManagedServerHookNames = []string{
	"pre-push",
	"pre-receive",
	"update",
	"post-receive",
	"post-update",
	"reference-transaction",
	"push-to-checkout",
	"pre-auto-gc"}

ManagedServerHookNames are hook names managed by Githooks for bare repositories.

View Source
var SharedHookTypeV = &sharedHookType{Repo: 0, Local: 1, Global: 2, count: 3} // nolint:gomnd

SharedHookTypeV enumerates all types of shared hooks.

View Source
var StagedFilesHookNames = [3]string{"pre-commit", "prepare-commit-msg", "commit-msg"}

StagedFilesHookNames are the hook names on which staged files are exported.

View Source
var TaggedHookIndices = taggedHooksIndex{
	Replaced:     0,
	Repo:         1,
	SharedRepo:   2,
	SharedLocal:  3,
	SharedGlobal: 4,
	// contains filtered or unexported fields
}

TaggedHookIndices is a list of indices for all possible hooks Githooks supports. nolint: gomnd

Functions

func AllHooksSuccessful

func AllHooksSuccessful(results []HookResult) bool

AllHooksSuccessful returns `true`.

func AllowLocalURLInRepoSharedHooks

func AllowLocalURLInRepoSharedHooks() bool

AllowLocalURLInRepoSharedHooks defines if local urls such as `file://` should be allowed in repository configured shared hooks.

func AssertTemporaryDir

func AssertTemporaryDir(installDir string) (tempDir string, err error)

AssertTemporaryDir returns the Githooks temporary directory inside the install directory.

func CleanTemporaryDir

func CleanTemporaryDir(installDir string) (string, error)

CleanTemporaryDir returns the Githooks temporary directory inside the install directory.

func ClearGlobalSharedHooks

func ClearGlobalSharedHooks() error

ClearGlobalSharedHooks clears the shared hook list in the global Git config.

func ClearLocalSharedHooks

func ClearLocalSharedHooks(gitx *git.Context) error

ClearLocalSharedHooks clears the shared hook list in the local Git config.

func ClearRepoSharedHooks

func ClearRepoSharedHooks(repoDir string) error

ClearRepoSharedHooks clears the shared hook list in the repository.

func DeleteHookDirTemp

func DeleteHookDirTemp(hookDir string) (err error)

DeleteHookDirTemp deletes the temporary director inside the Git's hook directory.

func GetBinaryDir

func GetBinaryDir(installDir string) string

GetBinaryDir returns the Githooks binary directory inside the install directory.

func GetBugReportingInfo

func GetBugReportingInfo(repoPath string) (info string, err error)

GetBugReportingInfo gets the default bug reporting url. Argument 'repoPath' can be empty.

func GetCLIExecutable

func GetCLIExecutable(installDir string) cm.Executable

GetCLIExecutable gets the global Githooks CLI executable.

func GetChecksumDirectoryGitDir

func GetChecksumDirectoryGitDir(gitDir string) string

GetChecksumDirectoryGitDir gets the checksum file inside the Git directory.

func GetDefaultHooksNamespaceShared

func GetDefaultHooksNamespaceShared(sharedRepo *SharedRepo) string

GetDefaultHooksNamespaceShared returns the default hooks namespace for a shared url.

func GetDefaultRunner

func GetDefaultRunner(hookPath string) cm.IExecutable

GetDefaultRunner gets the default hook runner.

func GetDialogExecutable

func GetDialogExecutable(installDir string) (p string)

GetDialogExecutable gets the installed Githooks dialog executable.

func GetGithooksDir

func GetGithooksDir(repoDir string) string

GetGithooksDir gets the hooks directory for Githooks inside a repository (bare, non-bare).

func GetGlobalGitConfigKeys

func GetGlobalGitConfigKeys() []string

GetGlobalGitConfigKeys gets all global git config keys relevant for Githooks.

func GetHookIgnoreFileGitDir

func GetHookIgnoreFileGitDir(gitDir string) string

GetHookIgnoreFileGitDir gets the file of all ignored hooks in the current Git directory.

func GetHookIgnoreFilesHooksDir

func GetHookIgnoreFilesHooksDir(repoHooksDir string, hookNames []string) (files []string)

GetHookIgnoreFilesHooksDir gets ignores files inside the hook directory.

func GetHookIngoreFileHooksDir

func GetHookIngoreFileHooksDir(repoHooksDir string, hookName string) string

GetHookIngoreFileHooksDir gets ignores files inside the hook directory. The `hookName` can be empty.

func GetHookReplacementFileName

func GetHookReplacementFileName(fileName string) string

GetHookReplacementFileName returns the file name of a replaced custom Git hook.

func GetHookRunCmd

func GetHookRunCmd(
	hookPath string,
	parseRunnerConfig bool,
	rootDir string) (cm.IExecutable, error)

GetHookRunCmd gets the executable for the hook `hookPath`. Any command in a runner config YAML with path separators will be made absolute to `rootDir`.

func GetHookTagNameMappings

func GetHookTagNameMappings() []string

GetHookTagNameMappings gets the mapping of a hook tag to a name. Indexable by `HookTagV`.

func GetHooksNamespace

func GetHooksNamespace(hookDir string) (s string, err error)

GetHooksNamespace get the namespace in which all hooks in `hooksDir` are residing.

func GetInstallDir

func GetInstallDir() string

GetInstallDir returns the Githooks install directory.

func GetInstallerExecutable

func GetInstallerExecutable(installDir string) cm.Executable

GetInstallerExecutable gets the global Githooks installer executable (cli with args).

func GetLFSRequiredFile

func GetLFSRequiredFile(repoDir string) (string, bool)

GetLFSRequiredFile gets the LFS-Required file inside the repository and `true` if existing.

func GetLocalGitConfigKeys

func GetLocalGitConfigKeys() []string

GetLocalGitConfigKeys gets all local git config keys relevant for Githooks.

func GetReadmeFile

func GetReadmeFile(repoDir string) string

GetReadmeFile gets the Githooks readme file inside a repository hooks directory.

func GetRegisterFile

func GetRegisterFile(installDir string) string

GetRegisterFile get the register file in the install directory. which holds all Git dirs where run-wrappers have been installed.

func GetReleaseCloneDir

func GetReleaseCloneDir(installDir string) string

GetReleaseCloneDir get the release clone directory inside the install dir.

func GetRepoSharedFile

func GetRepoSharedFile(repoDir string) string

GetRepoSharedFile gets the shared file with respect to the hooks dir in the repository.

func GetRepoSharedFileRel

func GetRepoSharedFileRel() string

GetRepoSharedFileRel gets the shared file with respect to the repository.

func GetRunnerExecutable

func GetRunnerExecutable(installDir string) (p string)

GetRunnerExecutable gets the installed Githooks runner executable.

func GetSharedCloneDir

func GetSharedCloneDir(installDir string, url string) string

GetSharedCloneDir gets the directory for all shared hook repo clones.

func GetSharedDir

func GetSharedDir(installDir string) string

GetSharedDir gets the shared directory where all shared clone reside inside the install dir.

func GetSharedGithooksDir

func GetSharedGithooksDir(repoDir string) string

GetSharedGithooksDir gets the hooks directory for Githooks inside a shared repository.

func GetSharedHookTypeString

func GetSharedHookTypeString(sharedType SharedHookType) string

GetSharedHookTypeString translates the shared type enum to a string.

func GetSharedRepoTagNames

func GetSharedRepoTagNames() []string

GetSharedRepoTagNames gets the tag names corresponding to `SharedHookTypeV`.

func GetStagedFiles

func GetStagedFiles(gitx *git.Context) (string, error)

GetStagedFiles gets all currently staged files.

func GetTemporaryDir

func GetTemporaryDir(installDir string) string

GetTemporaryDir returns the Githooks temporary directory inside the install directory.

func GetTrustAllSetting

func GetTrustAllSetting(gitx *git.Context) (trustall bool, isSet bool)

GetTrustAllSetting gets the trust-all setting in the local Git configuration.

func GetTrustMarkerFile

func GetTrustMarkerFile(repoDir string) string

GetTrustMarkerFile get the trust marker file in the current repo.

func GetUninstallerExecutable

func GetUninstallerExecutable(installDir string) cm.Executable

GetUninstallerExecutable gets the global Githooks uninstaller executable (cli with args).

func InstallLFSHooks

func InstallLFSHooks(gitDir string) error

InstallLFSHooks installs LFS Hooks into `gitDir`.

func InstallRunWrappers

func InstallRunWrappers(
	dir string,
	hookNames []string,
	beforeSaveCallback func(file string),
	disableHookIfLFS func(file string) HookDisableOption,
	log cm.ILogContext) error

InstallRunWrappers installs run-wrappers for the given `hookNames` in `dir`. Existing custom hooks get renamed. All deleted hooks by this function get moved to the `tempDir` directory, because we should not delete them yet.

func IsGithooksDisabled

func IsGithooksDisabled(gitx *git.Context, checkEnv bool) bool

IsGithooksDisabled checks if Githooks is disabled in any config starting from the working dir given by the git context or optional also by the env. variable `GITHOOKS_DISABLE`.

func IsHookPatternValid

func IsHookPatternValid(pattern string) bool

IsHookPatternValid validates a ignore `pattern`. This test supports `globstar` syntax.

func IsRepoTrusted

func IsRepoTrusted(
	gitx *git.Context,
	repoPath string) (isTrusted bool, hasTrustFile bool)

IsRepoTrusted tells if the repository `repoPath` is trusted. It is only trusted if the trust marker is present and the `trustAll` settings is set to `trusted`. On any error `false` is reported together with the error.

func IsRunWrapper

func IsRunWrapper(filePath string) (bool, error)

IsRunWrapper answers the question if `filePath` is a Githooks hook template file.

func IsRunnerNonInteractive

func IsRunnerNonInteractive(gitx *git.Context, scope git.ConfigScope) bool

IsRunnerNonInteractive tells if the runner should run in non-interactive mode meaning all non-fatal prompts will be skipped with default answering and fatal prompts still need to be configured to pass.

func IsSharedHooksUpdateDisabled

func IsSharedHooksUpdateDisabled(gitx *git.Context, scope git.ConfigScope) (disabled bool, isSet bool)

IsSharedHooksUpdateDisable checks if automatic updates for shared hooks is disabled.

func MakeNamespacePath

func MakeNamespacePath(basePath string, path string, namespace string) (string, error)

MakeNamespacePath makes `path` relative to `basePath` and adds `namespace/` as prefix if not empty.

func MarkRepoRegistered

func MarkRepoRegistered(gitx *git.Context) error

MarkRepoRegistered sets the register flag inside the repo to denote the repository as registered.

func ModifyGlobalSharedHooks

func ModifyGlobalSharedHooks(gitx *git.Context, url string, remove bool) (modified bool, err error)

ModifyGlobalSharedHooks adds/removes a URL to the global shared hooks.

func ModifyLocalSharedHooks

func ModifyLocalSharedHooks(gitx *git.Context, url string, remove bool) (modified bool, err error)

ModifyLocalSharedHooks adds/removes a URL to the local shared hooks.

func ModifyRepoSharedHooks

func ModifyRepoSharedHooks(repoDir string, url string, remove bool) (modified bool, err error)

ModifyRepoSharedHooks adds/removes a URL to the repository shared hooks.

func PurgeSharedDir

func PurgeSharedDir(installDir string) error

PurgeSharedDir purges all shared hook repositories.

func RegisterRepo

func RegisterRepo(absGitDir string, installDir string, filterExisting bool, filterGitDirs bool) error

RegisterRepo registers the Git directory in the install directory.

func SetCLIExecutableAlias

func SetCLIExecutableAlias(path string) error

SetCLIExecutableAlias sets the global Githooks runner executable.

func SetDialogExecutableConfig

func SetDialogExecutableConfig(path string) error

SetDialogExecutableConfig sets the global Githooks dialog executable.

func SetDisableSharedHooksUpdate

func SetDisableSharedHooksUpdate(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error

SetDisableSharedHooksUpdate sets settings if the hook runner should disable automatic updates for shared hooks.

func SetInstallDir

func SetInstallDir(path string) error

SetInstallDir sets the global Githooks install directory.

func SetRunnerExecutableAlias

func SetRunnerExecutableAlias(path string) error

SetRunnerExecutableAlias sets the global Githooks runner executable.

func SetRunnerNonInteractive

func SetRunnerNonInteractive(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error

SetRunnerNonInteractive sets the runner to non-interactive mode.

func SetSkipNonExistingSharedHooks

func SetSkipNonExistingSharedHooks(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error

SetSkipNonExistingSharedHooks sets settings if the hook runner should fail on non existing hooks.

func SetSkipUntrustedHooks

func SetSkipUntrustedHooks(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error

SetSkipUntrustedHooks sets the settings if the hook runner should fail on active non-trusted hooks.

func SetTrustAllSetting

func SetTrustAllSetting(gitx *git.Context, enable bool, reset bool) error

SetTrustAllSetting sets the trust-all setting in the local Git configuration.

func SkipNonExistingSharedHooks

func SkipNonExistingSharedHooks(gitx *git.Context, scope git.ConfigScope) (enabled bool, isSet bool)

SkipNonExistingSharedHooks gets the settings if the hook runner should fail on non existing hooks.

func SkipUntrustedHooks

func SkipUntrustedHooks(gitx *git.Context, scope git.ConfigScope) (enabled bool, isSet bool)

SkipUntrustedHooks gets the settings if the hook runner should fail on active non-trusted hooks.

func StoreHookPatternsGitDir

func StoreHookPatternsGitDir(patterns HookPatterns, gitDirWorktree string) error

StoreHookPatternsGitDir stores all ignored hooks in the worktrees Git directory `gitDirWorktree`.

func StoreIgnorePatterns

func StoreIgnorePatterns(patterns HookPatterns, file string) (err error)

StoreIgnorePatterns stores patterns.

func UninstallRunWrappers

func UninstallRunWrappers(dir string, hookNames []string) (err error)

UninstallRunWrappers deletes run-wrappers in `dir`. Existing replaced hooks get renamed.

func UpdateAllSharedHooks

func UpdateAllSharedHooks(
	log cm.ILogContext,
	gitx *git.Context,
	installDir string,
	repoDir string) (updated int, err error)

UpdateAllSharedHooks all shared hooks tries to update all shared hooks. The argument `repoDir` can be empty which will skip local shared repositories.

func UpdateSharedHooks

func UpdateSharedHooks(
	log cm.ILogContext,
	sharedHooks []SharedRepo,
	sharedType SharedHookType) (updateCount int, err error)

UpdateSharedHooks updates all shared hooks `sharedHooks`. It clones or pulls latest changes in the shared clones. The `log` can be nil.

func WriteReadmeFile

func WriteReadmeFile(filePath string) (err error)

WriteReadmeFile writes the readme content to `file`.

func WriteRunWrapper

func WriteRunWrapper(filePath string) (err error)

WriteRunWrapper writes the run-wrapper to the file `filePath`.

Types

type ChecksumData

type ChecksumData struct {
	Paths []string
}

ChecksumData represents the data for one checksum which was stored.

type ChecksumResult

type ChecksumResult struct {
	SHA1          string // SHA1 hash.
	Path          string // Path.
	NamespacePath string // Namespaced path.
}

ChecksumResult defines the SHA1 hash and the path it was computed with together with the namespaced path.

type ChecksumStore

type ChecksumStore struct {
	// contains filtered or unexported fields
}

ChecksumStore represents a set of checksum which can be consulted to check if a hook is trusted or not.

func GetChecksumStorage

func GetChecksumStorage(gitx *git.Context, gitDirWorktree string) (store ChecksumStore, err error)

GetChecksumStorage loads the checksum store from the Git config 'GitCKChecksumCacheDir' and if not possible from the current Git directory.

func NewChecksumStore

func NewChecksumStore(path string, addAsDirIfNonExisting bool) (ChecksumStore, error)

NewChecksumStore creates a checksum store from `path` (file or directory).

func (*ChecksumStore) AddChecksum

func (t *ChecksumStore) AddChecksum(sha1 string, filePath string) bool

AddChecksum adds a SHA1 checksum of a path and returns if it was added (or it existed already).

func (*ChecksumStore) AddChecksums

func (t *ChecksumStore) AddChecksums(path string, addAsDirIfNonExisting bool) error

AddChecksums adds checksum data from `path` (file or directory) to the store.

func (*ChecksumStore) IsTrusted

func (t *ChecksumStore) IsTrusted(filePath string) (bool, string, error)

IsTrusted checks if a path has been trusted.

func (*ChecksumStore) Summary

func (t *ChecksumStore) Summary() string

Summary returns a summary of the checksum store.

func (*ChecksumStore) SyncChecksumAdd

func (t *ChecksumStore) SyncChecksumAdd(checksums ...ChecksumResult) error

SyncChecksumAdd adds SHA1 checksums of a path to the first search directory.

func (*ChecksumStore) SyncChecksumRemove

func (t *ChecksumStore) SyncChecksumRemove(sha1s ...string) (removed int, err error)

SyncChecksumRemove removes SHA1 checksums of a path from the first search directory.

type Hook

type Hook struct {
	// The executable of the hook.
	cm.IExecutable

	// The path to the file which configured this executable.
	Path string

	// The namespaced path of the hook `<namespace>/<relPath>`.
	NamespacePath string

	// If the hook is not ignored by any ignore patterns.
	// Has priority 1 for execution determination.
	Active bool
	// If the hook is trusted by means of the chechsum store.
	// Has priority 2 for execution determination.
	Trusted bool

	// SHA1 hash of the hook. (if determined)
	SHA1 string

	// BatchName denotes the parallel batch
	BatchName string
}

Hook contains the data to an executable hook.

func GetAllHooksIn

func GetAllHooksIn(
	rootDir string,
	hooksDir string,
	hookName string,
	hookNamespace string,
	isIgnored IngoreCallback,
	isTrusted TrustCallback,
	lazyIfIgnored bool,
	parseRunnerConfig bool) (allHooks []Hook, maxBatches int, err error)

GetAllHooksIn gets all hooks with name `hookName` in hooks dir `hookDir`. The reported `maxBatches` might include empty ones.

func (*Hook) AssertSHA1

func (h *Hook) AssertSHA1() (err error)

AssertSHA1 ensures that the hook has its SHA1 computed.

type HookDisableOption

type HookDisableOption int

HookDisableOption are the options how to disable a hook.

const (
	// BackupHook defines that a hook file gets backuped.
	BackupHook HookDisableOption = 1
	// DeleteHook defines that a hook file gets deleted.
	DeleteHook HookDisableOption = 2
)

type HookPatterns

type HookPatterns struct {
	Patterns       []string
	NamespacePaths []string
}

HookPatterns for matching the namespace path of hooks.

func CombineIgnorePatterns

func CombineIgnorePatterns(patterns ...*HookPatterns) HookPatterns

CombineIgnorePatterns combines two ignore patterns.

func GetHookPatternsHooksDir

func GetHookPatternsHooksDir(repoHooksDir string, hookNames []string) (patterns HookPatterns, err error)

GetHookPatternsHooksDir gets all ignored hooks in the hook directory.

func LoadIgnorePatterns

func LoadIgnorePatterns(file string) (patterns HookPatterns, err error)

LoadIgnorePatterns loads patterns.

func (*HookPatterns) Add

func (h *HookPatterns) Add(p *HookPatterns)

Add adds pattern from patterns `p` to itself.

func (*HookPatterns) AddNamespacePaths

func (h *HookPatterns) AddNamespacePaths(namespacePath ...string)

AddNamespacePaths adds a namespace path to the patterns.

func (*HookPatterns) AddNamespacePathsUnique

func (h *HookPatterns) AddNamespacePathsUnique(namespacePath ...string) (added int)

AddNamespacePathsUnique adds a namespace path to the patterns.

func (*HookPatterns) AddPatterns

func (h *HookPatterns) AddPatterns(pattern ...string)

AddPatterns adds pattern to the patterns.

func (*HookPatterns) AddPatternsUnique

func (h *HookPatterns) AddPatternsUnique(pattern ...string) (added int)

AddPatternsUnique adds a namespace path to the patterns.

func (*HookPatterns) AddUnique

func (h *HookPatterns) AddUnique(p *HookPatterns) (added int)

AddUnique adds pattern uniquely from patterns `p` to itself.

func (*HookPatterns) GetCount

func (h *HookPatterns) GetCount() int

GetCount gets the count of all patterns.

func (*HookPatterns) IsEmpty

func (h *HookPatterns) IsEmpty() bool

IsEmpty checks if there are any patterns stored.

func (*HookPatterns) Matches

func (h *HookPatterns) Matches(namespacePath string) (matched bool)

Matches returns true if `namespacePath` matches any of the patterns and otherwise `false`.

func (*HookPatterns) Remove

func (h *HookPatterns) Remove(p *HookPatterns) (removed int)

Remove removes pattern from patterns `p` to itself.

func (*HookPatterns) RemoveAll

func (h *HookPatterns) RemoveAll() (removed int)

RemoveAll removes all patterns.

func (*HookPatterns) RemoveNamespacePaths

func (h *HookPatterns) RemoveNamespacePaths(namespacePath ...string) (removed int)

RemoveNamespacePaths adds a namespace path to the patterns.

func (*HookPatterns) RemovePatterns

func (h *HookPatterns) RemovePatterns(pattern ...string) (removed int)

RemovePatterns removes patterns from the list.

func (*HookPatterns) Reserve

func (h *HookPatterns) Reserve(nPatterns int)

Reserve reserves 'nPatterns'.

type HookPrioList

type HookPrioList [][]Hook

HookPrioList is a list of lists of executable hooks. Each list contains a set of hooks which can potentially be executed in parallel.

func (*HookPrioList) GetHooksCount

func (h *HookPrioList) GetHooksCount() (count int)

GetHooksCount gets the number of all hooks in the priority list.

type HookResult

type HookResult struct {
	Hook   *Hook
	Output []byte
	Error  error
}

HookResult is the data assembly of the output of an executed hook.

func ExecuteHooksParallel

func ExecuteHooksParallel(
	pool *thx.ThreadPool,
	exec cm.IExecContext,
	hs *HookPrioList,
	res []HookResult,
	outputCallback func(res ...HookResult),
	args ...string) ([]HookResult, error)

ExecuteHooksParallel executes hooks in parallel over a thread pool.

type Hooks

type Hooks struct {
	LocalHooks        HookPrioList
	RepoSharedHooks   HookPrioList
	LocalSharedHooks  HookPrioList
	GlobalSharedHooks HookPrioList
}

Hooks is a collection of all executable hooks. Json serialization is only for debug pruposes.

func (*Hooks) GetHooksCount

func (h *Hooks) GetHooksCount() int

GetHooksCount gets the number of all hooks.

func (*Hooks) StoreJSON

func (h *Hooks) StoreJSON(writer io.Writer) error

StoreJSON stores the hooks priority list in JSON to the writer.

type IngoreCallback

type IngoreCallback = func(namespacePath string) (ignored bool)

IngoreCallback is the callback type for ignoring hooks.

type RegisterRepos

type RegisterRepos struct {
	GitDirs []string `yaml:"git-dirs"`
}

RegisterRepos is the format of the register file in the install folder.

func (*RegisterRepos) FilterExisting

func (r *RegisterRepos) FilterExisting()

FilterExisting filter by existing directories.

func (*RegisterRepos) FilterGitDirs

func (r *RegisterRepos) FilterGitDirs()

FilterGitDirs filter by Git directories.

func (*RegisterRepos) Insert

func (r *RegisterRepos) Insert(gitDir string) (inserted bool)

Insert adds a repository Git directory uniquely.

func (*RegisterRepos) Load

func (r *RegisterRepos) Load(installDir string, filterExisting bool, filterGitDirs bool) (err error)

Load gets the registered repos loaded from the register file in the install folder.

func (*RegisterRepos) Remove

func (r *RegisterRepos) Remove(gitDir string) (removed int)

Remove removes a repository Git directory.

func (*RegisterRepos) Store

func (r *RegisterRepos) Store(installDir string) (err error)

Store sets the registered repos to the register file in the install folder.

type RepoIgnorePatterns

type RepoIgnorePatterns struct {
	HooksDir HookPatterns // Ignores set by `.ignore` file in the hooks directory of the repository.
	User     HookPatterns // Ignores set by the `.ignore` file in the Git directory of the repository.
}

RepoIgnorePatterns is the list of possible ignore patterns in a repository.

func GetIgnorePatterns

func GetIgnorePatterns(
	repoHooksDir string,
	gitDirWorktree string,
	hookNames []string) (patt RepoIgnorePatterns, err error)

GetIgnorePatterns loads all ignore patterns in the worktree's hooks dir and also in the worktrees Git directory.

func (*RepoIgnorePatterns) IsIgnored

func (h *RepoIgnorePatterns) IsIgnored(namespacePath string) (bool, bool)

IsIgnored returns `true` if the hooksPath is ignored by either the worktree patterns or the user patterns and otherwise `false`. The second value is `true` if it was ignored by the user patterns.

type SharedHookType

type SharedHookType int

SharedHookType is the enum type of the shared hook type.

type SharedRepo

type SharedRepo struct {
	OriginalURL string // Original URL.

	IsCloned bool   // If the repo needs to be cloned.
	URL      string // The clone URL.
	Branch   string // The clone branch.

	IsLocal bool // If the original URL points to a local directory.

	RepositoryDir string // The shared hook repository directory.
}

SharedRepo holds the data for a shared hook.

func LoadConfigSharedHooks

func LoadConfigSharedHooks(
	installDir string,
	gitx *git.Context,
	scope git.ConfigScope) (hooks []SharedRepo, err error)

LoadConfigSharedHooks gets all shared hooks that are specified in the local/global Git configuration. No checks are made to the filesystem if paths are existing in `SharedHook`.

func LoadRepoSharedHooks

func LoadRepoSharedHooks(installDir string, repoDir string) (hooks []SharedRepo, err error)

LoadRepoSharedHooks gets all shared hooks that reside inside `hooks.GetRepoSharedFile()` No checks are made to the filesystem if paths are existing in `SharedHook`.

func (*SharedRepo) IsCloneValid

func (s *SharedRepo) IsCloneValid() bool

IsCloneValid checks if the cloned shared hook repository is valid, contains the same remote URL as the requested.

type SharedRepos

type SharedRepos [][]SharedRepo

SharedRepos a collection of all shared repos. Indexable by `SharedHookTypeV`.

func NewSharedRepos

func NewSharedRepos(capacity int) (res SharedRepos)

NewSharedRepos returns a collection of all shared repos. Indexable by `SharedHookTypeV`.

func (*SharedRepos) GetCount

func (s *SharedRepos) GetCount() (count int)

GetCount gets the count of all shared repos.

type TaggedHooks

type TaggedHooks [][]Hook

TaggedHooks represents a map for all hooks sorted by tags. A list of hooks for each index `TaggedHookIndices`.

func NewTaggedHooks

func NewTaggedHooks(capacity int) (res TaggedHooks)

NewTaggedHooks returns a slice of hooks for each index `TaggedHookIndices`.

type TaggedHooksIndex

type TaggedHooksIndex int

TaggedHooksIndex is the index type for hook tags.

type TrustCallback

type TrustCallback = func(hookPath string) (trusted bool, sha1 string)

TrustCallback is the callback type for trusting hooks.

Jump to

Keyboard shortcuts

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