Documentation ¶
Index ¶
- Constants
- Variables
- func AllHooksSuccessful(results []HookResult) bool
- func AllowLocalURLInRepoSharedHooks() bool
- func AssertTemporaryDir(installDir string) (tempDir string, err error)
- func CleanTemporaryDir(installDir string) (string, error)
- func ClearGlobalSharedHooks() error
- func ClearLocalSharedHooks(gitx *git.Context) error
- func ClearRepoSharedHooks(repoDir string) error
- func DeleteHookDirTemp(hookDir string) (err error)
- func GetBinaryDir(installDir string) string
- func GetBugReportingInfo(repoPath string) (info string, err error)
- func GetCLIExecutable(installDir string) cm.Executable
- func GetChecksumDirectoryGitDir(gitDir string) string
- func GetDefaultHooksNamespaceShared(sharedRepo *SharedRepo) string
- func GetDefaultRunner(hookPath string) cm.IExecutable
- func GetDialogExecutable(installDir string) (p string)
- func GetGithooksDir(repoDir string) string
- func GetGlobalGitConfigKeys() []string
- func GetHookIgnoreFileGitDir(gitDir string) string
- func GetHookIgnoreFilesHooksDir(repoHooksDir string, hookNames []string) (files []string)
- func GetHookIngoreFileHooksDir(repoHooksDir string, hookName string) string
- func GetHookReplacementFileName(fileName string) string
- func GetHookRunCmd(hookPath string, parseRunnerConfig bool, rootDir string) (cm.IExecutable, error)
- func GetHookTagNameMappings() []string
- func GetHooksNamespace(hookDir string) (s string, err error)
- func GetInstallDir() string
- func GetInstallerExecutable(installDir string) cm.Executable
- func GetLFSRequiredFile(repoDir string) (string, bool)
- func GetLocalGitConfigKeys() []string
- func GetReadmeFile(repoDir string) string
- func GetRegisterFile(installDir string) string
- func GetReleaseCloneDir(installDir string) string
- func GetRepoSharedFile(repoDir string) string
- func GetRepoSharedFileRel() string
- func GetRunnerExecutable(installDir string) (p string)
- func GetSharedCloneDir(installDir string, url string) string
- func GetSharedDir(installDir string) string
- func GetSharedGithooksDir(repoDir string) string
- func GetSharedHookTypeString(sharedType SharedHookType) string
- func GetSharedRepoTagNames() []string
- func GetStagedFiles(gitx *git.Context) (string, error)
- func GetTemporaryDir(installDir string) string
- func GetTrustAllSetting(gitx *git.Context) (trustall bool, isSet bool)
- func GetTrustMarkerFile(repoDir string) string
- func GetUninstallerExecutable(installDir string) cm.Executable
- func InstallLFSHooks(gitDir string) error
- func InstallRunWrappers(dir string, hookNames []string, beforeSaveCallback func(file string), ...) error
- func IsGithooksDisabled(gitx *git.Context, checkEnv bool) bool
- func IsHookPatternValid(pattern string) bool
- func IsRepoTrusted(gitx *git.Context, repoPath string) (isTrusted bool, hasTrustFile bool)
- func IsRunWrapper(filePath string) (bool, error)
- func IsRunnerNonInteractive(gitx *git.Context, scope git.ConfigScope) bool
- func IsSharedHooksUpdateDisabled(gitx *git.Context, scope git.ConfigScope) (disabled bool, isSet bool)
- func MakeNamespacePath(basePath string, path string, namespace string) (string, error)
- func MarkRepoRegistered(gitx *git.Context) error
- func ModifyGlobalSharedHooks(gitx *git.Context, url string, remove bool) (modified bool, err error)
- func ModifyLocalSharedHooks(gitx *git.Context, url string, remove bool) (modified bool, err error)
- func ModifyRepoSharedHooks(repoDir string, url string, remove bool) (modified bool, err error)
- func PurgeSharedDir(installDir string) error
- func RegisterRepo(absGitDir string, installDir string, filterExisting bool, filterGitDirs bool) error
- func SetCLIExecutableAlias(path string) error
- func SetDialogExecutableConfig(path string) error
- func SetDisableSharedHooksUpdate(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error
- func SetInstallDir(path string) error
- func SetRunnerExecutableAlias(path string) error
- func SetRunnerNonInteractive(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error
- func SetSkipNonExistingSharedHooks(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error
- func SetSkipUntrustedHooks(gitx *git.Context, enable bool, reset bool, scope git.ConfigScope) error
- func SetTrustAllSetting(gitx *git.Context, enable bool, reset bool) error
- func SkipNonExistingSharedHooks(gitx *git.Context, scope git.ConfigScope) (enabled bool, isSet bool)
- func SkipUntrustedHooks(gitx *git.Context, scope git.ConfigScope) (enabled bool, isSet bool)
- func StoreHookPatternsGitDir(patterns HookPatterns, gitDirWorktree string) error
- func StoreIgnorePatterns(patterns HookPatterns, file string) (err error)
- func UninstallRunWrappers(dir string, hookNames []string) (err error)
- func UpdateAllSharedHooks(log cm.ILogContext, gitx *git.Context, installDir string, repoDir string) (updated int, err error)
- func UpdateSharedHooks(log cm.ILogContext, sharedHooks []SharedRepo, sharedType SharedHookType) (updateCount int, err error)
- func WriteReadmeFile(filePath string) (err error)
- func WriteRunWrapper(filePath string) (err error)
- type ChecksumData
- type ChecksumResult
- type ChecksumStore
- func (t *ChecksumStore) AddChecksum(sha1 string, filePath string) bool
- func (t *ChecksumStore) AddChecksums(path string, addAsDirIfNonExisting bool) error
- func (t *ChecksumStore) IsTrusted(filePath string) (bool, string, error)
- func (t *ChecksumStore) Summary() string
- func (t *ChecksumStore) SyncChecksumAdd(checksums ...ChecksumResult) error
- func (t *ChecksumStore) SyncChecksumRemove(sha1s ...string) (removed int, err error)
- type Hook
- type HookDisableOption
- type HookPatterns
- func (h *HookPatterns) Add(p *HookPatterns)
- func (h *HookPatterns) AddNamespacePaths(namespacePath ...string)
- func (h *HookPatterns) AddNamespacePathsUnique(namespacePath ...string) (added int)
- func (h *HookPatterns) AddPatterns(pattern ...string)
- func (h *HookPatterns) AddPatternsUnique(pattern ...string) (added int)
- func (h *HookPatterns) AddUnique(p *HookPatterns) (added int)
- func (h *HookPatterns) GetCount() int
- func (h *HookPatterns) IsEmpty() bool
- func (h *HookPatterns) Matches(namespacePath string) (matched bool)
- func (h *HookPatterns) Remove(p *HookPatterns) (removed int)
- func (h *HookPatterns) RemoveAll() (removed int)
- func (h *HookPatterns) RemoveNamespacePaths(namespacePath ...string) (removed int)
- func (h *HookPatterns) RemovePatterns(pattern ...string) (removed int)
- func (h *HookPatterns) Reserve(nPatterns int)
- type HookPrioList
- type HookResult
- type Hooks
- type IngoreCallback
- type RegisterRepos
- func (r *RegisterRepos) FilterExisting()
- func (r *RegisterRepos) FilterGitDirs()
- func (r *RegisterRepos) Insert(gitDir string) (inserted bool)
- func (r *RegisterRepos) Load(installDir string, filterExisting bool, filterGitDirs bool) (err error)
- func (r *RegisterRepos) Remove(gitDir string) (removed int)
- func (r *RegisterRepos) Store(installDir string) (err error)
- type RepoIgnorePatterns
- type SharedHookType
- type SharedRepo
- type SharedRepos
- type TaggedHooks
- type TaggedHooksIndex
- type TrustCallback
Constants ¶
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.
const ( GitCKRegistered = "githooks.registered" GitCKTrustAll = "githooks.trustAll" )
Git config keys for local config.
const ( GitCKSkipUntrustedHooks = "githooks.skipUntrustedHooks" GitCKRunnerIsNonInteractive = "githooks.runnerIsNonInteractive" )
Git config keys for local/global config.
const ( // TagNameReplaced is the hook tag for replaced hooks. TagNameReplaced = "replaced" // TagNameRepository is the hook tag for repository hooks. TagNameRepository = "repo" TagNameSharedRepo = "shared:repo" TagNameSharedLocal = "shared:local" TagNameSharedGLobal = "shared:global" )
const ( // NamespaceRepositoryHook is the namespace for repository hooks. NamespaceRepositoryHook = "" // NamespaceReplacedHook is the namespace for replace hooks. NamespaceReplacedHook = "hooks" )
const DefaultBugReportingURL = "https://github.com/gabyx/githooks/issues"
DefaultBugReportingURL is the default url to report errors.
const EnvVariableArch = "GITHOOKS_ARCH"
EnvVariableArch is the environment variable which holds runtime architecture name.
const EnvVariableOs = "GITHOOKS_OS"
EnvVariableOs is the environment variable which holds runtime operating system name.
const EnvVariableStagedFiles = "STAGED_FILES"
EnvVariableStagedFiles is the environment variable which holds the staged files.
const GithooksWebpage = "https://github.com/gabyx/githooks"
GithooksWebpage is the main Githooks webpage.
const HooksDirName = ".githooks"
HooksDirName denotes the directory name used for repository specific hooks.
const (
// SHA1Length is the string length of a SHA1 hash.
SHA1Length = 40
)
const ( // UseThreadPool defines if a threadpool is used to execute the hooks. UseThreadPool = true )
Variables ¶
var LFSHookNames = [4]string{
"post-checkout",
"post-commit",
"post-merge",
"pre-push"}
LFSHookNames are the hook names of all Large File System (LFS) hooks.
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.
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.
SharedHookTypeV enumerates all types of shared hooks.
var StagedFilesHookNames = [3]string{"pre-commit", "prepare-commit-msg", "commit-msg"}
StagedFilesHookNames are the hook names on which staged files are exported.
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 ¶
AssertTemporaryDir returns the Githooks temporary directory inside the install directory.
func CleanTemporaryDir ¶
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 ¶
ClearLocalSharedHooks clears the shared hook list in the local Git config.
func ClearRepoSharedHooks ¶
ClearRepoSharedHooks clears the shared hook list in the repository.
func DeleteHookDirTemp ¶
DeleteHookDirTemp deletes the temporary director inside the Git's hook directory.
func GetBinaryDir ¶
GetBinaryDir returns the Githooks binary directory inside the install directory.
func GetBugReportingInfo ¶
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 ¶
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 ¶
GetDialogExecutable gets the installed Githooks dialog executable.
func GetGithooksDir ¶
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 ¶
GetHookIgnoreFileGitDir gets the file of all ignored hooks in the current Git directory.
func GetHookIgnoreFilesHooksDir ¶
GetHookIgnoreFilesHooksDir gets ignores files inside the hook directory.
func GetHookIngoreFileHooksDir ¶
GetHookIngoreFileHooksDir gets ignores files inside the hook directory. The `hookName` can be empty.
func GetHookReplacementFileName ¶
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 ¶
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 ¶
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 ¶
GetReadmeFile gets the Githooks readme file inside a repository hooks directory.
func GetRegisterFile ¶
GetRegisterFile get the register file in the install directory. which holds all Git dirs where run-wrappers have been installed.
func GetReleaseCloneDir ¶
GetReleaseCloneDir get the release clone directory inside the install dir.
func GetRepoSharedFile ¶
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 ¶
GetRunnerExecutable gets the installed Githooks runner executable.
func GetSharedCloneDir ¶
GetSharedCloneDir gets the directory for all shared hook repo clones.
func GetSharedDir ¶
GetSharedDir gets the shared directory where all shared clone reside inside the install dir.
func GetSharedGithooksDir ¶
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 ¶
GetStagedFiles gets all currently staged files.
func GetTemporaryDir ¶
GetTemporaryDir returns the Githooks temporary directory inside the install directory.
func GetTrustAllSetting ¶
GetTrustAllSetting gets the trust-all setting in the local Git configuration.
func GetTrustMarkerFile ¶
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 ¶
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 ¶
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 ¶
IsHookPatternValid validates a ignore `pattern`. This test supports `globstar` syntax.
func IsRepoTrusted ¶
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 ¶
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 ¶
MakeNamespacePath makes `path` relative to `basePath` and adds `namespace/` as prefix if not empty.
func MarkRepoRegistered ¶
MarkRepoRegistered sets the register flag inside the repo to denote the repository as registered.
func ModifyGlobalSharedHooks ¶
ModifyGlobalSharedHooks adds/removes a URL to the global shared hooks.
func ModifyLocalSharedHooks ¶
ModifyLocalSharedHooks adds/removes a URL to the local shared hooks.
func ModifyRepoSharedHooks ¶
ModifyRepoSharedHooks adds/removes a URL to the repository shared hooks.
func PurgeSharedDir ¶
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 ¶
SetCLIExecutableAlias sets the global Githooks runner executable.
func SetDialogExecutableConfig ¶
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 ¶
SetInstallDir sets the global Githooks install directory.
func SetRunnerExecutableAlias ¶
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 ¶
SetSkipUntrustedHooks sets the settings if the hook runner should fail on active non-trusted hooks.
func SetTrustAllSetting ¶
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 ¶
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 ¶
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 ¶
WriteReadmeFile writes the readme content to `file`.
func WriteRunWrapper ¶
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 ¶
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 ¶
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 ¶
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 }
Hooks is a collection of all executable hooks. Json serialization is only for debug pruposes.
func (*Hooks) GetHooksCount ¶
GetHooksCount gets the number of all hooks.
type IngoreCallback ¶
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 {}
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 TrustCallback ¶
TrustCallback is the callback type for trusting hooks.