diff --git a/README.md b/README.md index 71d3eea..faeec2b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Add to dependencies: ```elixir def deps do - [{:git_hooks, "~> 0.4.0", only: [:test, :dev], runtime: false}] + [{:git_hooks, "~> 0.4.1", only: [:test, :dev], runtime: false}] end ``` diff --git a/lib/mix/tasks/git_hooks/run.ex b/lib/mix/tasks/git_hooks/run.ex index 2981852..31448f8 100644 --- a/lib/mix/tasks/git_hooks/run.ex +++ b/lib/mix/tasks/git_hooks/run.ex @@ -93,6 +93,16 @@ defmodule Mix.Tasks.GitHooks.Run do into: Config.io_stream(git_hook_type), env: env_vars ) + |> case do + {_result, 0} -> + Printer.success("`#{script_file}` was successful") + + {result, _} -> + if !Config.verbose?(git_hook_type), do: IO.puts(result) + + Printer.error("`#{script_file}` execution failed") + error_exit() + end end defp run_task({:cmd, command}, git_hook_type, git_hook_args) do diff --git a/mix.exs b/mix.exs index 2243556..615c91c 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule GitHooks.MixProject do use Mix.Project - @version "0.4.0" + @version "0.4.1" def project do [ diff --git a/priv/test_script_fail b/priv/test_script_fail new file mode 100755 index 0000000..6ea6407 --- /dev/null +++ b/priv/test_script_fail @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Failed" +exit 1 diff --git a/test/mix/tasks/git_hooks/run_test.exs b/test/mix/tasks/git_hooks/run_test.exs index a7f2262..bed9278 100644 --- a/test/mix/tasks/git_hooks/run_test.exs +++ b/test/mix/tasks/git_hooks/run_test.exs @@ -108,5 +108,19 @@ defmodule Mix.Tasks.RunTest do assert capture_io(fn -> Run.run(["pre-commit"]) end) =~ "test-value" end + + test "when the file returns exits with != 0 the hook exits with != 0" do + env = [{"TEST", "test-value"}] + + put_git_hook_config(:pre_commit, + tasks: [{:file, "priv/test_script_fail", env: env}], + verbose: true + ) + + capture_io(fn -> + # Run.run(["pre-commit"]) + assert catch_exit(Run.run(["pre-commit"])) == 1 + end) =~ "Failed" + end end end