@@ -51,17 +51,28 @@ func GetHook(repoPath, name string) (*Hook, error) {
5151 }
5252 h := & Hook {
5353 name : name ,
54- path : path .Join (repoPath , "hooks" , name + ".d" , name ),
54+ path : filepath .Join (repoPath , "hooks" , name + ".d" , name ),
5555 }
56- samplePath := filepath .Join (repoPath , "hooks" , name + ".sample" )
57- if isFile (h .path ) {
56+ isFile , err := util .IsFile (h .path )
57+ if err != nil {
58+ return nil , err
59+ }
60+ if isFile {
5861 data , err := os .ReadFile (h .path )
5962 if err != nil {
6063 return nil , err
6164 }
6265 h .IsActive = true
6366 h .Content = string (data )
64- } else if isFile (samplePath ) {
67+ return h , nil
68+ }
69+
70+ samplePath := filepath .Join (repoPath , "hooks" , name + ".sample" )
71+ isFile , err = util .IsFile (samplePath )
72+ if err != nil {
73+ return nil , err
74+ }
75+ if isFile {
6576 data , err := os .ReadFile (samplePath )
6677 if err != nil {
6778 return nil , err
@@ -79,7 +90,11 @@ func (h *Hook) Name() string {
7990// Update updates hook settings.
8091func (h * Hook ) Update () error {
8192 if len (strings .TrimSpace (h .Content )) == 0 {
82- if isExist (h .path ) {
93+ exist , err := util .IsExist (h .path )
94+ if err != nil {
95+ return err
96+ }
97+ if exist {
8398 err := util .Remove (h .path )
8499 if err != nil {
85100 return err
@@ -103,7 +118,10 @@ func (h *Hook) Update() error {
103118
104119// ListHooks returns a list of Git hooks of given repository.
105120func ListHooks (repoPath string ) (_ []* Hook , err error ) {
106- if ! isDir (path .Join (repoPath , "hooks" )) {
121+ exist , err := util .IsDir (filepath .Join (repoPath , "hooks" ))
122+ if err != nil {
123+ return nil , err
124+ } else if ! exist {
107125 return nil , errors .New ("hooks path does not exist" )
108126 }
109127
0 commit comments