Skip to content

Commit 37875d4

Browse files
committed
Resolve app path based on git path
1 parent 8810bf0 commit 37875d4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/git.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule GitHooks.Git do
22
@moduledoc false
33

44
@spec git_version() :: Version.t()
5-
def git_version() do
5+
def git_version do
66
{full_git_version, 0} = System.cmd("git", ["--version"])
77

88
[version] = Regex.run(~r/\d\.\d+\.\d+/, full_git_version)

lib/git/path.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule GitHooks.Git.Path do
1111

1212
case {git_hooks_path_config, git_path_config} do
1313
{nil, nil} ->
14-
resolve_git_hooks_path_based_on_git_version()
14+
resolve_git_path_based_on_git_version("hooks")
1515

1616
{nil, git_path_config} ->
1717
"#{git_path_config}/hooks"
@@ -23,7 +23,8 @@ defmodule GitHooks.Git.Path do
2323

2424
@doc false
2525
def resolve_app_path do
26-
git_dir = Application.get_env(:git_hooks, :git_path, &resolve_git_hooks_path/0)
26+
git_path = resolve_git_path_based_on_git_version()
27+
git_dir = Application.get_env(:git_hooks, :git_path, git_path)
2728
repo_dir = Path.dirname(git_dir)
2829

2930
Path.relative_to(File.cwd!(), repo_dir)
@@ -48,17 +49,17 @@ defmodule GitHooks.Git.Path do
4849
# This will support as well changes on the default /hooks path:
4950
# `git config core.hooksPath .myCustomGithooks/`
5051

51-
@spec resolve_git_hooks_path_based_on_git_version() :: String.t()
52-
defp resolve_git_hooks_path_based_on_git_version() do
52+
@spec resolve_git_path_based_on_git_version(dir :: String.t()) :: String.t()
53+
defp resolve_git_path_based_on_git_version(dir \\ "") do
5354
Git.git_version()
5455
|> Version.compare(Version.parse!("2.10.0"))
5556
|> case do
5657
:lt ->
57-
{path, 0} = System.cmd("git", ["rev-parse", "--git-dir", "hooks"])
58+
{path, 0} = System.cmd("git", ["rev-parse", "--git-dir", dir])
5859
String.replace(path, "\n", "")
5960

6061
_gt_or_eq ->
61-
{path, 0} = System.cmd("git", ["rev-parse", "--git-path", "hooks"])
62+
{path, 0} = System.cmd("git", ["rev-parse", "--git-path", dir])
6263
String.replace(path, "\n", "")
6364
end
6465
end

0 commit comments

Comments
 (0)