Skip to content

Commit

Permalink
fix: Correct wrong directory check for the marker file (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx authored May 2, 2024
1 parent 9a9d9ca commit f950d47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion githooks/cmd/common/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CheckGithooksSetup(log cm.ILogContext, gitx *git.Context) {

gitDir, err := gitx.GetGitDirCommon()
log.AssertNoErrorF(err, "Could not determine common Git dir.")
hasRunWrappers, _ := cm.IsPathExisting(path.Join(gitDir, "githooks-contains-run-wrappers"))
hasRunWrappers, _ := cm.IsPathExisting(path.Join(gitDir, "hooks", hooks.RunWrapperMarkerFileName))

if hasHooksConfigured &&
!localCoreHooksPathSet && !globalCoreHooksPathSet &&
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 @@ -47,7 +47,7 @@ func InstallIntoRepo(
// a link `core.hooksPath`.
// We switch to run-wrappers if we install a set of maintained hooks.
// or repository settings have maintained hooks set.
installRunWrappers, _ := cm.IsPathExisting(path.Join(hooksDir, "githooks-contains-run-wrappers"))
installRunWrappers, _ := cm.IsPathExisting(path.Join(hooksDir, hooks.RunWrapperMarkerFileName))
log.DebugF("Marker file for run-wrappers detected: '%v'.", installRunWrappers)
installRunWrappers = installRunWrappers || hookNames != nil

Expand Down Expand Up @@ -197,7 +197,7 @@ func UninstallFromRepo(

// We always uninstall run-wrappers if any are existing.
// Also reinstalls LFS hooks.
// No need to check the marker file `.githooks-contains-run-wrappers`.
// No need to check the marker file `RunWrapperMarkerFileName`.
nLfsCount, err = hooks.UninstallRunWrappers(hooksDir, lfsHooksCache)
log.InfoF("Githooks has reinstalled '%v' LFS hooks into '%s'.", nLfsCount, hooksDir)

Expand Down
5 changes: 3 additions & 2 deletions githooks/hooks/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
strs "github.com/gabyx/githooks/githooks/strings"
)

var RunWrapperMarkerFileName = "githooks-contains-run-wrappers"
var runWrapperDetectionRegex = regexp.MustCompile(`https://github\.com/(gabyx|rycus86)/githooks`)

// IsRunWrapper answers the question if `filePath`
Expand Down Expand Up @@ -321,7 +322,7 @@ func InstallRunWrappers(
}
}

err = cm.TouchFile(path.Join(dir, "githooks-contains-run-wrappers"), true)
err = cm.TouchFile(path.Join(dir, RunWrapperMarkerFileName), true)
if err != nil {
err = cm.CombineErrors(err,
cm.ErrorF("Could not create marker that directory '%s' contains run-wrappers.", dir))
Expand Down Expand Up @@ -389,7 +390,7 @@ func uninstallRunWrappers(
}
}

_ = os.Remove(path.Join(dir, "githooks-contains-run-wrappers"))
_ = os.Remove(path.Join(dir, RunWrapperMarkerFileName))

return
}
Expand Down

0 comments on commit f950d47

Please sign in to comment.