Skip to content

Commit 94eadbf

Browse files
committed
Add option to set a mix executable path
1 parent 91db4a4 commit 94eadbf

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Main features are:
2929
* [Automatic installation](#automatic-installation)
3030
* [Manual installation](#manual-installation)
3131
* [Configuration](#configuration)
32-
* [Disable auto install](#disable-auto-install)
32+
* [Mix path](#mix-path)
33+
* [Auto install](#auto-install)
34+
* [Hook configuration](#hook-configuration)
3335
* [Example config](#example-config)
3436
* [Type of tasks](#type-of-tasks)
3537
* [Mix task](#mix-task)
@@ -40,6 +42,7 @@ Main features are:
4042
* [Execution](#execution)
4143
* [Automatic execution](#automatic-execution)
4244
* [Manual execution](#manual-execution)
45+
* [Copyright and License](#copyright-and-license)
4346

4447
<!-- vim-markdown-toc -->
4548

@@ -85,6 +88,25 @@ mix git_hooks.install
8588

8689
## Configuration
8790

91+
### Mix path
92+
93+
This library expects `elixir` to be installed in your system and the `mix` binary to be available. If you want to provide an specific path to run the `mix` executable, it can be done using the `mix_path` configuration.
94+
95+
The following example would run the hooks on a docker container:
96+
97+
```elixir
98+
config :git_hooks,
99+
auto_install: false,
100+
mix_path: "docker-compose exec mix",
101+
```
102+
103+
### Auto install
104+
105+
To disable the automatic install of the git hooks set the configuration key `auto_install` to
106+
`false`.
107+
108+
### Hook configuration
109+
88110
One or more git hooks can be configured, those hooks will be the ones
89111
[installed](#installation) in your git project.
90112

@@ -93,11 +115,6 @@ Currently there are supported two configuration options:
93115
* **tasks**: A list of the commands that will be executed when running a git hook. [See types of tasks](#type-of-tasks) for more info.
94116
* **verbose**: If true, the output of the mix tasks will be visible. This can be configured globally or per git hook.
95117

96-
### Disable auto install
97-
98-
To disable the automatic install of the git hooks set the configuration key `auto_install` to
99-
`false`.
100-
101118
### Example config
102119

103120
In `config/config.exs`

lib/config/config.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ defmodule GitHooks.Config do
6060
{git_hook_type, tasks}
6161
end
6262

63+
@doc """
64+
Returns the configured mix path.
65+
66+
The config should be a valid path the `mix` binary. The default behaviour
67+
expects a regular `elixir` install and defaults to `mix`.
68+
"""
69+
@spec mix_path() :: String.t()
70+
def mix_path() do
71+
Application.get_env(:git_hooks, :mix_path, "mix")
72+
end
73+
6374
@doc """
6475
Returns the general verbose configuration.
6576
"""

lib/mix/tasks/git_hooks/install.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ defmodule Mix.Tasks.GitHooks.Install do
4242

4343
Printer.info("Installing git hooks...")
4444

45+
mix_path = Config.mix_path()
46+
4547
ensure_hooks_folder_exists()
4648
clean_missing_hooks()
4749
track_configured_hooks()
@@ -58,7 +60,9 @@ defmodule Mix.Tasks.GitHooks.Install do
5860
|> Path.join("/../.git/hooks/#{git_hook_atom_as_kebab_string}")
5961

6062
target_file_body =
61-
String.replace(body, "$git_hook", git_hook_atom_as_string, global: true)
63+
body
64+
|> String.replace("$git_hook", git_hook_atom_as_string)
65+
|> String.replace("$mix_path", mix_path)
6266

6367
unless opts[:quiet] || !Config.verbose?() do
6468
Printer.info(

priv/hook_template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
mix git_hooks.run $git_hook "$@"
3+
$mix_path git_hooks.run $git_hook "$@"
44
[ $? -ne 0 ] && exit 1
55
exit 0
66
fi

0 commit comments

Comments
 (0)