Skip to content
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
8 changes: 4 additions & 4 deletions hook_pre-commit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"github.com/urfave/cli"
)

func HookPreCommitEnable(args []string) (string, error) {
Expand All @@ -14,16 +14,16 @@ func HookPreCommitDisable(args []string) error {

func HookPreCommitRun(args []string) error {
options := map[string]interface{}{
"commit": false,
"staged": true,
"commit-files": false,
"staged-files": true,
}

secrets, err := gs.RunCheck(options)
if err != nil {
return err
}
if secrets != 0 {
return fmt.Errorf("commit cannot proceed")
return cli.NewExitError("commit cannot proceed", 42)
}

return nil
Expand Down
31 changes: 31 additions & 0 deletions main_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/libgit2/git2go"
"github.com/urfave/cli"
"os"
"path"
)

type GitSeekretHookHandler struct {
Expand Down Expand Up @@ -77,6 +78,10 @@ func GitSeekretHook(c *cli.Context) error {
}
}

if run == "" {
listEnabledHooks()
}

return nil
}

Expand Down Expand Up @@ -164,3 +169,29 @@ func getHookFile(name string) (string, error) {
}
return hookfile, nil
}

func listEnabledHooks() error {
var n int

hookdir := fmt.Sprintf("%s/hooks", gs.repo)

hd, err := os.Open(hookdir)
if err != nil {
return err
}
defer hd.Close()

hooks, err := hd.Readdirnames(n)
fmt.Printf("Hooks Found:\n")
for _, hookfile := range hooks {
if path.Ext(hookfile) == "" {
fmt.Printf("\t%s\n", hookfile)
}
}

if err != nil {
return err
}

return nil
}