Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
frankywahl committed Mar 23, 2022
1 parent 497c406 commit 5b975ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
27 changes: 8 additions & 19 deletions hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,15 @@ func isExecutable(f os.FileInfo) bool {

func allPath() []string {
paths := []string{}
if out, err := git.GlobalHookPath(); err == nil {
paths = append(paths, out...)
pathFuncs := []func() ([]string, error){
git.GlobalHookPath,
git.UserHookPath,
git.LocalHookPath,
}

if out, err := git.UserHookPath(); err == nil {
paths = append(paths, out...)
}

if out, err := git.LocalHookPath(); err == nil {
paths = append(paths, out...)
}

return paths
}

func hasElement(list []string, word string) bool {
for _, element := range list {
if element == word {
return true
for _, pathFunc := range pathFuncs {
if out, err := pathFunc(); err == nil {
paths = append(paths, out...)
}
}
return false
return paths
}
15 changes: 13 additions & 2 deletions hook/hook_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package hook
package hook_test

import (
"testing"

"github.com/frankywahl/super_hooks/hook"
)

func TestList(t *testing.T) {
Expand All @@ -24,8 +26,17 @@ func TestList(t *testing.T) {
}

for _, h := range hooks {
if !hasElement(List, h) {
if !hasElement(hook.List, h) {
t.Errorf("Error expected to have a hook for %+v", h)
}
}
}

func hasElement(list []string, word string) bool {
for _, element := range list {
if element == word {
return true
}
}
return false
}

0 comments on commit 5b975ec

Please sign in to comment.