Skip to content

feat: configure the name of the checksums dir using env. var or git config #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions githooks/cmd/common/install/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func InstallIntoRepo(

func cleanArtefactsInRepo(log cm.ILogContext, gitDir string) {

// Remove checksum files...
cacheDir := hooks.GetChecksumDirectoryGitDir(gitDir)
// Remove local checksum files...
cacheDir := path.Join(gitDir, hooks.ChecksumsDir)
if cm.IsDirectory(cacheDir) {
log.AssertNoErrorF(os.RemoveAll(cacheDir),
"Could not delete checksum cache dir '%s'.", cacheDir)
Expand Down
5 changes: 5 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 Expand Up @@ -102,6 +104,8 @@ func GetGlobalGitConfigKeys() []string {
GitCKExportStagedFilesAsFile,

GitCKContainerizedHooksEnabled,

GitCKChecksumsDir,
}
}

Expand All @@ -126,6 +130,7 @@ func GetLocalGitConfigKeys() []string {
GitCKContainerizedHooksEnabled,

GitCKExportStagedFilesAsFile,
GitCKChecksumsDir,
}
}

Expand Down
3 changes: 3 additions & 0 deletions githooks/hooks/githooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const DialogExecutableName = "githooks-dialog"
const HooksDirName = ".githooks"
const HooksDirNameShared = "githooks"

// ChecksumsDir denotes the directory name used by default for storing checksums for trusted hooks.
const ChecksumsDir = ".githooks.checksums"

// GithooksWebpage is the main Githooks webpage.
const GithooksWebpage = "https://github.com/gabyx/githooks"

Expand Down
15 changes: 14 additions & 1 deletion githooks/hooks/trusted.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,20 @@ 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)
}

switch {
case !strs.IsEmpty(conf) && filepath.IsAbs(conf):
return conf
default:
return path.Join(gitDir, ChecksumsDir)
}
}

// GetChecksumStorage loads the checksum store from the
Expand Down