@@ -44,6 +44,43 @@ defmodule Mix.Tasks.InstallTest do
4444
4545 Application . delete_env ( :git_hooks , :project_path )
4646 end
47+
48+ test "installs git hooks when run from the project root" , % { tmp_dir: project_path } do
49+ put_git_hook_config (
50+ [ :pre_commit , :pre_push ] ,
51+ tasks: { :cmd , "check" }
52+ )
53+
54+ hooks_file = Install . run ( [ "--dry-run" , "--quiet" ] )
55+
56+ assert hooks_file == [
57+ pre_commit: expect_hook_template ( "pre_commit" , project_path ) ,
58+ pre_push: expect_hook_template ( "pre_push" , project_path )
59+ ]
60+ end
61+
62+ test "installs git hooks when run from the dependency directory" , % { tmp_dir: project_path } do
63+ # Simulate being in the dependency directory
64+ deps_git_hooks_dir = Path . join ( [ project_path , "deps" , "git_hooks" ] )
65+ File . mkdir_p! ( deps_git_hooks_dir )
66+
67+ File . cd! ( deps_git_hooks_dir , fn ->
68+ # Need to reset the config cache because Application env might be cached
69+ Application . delete_env ( :git_hooks , :project_path )
70+
71+ put_git_hook_config (
72+ [ :pre_commit , :pre_push ] ,
73+ tasks: { :cmd , "check" }
74+ )
75+
76+ hooks_file = Install . run ( [ "--dry-run" , "--quiet" ] )
77+
78+ assert hooks_file == [
79+ pre_commit: expect_hook_template ( "pre_commit" , project_path ) ,
80+ pre_push: expect_hook_template ( "pre_push" , project_path )
81+ ]
82+ end )
83+ end
4784 end
4885
4986 #
0 commit comments