• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evilmartians / lefthook / 17762708138

16 Sep 2025 10:23AM UTC coverage: 71.322% (-2.7%) from 73.996%
17762708138

push

github

web-flow
refactor: reduce the amount of code in a single file (#1131)

* refactor: reduce the amount of code in a single file

251 of 302 new or added lines in 5 files covered. (83.11%)

154 existing lines in 5 files now uncovered.

3457 of 4847 relevant lines covered (71.32%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.9
/internal/run/controller/command/build_script.go
1
package command
2

3
import (
4
        "fmt"
5
        "os"
6
        "path/filepath"
7
        "strings"
8

9
        "github.com/alessio/shellescape"
10

11
        "github.com/evilmartians/lefthook/internal/log"
12
)
13

14
const (
15
        executableFileMode os.FileMode = 0o751
16
        executableMask     os.FileMode = 0o111
17
)
18

19
type scriptNotExistsError struct {
20
        scriptPath string
21
}
22

NEW
23
func (s scriptNotExistsError) Error() string {
×
NEW
24
        return fmt.Sprintf("script does not exist: %s", s.scriptPath)
×
NEW
25
}
×
26

27
func (b *Builder) buildScript(params *JobParams) ([]string, []string, error) {
3✔
28
        if err := params.validateScript(); err != nil {
3✔
NEW
29
                return nil, nil, err
×
NEW
30
        }
×
31

32
        var scriptExists bool
3✔
33
        execs := make([]string, 0)
3✔
34
        for _, sourceDir := range b.opts.SourceDirs {
6✔
35
                scriptPath := filepath.Join(sourceDir, b.opts.HookName, params.Script)
3✔
36
                fileInfo, err := b.git.Fs.Stat(scriptPath)
3✔
37
                if os.IsNotExist(err) {
6✔
38
                        log.Debugf("[lefthook] script doesn't exist: %s", scriptPath)
3✔
39
                        continue
3✔
40
                }
41
                if err != nil {
3✔
NEW
42
                        log.Errorf("Failed to get info about a script: %s", params.Script)
×
NEW
43
                        return nil, nil, err
×
NEW
44
                }
×
45

46
                scriptExists = true
3✔
47

3✔
48
                if !fileInfo.Mode().IsRegular() {
3✔
NEW
49
                        log.Debugf("[lefthook] script '%s' is not a regular file, skipping", scriptPath)
×
NEW
50
                        return nil, nil, SkipError{"not a regular file"}
×
NEW
51
                }
×
52

53
                // Make sure file is executable
54
                if (fileInfo.Mode() & executableMask) == 0 {
6✔
55
                        if err := b.git.Fs.Chmod(scriptPath, executableFileMode); err != nil {
3✔
NEW
56
                                log.Errorf("Couldn't change file mode to make file executable: %s", err)
×
NEW
57
                                return nil, nil, err
×
NEW
58
                        }
×
59
                }
60

61
                var args []string
3✔
62
                if len(params.Runner) > 0 {
6✔
63
                        args = append(args, params.Runner)
3✔
64
                }
3✔
65

66
                args = append(args, shellescape.Quote(scriptPath))
3✔
67
                args = append(args, b.opts.GitArgs...)
3✔
68

3✔
69
                execs = append(execs, strings.Join(args, " "))
3✔
70
        }
71

72
        if !scriptExists {
3✔
NEW
73
                return nil, nil, scriptNotExistsError{params.Script}
×
NEW
74
        }
×
75

76
        return execs, nil, nil
3✔
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc