Skip to content

Commit

Permalink
Merge branch 'master' into Avoid-splitting-filenames-on-valid-filenam…
Browse files Browse the repository at this point in the history
…e-characters
  • Loading branch information
mrexox authored Jan 19, 2024
2 parents a09c15f + c0e9575 commit ee66734
Show file tree
Hide file tree
Showing 37 changed files with 350 additions and 200 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## master (unreleased)

## 1.5.7 (2024-01-17)

- fix: pre push hook handling ([#613](https://github.com/evilmartians/lefthook/pull/613)) by @mrexox
- chore: hide wiki links ([#608](https://github.com/evilmartians/lefthook/pull/608)) by @mrexox

## 1.5.6 (2024-01-12)

- feat: shell completion improvements ([#577](https://github.com/evilmartians/lefthook/pull/577)) by @scop
- fix: safe execute git commands without sh wrapper ([#606](https://github.com/evilmartians/lefthook/pull/606)) by @mrexox
- fix: use lefthook package with npx ([#604](https://github.com/evilmartians/lefthook/pull/604)) by @mrexox
- feat: allow setting a bool value for skip_output ([#601](https://github.com/evilmartians/lefthook/pull/601)) by @nsklyarov
- docs: update exception case about interactive option by @mrexox

## 1.5.5 (2023-11-30)

- fix: use empty stdin by default ([#590](https://github.com/evilmartians/lefthook/pull/590)) by @mrexox
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ git add -A && git commit -m '...'

- [**Configuration**](./docs/configuration.md) for `lefthook.yml` config options.
- [**Usage**](./docs/usage.md) for **lefthook** CLI options, supported ENVs, and usage tips.
- [**Wiki**](https://github.com/evilmartians/lefthook/wiki) for guides, examples, and benchmarks.
- [**Discussions**](https://github.com/evilmartians/lefthook/discussions) for questions, ideas, suggestions.
<!-- - [**Wiki**](https://github.com/evilmartians/lefthook/wiki) for guides, examples, and benchmarks. -->

***

Expand Down Expand Up @@ -215,23 +215,23 @@ skip_output:
* [Install for Arch Linux](./docs/install.md#arch)
* [Usage](./docs/usage.md)
* [Configuration](./docs/configuration.md)
* [Troubleshooting](https://github.com/evilmartians/lefthook/wiki/Troubleshooting)
<!-- * [Troubleshooting](https://github.com/evilmartians/lefthook/wiki/Troubleshooting) -->
### Migrate from
* [Husky](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky)
* [Husky and lint-staged](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky-with-lint-staged)
* [Overcommit](https://github.com/evilmartians/lefthook/wiki/Migration-from-overcommit)
<!-- ### Migrate from -->
<!-- * [Husky](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky) -->
<!-- * [Husky and lint-staged](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky-with-lint-staged) -->
<!-- * [Overcommit](https://github.com/evilmartians/lefthook/wiki/Migration-from-overcommit) -->
### Examples
* [Simple script](https://github.com/evilmartians/lefthook/tree/master/examples/with_scripts)
* [Full features](https://github.com/evilmartians/lefthook/tree/master/examples/complete)
### Benchmarks
* [vs Overcommit](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-overcommit)
* [vs pre-commit](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-pre-commit)
<!-- ### Benchmarks -->
<!-- * [vs Overcommit](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-overcommit) -->
<!-- * [vs pre-commit](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-pre-commit) -->
### Comparison list
* [vs Overcommit, Husky, pre-commit](https://github.com/evilmartians/lefthook/wiki/Comparison-with-other-solutions)
<!-- ### Comparison list -->
<!-- * [vs Overcommit, Husky, pre-commit](https://github.com/evilmartians/lefthook/wiki/Comparison-with-other-solutions) -->
### Articles
* [Lefthook: Knock your team’s code back into shape](https://evilmartians.com/chronicles/lefthook-knock-your-teams-code-back-into-shape?utm_source=lefthook)
Expand Down
21 changes: 16 additions & 5 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/evilmartians/lefthook/internal/config"
"github.com/evilmartians/lefthook/internal/lefthook"
)

Expand All @@ -14,12 +15,22 @@ var addDoc string
func newAddCmd(opts *lefthook.Options) *cobra.Command {
args := lefthook.AddArgs{}

addHookCompletions := func(cmd *cobra.Command, args []string, toComplete string) (ret []string, compDir cobra.ShellCompDirective) {
compDir = cobra.ShellCompDirectiveNoFileComp
if len(args) != 0 {
return
}
ret = config.AvailableHooks[:]
return
}

addCmd := cobra.Command{
Use: "add hook-name",
Short: "This command adds a hook directory to a repository",
Long: addDoc,
Example: "lefthook add pre-commit",
Args: cobra.MinimumNArgs(1),
Use: "add hook-name",
Short: "This command adds a hook directory to a repository",
Long: addDoc,
Example: "lefthook add pre-commit",
ValidArgsFunction: addHookCompletions,
Args: cobra.MinimumNArgs(1),
RunE: func(_cmd *cobra.Command, hooks []string) error {
args.Hook = hooks[0]
return lefthook.Add(opts, &args)
Expand Down
7 changes: 4 additions & 3 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
func newDumpCmd(opts *lefthook.Options) *cobra.Command {
dumpArgs := lefthook.DumpArgs{}
dumpCmd := cobra.Command{
Use: "dump",
Short: "Prints config merged from all extensions (in YAML format by default)",
Example: "lefthook dump",
Use: "dump",
Short: "Prints config merged from all extensions (in YAML format by default)",
Example: "lefthook dump",
ValidArgsFunction: cobra.NoFileCompletions,
Run: func(cmd *cobra.Command, args []string) {
lefthook.Dump(opts, dumpArgs)
},
Expand Down
5 changes: 3 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ func newInstallCmd(opts *lefthook.Options) *cobra.Command {
var a, force bool

installCmd := cobra.Command{
Use: "install",
Short: "Write basic configuration file in your project repository. Or initialize existed config",
Use: "install",
Short: "Write basic configuration file in your project repository. Or initialize existed config",
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, _args []string) error {
return lefthook.Install(opts, force)
},
Expand Down
31 changes: 27 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,39 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/evilmartians/lefthook/internal/config"
"github.com/evilmartians/lefthook/internal/lefthook"
"github.com/evilmartians/lefthook/internal/log"
)

func newRunCmd(opts *lefthook.Options) *cobra.Command {
runArgs := lefthook.RunArgs{}

runHookCompletions := func(cmd *cobra.Command, args []string, toComplete string) (ret []string, compDir cobra.ShellCompDirective) {
compDir = cobra.ShellCompDirectiveNoFileComp
if len(args) != 0 {
return
}
ret = lefthook.ConfigHookCompletions(opts)
ret = append(ret, config.AvailableHooks[:]...)
return
}

runHookCommandCompletions := func(cmd *cobra.Command, args []string, toComplete string) (ret []string, compDir cobra.ShellCompDirective) {
compDir = cobra.ShellCompDirectiveNoFileComp
if len(args) == 0 {
return
}
ret = lefthook.ConfigHookCommandCompletions(opts, args[0])
return
}

runCmd := cobra.Command{
Use: "run hook-name [git args...]",
Short: "Execute group of hooks",
Example: "lefthook run pre-commit",
Args: cobra.MinimumNArgs(1),
Use: "run hook-name [git args...]",
Short: "Execute group of hooks",
Example: "lefthook run pre-commit",
ValidArgsFunction: runHookCompletions,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// args[0] - hook name
// args[1:] - git hook arguments, number and value depends on the hook
Expand Down Expand Up @@ -62,5 +83,7 @@ func newRunCmd(opts *lefthook.Options) *cobra.Command {
log.Warn("Unexpected error:", err)
}

_ = runCmd.RegisterFlagCompletionFunc("commands", runHookCommandCompletions)

return &runCmd
}
5 changes: 3 additions & 2 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ func newUninstallCmd(opts *lefthook.Options) *cobra.Command {
args := lefthook.UninstallArgs{}

uninstallCmd := cobra.Command{
Use: "uninstall",
Short: "Revert install command",
Use: "uninstall",
Short: "Revert install command",
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, _args []string) error {
return lefthook.Uninstall(opts, &args)
},
Expand Down
5 changes: 3 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ func newVersionCmd(_opts *lefthook.Options) *cobra.Command {
var verbose bool

versionCmd := cobra.Command{
Use: "version",
Short: "Show lefthook version",
Use: "version",
Short: "Show lefthook version",
ValidArgsFunction: cobra.NoFileCompletions,
Run: func(cmd *cobra.Command, args []string) {
log.Println(version.Version(verbose))
},
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ You can manage the verbosity using the `skip_output` config. You can set whether

Possible values are `meta,summary,success,failure,execution,execution_out,execution_info,skips`.

You can also disable all output with setting `skip_output: true`. In this case only errors will be printed.

This config quiets all outputs except for errors.

**Example**
Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ python3 -m pip install --user lefthook
You can find the Swift wrapper plugin [here](https://github.com/csjones/lefthook-plugin). To utilize lefthook, include the plugin in the dependencies section of your `Package.swift`:

```swift
.package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "1.5.5"),
.package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "1.5.7"),
```

## <a id="scoop"></a> Scoop for Windowss
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Config struct {
SourceDir string `mapstructure:"source_dir"`
SourceDirLocal string `mapstructure:"source_dir_local"`
Rc string `mapstructure:"rc,omitempty"`
SkipOutput []string `mapstructure:"skip_output,omitempty"`
SkipOutput interface{} `mapstructure:"skip_output,omitempty"`
Extends []string `mapstructure:"extends,omitempty"`
NoTTY bool `mapstructure:"no_tty,omitempty"`
AssertLefthookInstalled bool `mapstructure:"assert_lefthook_installed,omitempty"`
Expand Down
43 changes: 11 additions & 32 deletions internal/git/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package git
import (
"os"
"os/exec"
"runtime"
"strings"

"github.com/evilmartians/lefthook/internal/log"
)

type Exec interface {
SetRootPath(root string)
Cmd(cmd string) (string, error)
CmdArgs(args ...string) (string, error)
CmdLines(cmd string) ([]string, error)
RawCmd(cmd string) (string, error)
Cmd(cmd []string) (string, error)
CmdLines(cmd []string) ([]string, error)
}

type OsExec struct {
Expand All @@ -32,46 +29,28 @@ func (o *OsExec) SetRootPath(root string) {
}

// Cmd runs plain string command. Trims spaces around output.
func (o *OsExec) Cmd(cmd string) (string, error) {
args := strings.Split(cmd, " ")
return o.CmdArgs(args...)
}

// CmdLines runs plain string command, returns its output split by newline.
func (o *OsExec) CmdLines(cmd string) ([]string, error) {
out, err := o.RawCmd(cmd)
if err != nil {
return nil, err
}

return strings.Split(out, "\n"), nil
}

// CmdArgs runs a command provided with separated words. Trims spaces around output.
func (o *OsExec) CmdArgs(args ...string) (string, error) {
out, err := o.rawExecArgs(args...)
func (o *OsExec) Cmd(cmd []string) (string, error) {
out, err := o.rawExecArgs(cmd)
if err != nil {
return "", err
}

return strings.TrimSpace(out), nil
}

// RawCmd runs a plain string command returning unprocessed output as string.
func (o *OsExec) RawCmd(cmd string) (string, error) {
var args []string
if runtime.GOOS == "windows" {
args = strings.Split(cmd, " ")
} else {
args = []string{"sh", "-c", cmd}
// CmdLines runs plain string command, returns its output split by newline.
func (o *OsExec) CmdLines(cmd []string) ([]string, error) {
out, err := o.rawExecArgs(cmd)
if err != nil {
return nil, err
}

return o.rawExecArgs(args...)
return strings.Split(strings.TrimSpace(out), "\n"), nil
}

// rawExecArgs executes git command with LEFTHOOK=0 in order
// to prevent calling subsequent lefthook hooks.
func (o *OsExec) rawExecArgs(args ...string) (string, error) {
func (o *OsExec) rawExecArgs(args []string) (string, error) {
log.Debug("[lefthook] cmd: ", args)

cmd := exec.Command(args[0], args[1:]...)
Expand Down
12 changes: 6 additions & 6 deletions internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ func (r *Repository) updateRemote(path, ref string) error {
log.Debugf("Updating remote config repository: %s", path)

if len(ref) != 0 {
_, err := r.Git.CmdArgs(
_, err := r.Git.Cmd([]string{
"git", "-C", path, "fetch", "--quiet", "--depth", "1",
"origin", ref,
)
})
if err != nil {
return err
}

_, err = r.Git.CmdArgs(
_, err = r.Git.Cmd([]string{
"git", "-C", path, "checkout", "FETCH_HEAD",
)
})
if err != nil {
return err
}
} else {
_, err := r.Git.CmdArgs("git", "-C", path, "pull", "--quiet")
_, err := r.Git.Cmd([]string{"git", "-C", path, "pull", "--quiet"})
if err != nil {
return err
}
Expand All @@ -93,7 +93,7 @@ func (r *Repository) cloneRemote(path, url, ref string) error {
}
cmdClone = append(cmdClone, url)

_, err := r.Git.CmdArgs(cmdClone...)
_, err := r.Git.Cmd(cmdClone)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ee66734

Please sign in to comment.