From 24872b49000a830467afab760033b5c2afa6c01a Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Wed, 29 May 2024 11:43:13 +0300 Subject: [PATCH] fix: fail the hook if git-lfs command failed --- internal/lefthook/run.go | 5 ++++- internal/lefthook/runner/runner.go | 8 ++++---- internal/lefthook/runner/runner_test.go | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/lefthook/run.go b/internal/lefthook/run.go index 59b526fb..5c0ab50d 100644 --- a/internal/lefthook/run.go +++ b/internal/lefthook/run.go @@ -169,7 +169,10 @@ Run 'lefthook install' manually.`, ) startTime := time.Now() - results := r.RunAll(ctx, sourceDirs) + results, runErr := r.RunAll(ctx, sourceDirs) + if runErr != nil { + return runErr + } if ctx.Err() != nil { return errors.New("Interrupted") diff --git a/internal/lefthook/runner/runner.go b/internal/lefthook/runner/runner.go index 8f3f48d9..e1095f4e 100644 --- a/internal/lefthook/runner/runner.go +++ b/internal/lefthook/runner/runner.go @@ -84,16 +84,16 @@ type executable interface { // RunAll runs scripts and commands. // LFS hook is executed at first if needed. -func (r *Runner) RunAll(ctx context.Context, sourceDirs []string) []Result { +func (r *Runner) RunAll(ctx context.Context, sourceDirs []string) ([]Result, error) { results := make([]Result, 0, len(r.Hook.Commands)+len(r.Hook.Scripts)) if err := r.runLFSHook(ctx); err != nil { - log.Error(err) + return results, err } if r.Hook.DoSkip(r.Repo.State()) { r.logSkip(r.HookName, "hook setting") - return results + return results, nil } if !r.DisableTTY && !r.Hook.Follow { @@ -118,7 +118,7 @@ func (r *Runner) RunAll(ctx context.Context, sourceDirs []string) []Result { r.postHook() - return results + return results, nil } func (r *Runner) runLFSHook(ctx context.Context) error { diff --git a/internal/lefthook/runner/runner_test.go b/internal/lefthook/runner/runner_test.go index 034027d8..16888a81 100644 --- a/internal/lefthook/runner/runner_test.go +++ b/internal/lefthook/runner/runner_test.go @@ -766,7 +766,10 @@ func TestRunAll(t *testing.T) { } t.Run(fmt.Sprintf("%d: %s", i, tt.name), func(t *testing.T) { - results := runner.RunAll(context.Background(), tt.sourceDirs) + results, err := runner.RunAll(context.Background(), tt.sourceDirs) + if err != nil { + t.Errorf("unexpected error %s", err) + } var success, fail []Result for _, result := range results {