Skip to content

Commit

Permalink
fix: fail the hook if git-lfs command failed
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed May 29, 2024
1 parent b1a5d7a commit 24872b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/lefthook/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 24872b4

Please sign in to comment.