Skip to content

Commit

Permalink
ChecksumsDir used to set absolute path to a centralized directory
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcire committed Oct 11, 2024
1 parent fe148cb commit 82b824f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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
3 changes: 3 additions & 0 deletions githooks/hooks/gitconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func GetGlobalGitConfigKeys() []string {
GitCKExportStagedFilesAsFile,

GitCKContainerizedHooksEnabled,

GitCKChecksumsDir,
}
}

Expand All @@ -128,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
7 changes: 3 additions & 4 deletions githooks/hooks/trusted.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,11 @@ func GetChecksumDirectoryGitDir(gitDir string) string {
conf = gitx.GetConfig(GitCKChecksumsDir, scope)
}

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

Expand Down

0 comments on commit 82b824f

Please sign in to comment.