Skip to content
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

fix: Correct wrong directory check for the marker file #171

Merged
merged 2 commits into from
May 2, 2024
Merged
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: 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