Skip to content

Commit 3c1257c

Browse files
committed
Fix missing exit code on file execution.
Fixes #32
1 parent f1ed1c8 commit 3c1257c

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Add to dependencies:
3838

3939
```elixir
4040
def deps do
41-
[{:git_hooks, "~> 0.4.0", only: [:test, :dev], runtime: false}]
41+
[{:git_hooks, "~> 0.4.1", only: [:test, :dev], runtime: false}]
4242
end
4343
```
4444

lib/mix/tasks/git_hooks/run.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ defmodule Mix.Tasks.GitHooks.Run do
9393
into: Config.io_stream(git_hook_type),
9494
env: env_vars
9595
)
96+
|> case do
97+
{_result, 0} ->
98+
Printer.success("`#{script_file}` was successful")
99+
100+
{result, _} ->
101+
if !Config.verbose?(git_hook_type), do: IO.puts(result)
102+
103+
Printer.error("`#{script_file}` execution failed")
104+
error_exit()
105+
end
96106
end
97107

98108
defp run_task({:cmd, command}, git_hook_type, git_hook_args) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule GitHooks.MixProject do
33

44
use Mix.Project
55

6-
@version "0.4.0"
6+
@version "0.4.1"
77

88
def project do
99
[

priv/test_script_fail

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "Failed"
4+
exit 1

test/mix/tasks/git_hooks/run_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,19 @@ defmodule Mix.Tasks.RunTest do
108108

109109
assert capture_io(fn -> Run.run(["pre-commit"]) end) =~ "test-value"
110110
end
111+
112+
test "when the file returns exits with != 0 the hook exits with != 0" do
113+
env = [{"TEST", "test-value"}]
114+
115+
put_git_hook_config(:pre_commit,
116+
tasks: [{:file, "priv/test_script_fail", env: env}],
117+
verbose: true
118+
)
119+
120+
capture_io(fn ->
121+
# Run.run(["pre-commit"])
122+
assert catch_exit(Run.run(["pre-commit"])) == 1
123+
end) =~ "Failed"
124+
end
111125
end
112126
end

0 commit comments

Comments
 (0)