@@ -21,7 +21,7 @@ defmodule Mix.Tasks.GitHooks.Install do
2121 use Mix.Task
2222
2323 alias GitHooks.Config
24- alias GitHooks.Git
24+ alias GitHooks.Git.Path , as: GitPath
2525 alias GitHooks.Printer
2626
2727 @ impl true
@@ -55,9 +55,7 @@ defmodule Mix.Tasks.GitHooks.Install do
5555
5656 case File . read ( template_file ) do
5757 { :ok , body } ->
58- target_file_path =
59- Git . resolve_git_path ( )
60- |> Path . join ( "/hooks/#{ git_hook_atom_as_kebab_string } " )
58+ target_file_path = GitPath . git_hooks_path_for ( git_hook_atom_as_kebab_string )
6159
6260 target_file_body =
6361 body
@@ -85,13 +83,9 @@ defmodule Mix.Tasks.GitHooks.Install do
8583
8684 @ spec backup_current_hook ( String . t ( ) , Keyword . t ( ) ) :: { :error , atom } | { :ok , non_neg_integer ( ) }
8785 defp backup_current_hook ( git_hook_to_backup , opts ) do
88- source_file_path =
89- Git . resolve_git_path ( )
90- |> Path . join ( "/hooks/#{ git_hook_to_backup } " )
86+ source_file_path = GitPath . git_hooks_path_for ( git_hook_to_backup )
9187
92- target_file_path =
93- Git . resolve_git_path ( )
94- |> Path . join ( "/hooks/#{ git_hook_to_backup } .pre_git_hooks_backup" )
88+ target_file_path = GitPath . git_hooks_path_for ( "/#{ git_hook_to_backup } .pre_git_hooks_backup" )
9589
9690 unless opts [ :quiet ] || ! Config . verbose? ( ) do
9791 Printer . info ( "Backing up git hook file `#{ source_file_path } ` to `#{ target_file_path } `" )
@@ -104,8 +98,8 @@ defmodule Mix.Tasks.GitHooks.Install do
10498 defp track_configured_hooks do
10599 git_hooks = Config . git_hooks ( ) |> Enum . join ( " " )
106100
107- Git . resolve_git_path ( )
108- |> Path . join ( "/hooks/git_hooks.db" )
101+ "/git_hooks.db"
102+ |> GitPath . git_hooks_path_for ( )
109103 |> write_backup ( git_hooks )
110104 end
111105
@@ -123,8 +117,8 @@ defmodule Mix.Tasks.GitHooks.Install do
123117
124118 @ spec ensure_hooks_folder_exists ( ) :: any
125119 defp ensure_hooks_folder_exists do
126- Git . resolve_git_path ( )
127- |> Path . join ( "/hooks" )
120+ "/"
121+ |> GitPath . git_hooks_path_for ( )
128122 |> File . mkdir_p ( )
129123 end
130124
@@ -134,8 +128,8 @@ defmodule Mix.Tasks.GitHooks.Install do
134128 Config . git_hooks ( )
135129 |> Enum . map ( & Atom . to_string / 1 )
136130
137- Git . resolve_git_path ( )
138- |> Path . join ( "/git_hooks.db" )
131+ "/git_hooks.db"
132+ |> GitPath . git_hooks_path_for ( )
139133 |> File . read ( )
140134 |> case do
141135 { :ok , file } ->
@@ -149,8 +143,8 @@ defmodule Mix.Tasks.GitHooks.Install do
149143 "Remove old git hook `#{ git_hook_atom_as_kebab_string } ` and restore backup"
150144 )
151145
152- Git . resolve_git_path ( )
153- |> Path . join ( "/hooks/ #{ git_hook_atom_as_kebab_string } " )
146+ git_hook_atom_as_kebab_string
147+ |> GitPath . git_hooks_path_for ( )
154148 |> File . rm ( )
155149
156150 restore_backup ( git_hook_atom_as_kebab_string )
@@ -165,16 +159,9 @@ defmodule Mix.Tasks.GitHooks.Install do
165159 @ spec restore_backup ( String . t ( ) ) :: any
166160 defp restore_backup ( git_hook_atom_as_kebab_string ) do
167161 backup_path =
168- Path . join (
169- Git . resolve_git_path ( ) ,
170- "/hooks/#{ git_hook_atom_as_kebab_string } .pre_git_hooks_backup"
171- )
162+ GitPath . git_hooks_path_for ( "/#{ git_hook_atom_as_kebab_string } .pre_git_hooks_backup" )
172163
173- restore_path =
174- Path . join (
175- Git . resolve_git_path ( ) ,
176- "/#{ git_hook_atom_as_kebab_string } "
177- )
164+ restore_path = GitPath . git_hooks_path_for ( git_hook_atom_as_kebab_string )
178165
179166 case File . rename ( backup_path , restore_path ) do
180167 :ok -> :ok
0 commit comments