Skip to content

Commit

Permalink
Fix missing exit code on file execution.
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
qgadrian committed Jan 27, 2020
1 parent f1ed1c8 commit 3c1257c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
10 changes: 10 additions & 0 deletions lib/mix/tasks/git_hooks/run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule GitHooks.MixProject do

use Mix.Project

@version "0.4.0"
@version "0.4.1"

def project do
[
Expand Down
4 changes: 4 additions & 0 deletions priv/test_script_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "Failed"
exit 1
14 changes: 14 additions & 0 deletions test/mix/tasks/git_hooks/run_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3c1257c

Please sign in to comment.