@@ -21,8 +21,8 @@ defmodule Mix.Tasks.GitHooks.Install do
2121 use Mix.Task
2222
2323 alias GitHooks.Config
24+ alias GitHooks.Git
2425 alias GitHooks.Printer
25- alias Mix.Project
2626
2727 @ impl true
2828 @ spec run ( Keyword . t ( ) ) :: :ok
@@ -56,7 +56,7 @@ defmodule Mix.Tasks.GitHooks.Install do
5656 case File . read ( template_file ) do
5757 { :ok , body } ->
5858 target_file_path =
59- resolve_git_path ( )
59+ Git . resolve_git_path ( )
6060 |> Path . join ( "/hooks/#{ git_hook_atom_as_kebab_string } " )
6161
6262 target_file_body =
@@ -86,11 +86,11 @@ defmodule Mix.Tasks.GitHooks.Install do
8686 @ spec backup_current_hook ( String . t ( ) , Keyword . t ( ) ) :: { :error , atom } | { :ok , non_neg_integer ( ) }
8787 defp backup_current_hook ( git_hook_to_backup , opts ) do
8888 source_file_path =
89- resolve_git_path ( )
89+ Git . resolve_git_path ( )
9090 |> Path . join ( "/hooks/#{ git_hook_to_backup } " )
9191
9292 target_file_path =
93- resolve_git_path ( )
93+ Git . resolve_git_path ( )
9494 |> Path . join ( "/hooks/#{ git_hook_to_backup } .pre_git_hooks_backup" )
9595
9696 unless opts [ :quiet ] || ! Config . verbose? ( ) do
@@ -104,7 +104,7 @@ defmodule Mix.Tasks.GitHooks.Install do
104104 defp track_configured_hooks do
105105 git_hooks = Config . git_hooks ( ) |> Enum . join ( " " )
106106
107- resolve_git_path ( )
107+ Git . resolve_git_path ( )
108108 |> Path . join ( "/hooks/git_hooks.db" )
109109 |> write_backup ( git_hooks )
110110 end
@@ -121,40 +121,9 @@ defmodule Mix.Tasks.GitHooks.Install do
121121 )
122122 end
123123
124- @ spec resolve_git_path ( ) :: any
125- defp resolve_git_path ( ) do
126- :git_hooks
127- |> Application . get_env ( :git_path )
128- |> case do
129- nil ->
130- path = Path . join ( Project . deps_path ( ) , "/../.git" )
131-
132- if File . dir? ( path ) do
133- path
134- else
135- resolve_git_submodule_path ( path )
136- end
137-
138- custom_path ->
139- custom_path
140- end
141- end
142-
143- @ spec resolve_git_submodule_path ( String . t ( ) ) :: any
144- defp resolve_git_submodule_path ( git_path ) do
145- with { :ok , contents } <- File . read ( git_path ) ,
146- % { "dir" => submodule_dir } <- Regex . named_captures ( ~r/ ^gitdir:\s +(?<dir>.*)$/ , contents ) do
147- Project . deps_path ( )
148- |> Path . join ( "/../" <> submodule_dir )
149- else
150- _error ->
151- raise "Error resolving git submodule path '#{ git_path } '"
152- end
153- end
154-
155124 @ spec ensure_hooks_folder_exists ( ) :: any
156125 defp ensure_hooks_folder_exists do
157- resolve_git_path ( )
126+ Git . resolve_git_path ( )
158127 |> Path . join ( "/hooks" )
159128 |> File . mkdir_p ( )
160129 end
@@ -165,7 +134,7 @@ defmodule Mix.Tasks.GitHooks.Install do
165134 Config . git_hooks ( )
166135 |> Enum . map ( & Atom . to_string / 1 )
167136
168- resolve_git_path ( )
137+ Git . resolve_git_path ( )
169138 |> Path . join ( "/git_hooks.db" )
170139 |> File . read ( )
171140 |> case do
@@ -180,7 +149,7 @@ defmodule Mix.Tasks.GitHooks.Install do
180149 "Remove old git hook `#{ git_hook_atom_as_kebab_string } ` and restore backup"
181150 )
182151
183- resolve_git_path ( )
152+ Git . resolve_git_path ( )
184153 |> Path . join ( "/hooks/#{ git_hook_atom_as_kebab_string } " )
185154 |> File . rm ( )
186155
@@ -197,13 +166,13 @@ defmodule Mix.Tasks.GitHooks.Install do
197166 defp restore_backup ( git_hook_atom_as_kebab_string ) do
198167 backup_path =
199168 Path . join (
200- resolve_git_path ( ) ,
169+ Git . resolve_git_path ( ) ,
201170 "/hooks/#{ git_hook_atom_as_kebab_string } .pre_git_hooks_backup"
202171 )
203172
204173 restore_path =
205174 Path . join (
206- resolve_git_path ( ) ,
175+ Git . resolve_git_path ( ) ,
207176 "/#{ git_hook_atom_as_kebab_string } "
208177 )
209178
0 commit comments