File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,19 @@ defmodule GitHooks.Git.Path do
3
3
4
4
alias GitHooks.Git
5
5
6
- @ doc false
6
+ @ doc """
7
+ Returns the absolute `.git` path directory for the parent project.
8
+ """
7
9
@ spec resolve_git_hooks_path ( ) :: any
8
10
def resolve_git_hooks_path do
9
- resolve_git_path_based_on_git_version ( "hooks" )
11
+ path_for =
12
+ "hooks"
13
+ |> resolve_git_path_based_on_git_version ( )
14
+ |> Path . relative_to ( resolve_app_path ( ) )
15
+
16
+ resolve_app_path ( )
17
+ |> Path . join ( path_for )
18
+ |> String . replace ( ~r/ \/ +/ , "/" )
10
19
end
11
20
12
21
@ doc false
@@ -20,6 +29,10 @@ defmodule GitHooks.Git.Path do
20
29
Path . relative_to ( project_path , repo_path )
21
30
end
22
31
32
+ @ doc """
33
+ Returns the absolute `.git` path directory for the parent project, appending
34
+ the given path.
35
+ """
23
36
@ spec git_hooks_path_for ( path :: String . t ( ) ) :: String . t ( )
24
37
def git_hooks_path_for ( path ) do
25
38
__MODULE__ . resolve_git_hooks_path ( )
Original file line number Diff line number Diff line change @@ -4,14 +4,29 @@ defmodule GitHooks.Git.PathTest do
4
4
alias GitHooks.Git.Path
5
5
6
6
describe "git_hooks_path_for/1" do
7
- test "appends the path to the hooks folder" do
8
- assert Path . git_hooks_path_for ( "/testing" ) == ".git/hooks/testing"
7
+ setup [ :project_path ]
8
+
9
+ test "appends the path to the `.git/hooks` folder" , % { project_path: project_path } do
10
+ assert Path . git_hooks_path_for ( "/testing" ) == "#{ project_path } /.git/hooks/testing"
9
11
end
10
12
end
11
13
12
14
describe "resolve_git_hooks_path/0" do
13
- test "returns the git path of the project" do
14
- assert Path . resolve_git_hooks_path ( ) == ".git/hooks"
15
+ setup [ :project_path ]
16
+
17
+ test "returns the git path of the project" , % { project_path: project_path } do
18
+ assert Path . resolve_git_hooks_path ( ) == "#{ project_path } /.git/hooks"
15
19
end
16
20
end
21
+
22
+ #
23
+ # Private functions
24
+ #
25
+
26
+ defp project_path ( _ ) do
27
+ { project_path , 0 } = System . cmd ( "pwd" , [ ] )
28
+ project_path = String . replace ( project_path , ~r/ \n / , "" )
29
+
30
+ { :ok , % { project_path: project_path } }
31
+ end
17
32
end
You can’t perform that action at this time.
0 commit comments