@@ -51,15 +51,26 @@ func GetHook(repoPath, name string) (*Hook, error) {
5151 name : name ,
5252 path : filepath .Join (repoPath , "hooks" , name + ".d" , name ),
5353 }
54- samplePath := filepath .Join (repoPath , "hooks" , name + ".sample" )
55- if isFile (h .path ) {
54+ isFile , err := util .IsFile (h .path )
55+ if err != nil {
56+ return nil , err
57+ }
58+ if isFile {
5659 data , err := os .ReadFile (h .path )
5760 if err != nil {
5861 return nil , err
5962 }
6063 h .IsActive = true
6164 h .Content = string (data )
62- } else if isFile (samplePath ) {
65+ return h , nil
66+ }
67+
68+ samplePath := filepath .Join (repoPath , "hooks" , name + ".sample" )
69+ isFile , err = util .IsFile (samplePath )
70+ if err != nil {
71+ return nil , err
72+ }
73+ if isFile {
6374 data , err := os .ReadFile (samplePath )
6475 if err != nil {
6576 return nil , err
@@ -77,7 +88,11 @@ func (h *Hook) Name() string {
7788// Update updates hook settings.
7889func (h * Hook ) Update () error {
7990 if len (strings .TrimSpace (h .Content )) == 0 {
80- if isExist (h .path ) {
91+ exist , err := util .IsExist (h .path )
92+ if err != nil {
93+ return err
94+ }
95+ if exist {
8196 err := util .Remove (h .path )
8297 if err != nil {
8398 return err
@@ -101,7 +116,10 @@ func (h *Hook) Update() error {
101116
102117// ListHooks returns a list of Git hooks of given repository.
103118func ListHooks (repoPath string ) (_ []* Hook , err error ) {
104- if ! isDir (filepath .Join (repoPath , "hooks" )) {
119+ exist , err := util .IsDir (filepath .Join (repoPath , "hooks" ))
120+ if err != nil {
121+ return nil , err
122+ } else if ! exist {
105123 return nil , errors .New ("hooks path does not exist" )
106124 }
107125
0 commit comments