2015-08-01 02:31:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-08-01 03:16:17 +02:00
|
|
|
"path/filepath"
|
2015-08-01 02:31:03 +02:00
|
|
|
"strings"
|
|
|
|
|
2022-05-20 21:42:53 +02:00
|
|
|
"go.mthie.com/git-gohooks/general"
|
2015-08-01 02:31:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2015-08-01 03:16:17 +02:00
|
|
|
gitroot, _ := filepath.Abs(filepath.Dir(general.GetGitRoot()))
|
2015-08-23 00:16:22 +02:00
|
|
|
hookBase := strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0]))
|
2015-08-22 23:32:44 +02:00
|
|
|
hookPrefix := fmt.Sprintf("%s_", hookBase)
|
2015-08-01 03:16:17 +02:00
|
|
|
os.Chdir(gitroot)
|
|
|
|
|
2015-08-22 23:32:44 +02:00
|
|
|
filepath.Walk(gitroot, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if info.IsDir() {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
file := info.Name()
|
|
|
|
|
|
|
|
if strings.HasPrefix(file, hookPrefix) {
|
|
|
|
result, errCode := general.RunCommand(filepath.Join(gitroot, "/.git/hooks", file))
|
2015-08-01 02:31:03 +02:00
|
|
|
if errCode != 0 {
|
|
|
|
fmt.Fprintf(os.Stderr, "Error: %s", result)
|
|
|
|
os.Exit(errCode)
|
2015-08-22 23:32:44 +02:00
|
|
|
return nil
|
2015-08-01 02:31:03 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-22 23:32:44 +02:00
|
|
|
return nil
|
|
|
|
})
|
2015-08-01 02:31:03 +02:00
|
|
|
}
|