Skip to content

Commit c8509af

Browse files
committed
Update install module & tests
1 parent f2cd6a5 commit c8509af

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/mix/tasks/git_hooks/install.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ defmodule Mix.Tasks.GitHooks.Install do
135135

136136
@spec ensure_hooks_folder_exists() :: any
137137
defp ensure_hooks_folder_exists do
138-
"/"
139-
|> GitPath.git_hooks_path_for()
138+
GitPath.resolve_git_hooks_path()
140139
|> File.mkdir_p()
141140
end
142141

test/mix/tasks/git_hooks/install_test.exs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ defmodule Mix.Tasks.InstallTest do
33

44
use ExUnit.Case, async: false
55
use GitHooks.TestSupport.ConfigCase
6+
use GitHooks.TestSupport.GitProjectCase
67

78
alias Mix.Tasks.GitHooks.Install
89

910
@tag capture_log: true
1011

1112
describe "run/1" do
12-
test "replaces the hook template with config values" do
13+
test "replaces the hook template with config values", %{tmp_dir: project_path} do
1314
put_git_hook_config(
1415
[:pre_commit, :pre_push],
1516
tasks: {:cmd, "check"}
@@ -18,24 +19,27 @@ defmodule Mix.Tasks.InstallTest do
1819
hooks_file = Install.run(["--dry-run", "--quiet"])
1920

2021
assert hooks_file == [
21-
pre_commit: expect_hook_template("pre_commit"),
22-
pre_push: expect_hook_template("pre_push")
22+
pre_commit: expect_hook_template("pre_commit", project_path),
23+
pre_push: expect_hook_template("pre_push", project_path)
2324
]
2425
end
2526

26-
test "allows setting a custom path to execute the hook" do
27+
test "allows setting a custom path to execute the hook", %{tmp_dir: project_path} do
2728
put_git_hook_config(
2829
[:pre_commit, :pre_push],
2930
tasks: {:cmd, "check"}
3031
)
3132

32-
Application.put_env(:git_hooks, :project_path, "a_custom_path")
33+
custom_path = Path.join(project_path, "a_custom_path")
34+
File.mkdir_p!(custom_path)
35+
System.cmd("git", ["init"], cd: custom_path)
36+
Application.put_env(:git_hooks, :project_path, custom_path)
3337

3438
hooks_file = Install.run(["--dry-run", "--quiet"])
3539

3640
assert hooks_file == [
37-
pre_commit: expect_hook_template("pre_commit", "a_custom_path"),
38-
pre_push: expect_hook_template("pre_push", "a_custom_path")
41+
pre_commit: expect_hook_template("pre_commit", custom_path),
42+
pre_push: expect_hook_template("pre_push", custom_path)
3943
]
4044

4145
Application.delete_env(:git_hooks, :project_path)
@@ -46,7 +50,7 @@ defmodule Mix.Tasks.InstallTest do
4650
# Private functions
4751
#
4852

49-
defp expect_hook_template(git_hook, project_path \\ "") do
53+
defp expect_hook_template(git_hook, project_path) do
5054
~s(#!/bin/sh
5155
5256
[ "#{project_path}" != "" ] && cd "#{project_path}"

0 commit comments

Comments
 (0)