Skip to content

Commit

Permalink
Configure the name of the checksums dir using env var or git config
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcire committed Oct 2, 2024
1 parent 1dc5cb5 commit 5da6231
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions githooks/apps/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func setupSettings(repoPath string) (HookSettings, UISettings) {
nonInteractive := hooks.IsRunnerNonInteractive(gitx, git.Traverse)
skipNonExistingSharedHooks := hooks.SkipNonExistingSharedHooks(gitx, git.Traverse)
skipUntrustedHooks, _ := hooks.SkipUntrustedHooks(gitx, git.Traverse)
checksumsDir := hooks.GetChecksumDirectoryGitDir(gitDir)

isTrusted, hasTrustFile, trustAllSet := hooks.IsRepoTrusted(gitx, repoPath)
if !isTrusted && hasTrustFile && !trustAllSet && !nonInteractive && !isGithooksDisabled {
Expand All @@ -188,6 +189,7 @@ func setupSettings(repoPath string) (HookSettings, UISettings) {
RepositoryHooksDir: path.Join(repoPath, hooks.HooksDirName),
GitDirWorktree: gitDir,
InstallDir: installDir,
ChecksumsDir: checksumsDir,

HookPath: hookPath,
HookName: path.Base(hookPath),
Expand Down
1 change: 1 addition & 0 deletions githooks/apps/runner/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type HookSettings struct {
HookName string // Name of the hook.
HookDir string // Directory of the hook.
HookNamespace string // Namespace of this repositorie's Githooks.
ChecksumsDir string // Name of the directory with the trust checksums

IsRepoTrusted bool // If the repository is a trusted repository.
SkipNonExistingSharedHooks bool // If Githooks should skip non-existing shared hooks.
Expand Down
2 changes: 2 additions & 0 deletions githooks/hooks/gitconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const (
GitCKContainerImageUpdateAutomatic = "githooks.containerImageUpdateAutomatic"

GitCKExportStagedFilesAsFile = "githooks.exportStagedFilesAsFile"

GitCKChecksumsDir = "githooks.checksumsDir"
)

// GetGlobalGitConfigKeys gets all global git config keys relevant for Githooks.
Expand Down
16 changes: 15 additions & 1 deletion githooks/hooks/trusted.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,21 @@ func (t *ChecksumStore) Summary() string {

// GetChecksumDirectoryGitDir gets the checksum file inside the Git directory.
func GetChecksumDirectoryGitDir(gitDir string) string {
return path.Join(gitDir, ".githooks.checksums")
var conf string
gitx := git.NewCtxAt(gitDir)
scope := git.Traverse
conf, set := os.LookupEnv("GITHOOKS_CHECKSUMS_DIR")
if !set {
conf = gitx.GetConfig(GitCKChecksumsDir, scope)
}

exists, _ := cm.IsPathExisting(path.Join(gitDir, conf))
switch {
case !strs.IsEmpty(conf) && exists:
return path.Join(gitDir, conf)
default:
return path.Join(gitDir, ".githooks.checksums")
}
}

// GetChecksumStorage loads the checksum store from the
Expand Down

0 comments on commit 5da6231

Please sign in to comment.