Skip to content

Conversation

lvrach
Copy link
Member

@lvrach lvrach commented Oct 3, 2025

Introduce a clean-local-hooks [hooks] command, that will recursively search for git repositories that contain a hookPath configuration in .git/config

Local hookPath overrides prevent the global git-hooks from running.

To test locally, download the repo and do:

go run . clean-local-hooks ~

🔒 Scanned for secrets using gitleaks 8.28.0
@lvrach lvrach marked this pull request as ready for review October 3, 2025 10:42
@lvrach lvrach requested a review from arpl October 3, 2025 10:42
ExitSuccess = 0
ExitPartialSuccess = 1
ExitFailure = 2
ExitUserCancelled = 3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you planning to use these? They seem unused atm.

verbose := c.Bool("verbose")
force := c.Bool("force")

ctx := context.Background()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point in passing this context around, right? You could use signal.NotifyContext at least we can gracefully terminate the scanning with a single CTRL+C.

if err := removeHooksPath(&repos[i]); err != nil {
res.Error = err
} else {
res.Removed = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're here, isn't res.Removed already true?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this make more sense? 🤔

if err := removeHooksPath(&repos[i]); err != nil {
    res.Error = err
} else {
    res.Removed = true
    sum.ConfigsRemoved++
}

entries, err := os.ReadDir(path)
if err != nil {
if os.IsPermission(err) {
return nil // Skip permission errors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could print a warning here.

`
err = os.WriteFile(configPath, []byte(configContent), 0o644)
if err != nil {
t.Fatalf("Failed to write config: %v", err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] You can consider using the usual require for all assertions to increase readability and for consistency across Go projects.

return nil, err
}

err = walkDir(ctx, absRoot, 0, maxDepth, func(r Repository) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] could have used github.com/karrick/godirwalk
it's faster (and imo also easier to use)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants