Skip to content

Commit af3c728

Browse files
committed
Remove git_path config
The config is no longer needed as the git path will be resolved automatically for the repo.
1 parent 19b7970 commit af3c728

File tree

3 files changed

+8
-84
lines changed

3 files changed

+8
-84
lines changed

README.md

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ Main features:
3333
* [Auto install](#auto-install)
3434
* [Hook configuration](#hook-configuration)
3535
* [Git submodules](#git-submodules)
36-
* [Custom paths](#custom-paths)
37-
* [Git path](#git-path)
38-
* [Git hooks path](#git-hooks-path)
39-
* [Mix path](#mix-path)
36+
* [Custom mix path](#custom-mix-path)
4037
* [Troubleshooting in docker containers](#troubleshooting-in-docker-containers)
4138
* [Example config](#example-config)
4239
* [Task types](#task-types)
@@ -122,42 +119,7 @@ Setting a custom _git hooks_ config path is also supported:
122119
git config core.hooksPath .myCustomGithooks/
123120
```
124121

125-
### Custom paths
126-
127-
By default this library expects your Elixir project to be the root of the git
128-
repository. If this is the case, you might need to configure custom paths based
129-
on your folders relative paths.
130-
131-
#### Git path
132-
133-
If you need to override the folder of the _git path_ you
134-
can add the following configuration:
135-
136-
```elixir
137-
config :git_hooks,
138-
git_path: "../.git"
139-
```
140-
141-
This is useful if the root of your project is not managed directly by the VCS
142-
but the parent.
143-
144-
If you set the `git_path`, the git hooks path will expect to be inside
145-
the `hooks` folder of the provided path configuration. In the example above, `../.git/hooks`.
146-
147-
#### Git hooks path
148-
149-
If you need to override the folder of the _git hooks path_ you
150-
can add the following configuration:
151-
152-
```elixir
153-
config :git_hooks,
154-
git_hooks_path: "../.git/hooks"
155-
```
156-
157-
This is useful if the root of your project is not managed directly by the VCS
158-
but the parent and you are using a custom path for your git hooks.
159-
160-
#### Mix path
122+
### Custom mix path
161123

162124
This library expects `elixir` to be installed in your system and the `mix` binary to be available. If you want to provide a specific path to run the `mix` executable, it can be done using the `mix_path` configuration.
163125

lib/git/path.ex

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@ defmodule GitHooks.Git.Path do
66
@doc false
77
@spec resolve_git_hooks_path() :: any
88
def resolve_git_hooks_path do
9-
git_path_config = Application.get_env(:git_hooks, :git_path, nil)
10-
git_hooks_path_config = Application.get_env(:git_hooks, :git_hooks_path, nil)
11-
12-
case {git_hooks_path_config, git_path_config} do
13-
{nil, nil} ->
14-
resolve_git_path_based_on_git_version("hooks")
15-
16-
{nil, git_path_config} ->
17-
"#{git_path_config}/hooks"
18-
19-
{git_hooks_path_config, _} ->
20-
git_hooks_path_config
21-
end
9+
resolve_git_path_based_on_git_version("hooks")
2210
end
2311

2412
@doc false
2513
def resolve_app_path do
26-
git_path = resolve_git_path_based_on_git_version()
27-
git_dir = Application.get_env(:git_hooks, :git_path, git_path)
28-
repo_dir = Path.dirname(git_dir)
14+
repo_path =
15+
resolve_git_path_based_on_git_version()
16+
|> Path.dirname()
2917

30-
Path.relative_to(File.cwd!(), repo_dir)
18+
Path.relative_to(File.cwd!(), repo_path)
3119
end
3220

3321
@spec git_hooks_path_for(path :: String.t()) :: String.t()

test/git/path_test.exs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,7 @@ defmodule GitHooks.Git.PathTest do
1010
end
1111

1212
describe "resolve_git_hooks_path/0" do
13-
test "returns the configuration for git_hooks_path" do
14-
Application.put_env(:git_hooks, :git_hooks_path, "./custom-hooks-path")
15-
16-
assert Path.resolve_git_hooks_path() == "./custom-hooks-path"
17-
18-
Application.delete_env(:git_hooks, :git_hooks_path)
19-
end
20-
21-
test "returns the hooks path based on the git_path configuration" do
22-
Application.put_env(:git_hooks, :git_path, "./custom-git-path")
23-
24-
assert Path.resolve_git_hooks_path() == "./custom-git-path/hooks"
25-
26-
Application.delete_env(:git_hooks, :git_path)
27-
end
28-
29-
test "prioritizes the git_hooks_path config over the git_path" do
30-
Application.put_env(:git_hooks, :git_hooks_path, "./prioritized-custom-hooks-path")
31-
Application.put_env(:git_hooks, :git_path, "./custom-git-path")
32-
33-
assert Path.resolve_git_hooks_path() == "./prioritized-custom-hooks-path"
34-
35-
Application.delete_env(:git_hooks, :git_hooks_path)
36-
Application.delete_env(:git_hooks, :git_path)
37-
end
38-
39-
test "returns the git path when there is no other configuration" do
13+
test "returns the git path of the project" do
4014
assert Path.resolve_git_hooks_path() == ".git/hooks"
4115
end
4216
end

0 commit comments

Comments
 (0)