Skip to content

Commit

Permalink
Remove git_path config
Browse files Browse the repository at this point in the history
The config is no longer needed as the git path will be resolved
automatically for the repo.
  • Loading branch information
qgadrian committed Feb 7, 2022
1 parent 19b7970 commit af3c728
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 84 deletions.
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ Main features:
* [Auto install](#auto-install)
* [Hook configuration](#hook-configuration)
* [Git submodules](#git-submodules)
* [Custom paths](#custom-paths)
* [Git path](#git-path)
* [Git hooks path](#git-hooks-path)
* [Mix path](#mix-path)
* [Custom mix path](#custom-mix-path)
* [Troubleshooting in docker containers](#troubleshooting-in-docker-containers)
* [Example config](#example-config)
* [Task types](#task-types)
Expand Down Expand Up @@ -122,42 +119,7 @@ Setting a custom _git hooks_ config path is also supported:
git config core.hooksPath .myCustomGithooks/
```

### Custom paths

By default this library expects your Elixir project to be the root of the git
repository. If this is the case, you might need to configure custom paths based
on your folders relative paths.

#### Git path

If you need to override the folder of the _git path_ you
can add the following configuration:

```elixir
config :git_hooks,
git_path: "../.git"
```

This is useful if the root of your project is not managed directly by the VCS
but the parent.

If you set the `git_path`, the git hooks path will expect to be inside
the `hooks` folder of the provided path configuration. In the example above, `../.git/hooks`.

#### Git hooks path

If you need to override the folder of the _git hooks path_ you
can add the following configuration:

```elixir
config :git_hooks,
git_hooks_path: "../.git/hooks"
```

This is useful if the root of your project is not managed directly by the VCS
but the parent and you are using a custom path for your git hooks.

#### Mix path
### Custom mix path

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.

Expand Down
22 changes: 5 additions & 17 deletions lib/git/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ defmodule GitHooks.Git.Path do
@doc false
@spec resolve_git_hooks_path() :: any
def resolve_git_hooks_path do
git_path_config = Application.get_env(:git_hooks, :git_path, nil)
git_hooks_path_config = Application.get_env(:git_hooks, :git_hooks_path, nil)

case {git_hooks_path_config, git_path_config} do
{nil, nil} ->
resolve_git_path_based_on_git_version("hooks")

{nil, git_path_config} ->
"#{git_path_config}/hooks"

{git_hooks_path_config, _} ->
git_hooks_path_config
end
resolve_git_path_based_on_git_version("hooks")
end

@doc false
def resolve_app_path do
git_path = resolve_git_path_based_on_git_version()
git_dir = Application.get_env(:git_hooks, :git_path, git_path)
repo_dir = Path.dirname(git_dir)
repo_path =
resolve_git_path_based_on_git_version()
|> Path.dirname()

Path.relative_to(File.cwd!(), repo_dir)
Path.relative_to(File.cwd!(), repo_path)
end

@spec git_hooks_path_for(path :: String.t()) :: String.t()
Expand Down
28 changes: 1 addition & 27 deletions test/git/path_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@ defmodule GitHooks.Git.PathTest do
end

describe "resolve_git_hooks_path/0" do
test "returns the configuration for git_hooks_path" do
Application.put_env(:git_hooks, :git_hooks_path, "./custom-hooks-path")

assert Path.resolve_git_hooks_path() == "./custom-hooks-path"

Application.delete_env(:git_hooks, :git_hooks_path)
end

test "returns the hooks path based on the git_path configuration" do
Application.put_env(:git_hooks, :git_path, "./custom-git-path")

assert Path.resolve_git_hooks_path() == "./custom-git-path/hooks"

Application.delete_env(:git_hooks, :git_path)
end

test "prioritizes the git_hooks_path config over the git_path" do
Application.put_env(:git_hooks, :git_hooks_path, "./prioritized-custom-hooks-path")
Application.put_env(:git_hooks, :git_path, "./custom-git-path")

assert Path.resolve_git_hooks_path() == "./prioritized-custom-hooks-path"

Application.delete_env(:git_hooks, :git_hooks_path)
Application.delete_env(:git_hooks, :git_path)
end

test "returns the git path when there is no other configuration" do
test "returns the git path of the project" do
assert Path.resolve_git_hooks_path() == ".git/hooks"
end
end
Expand Down

0 comments on commit af3c728

Please sign in to comment.