@@ -9,11 +9,15 @@ def initialize(config)
9
9
10
10
# Loads and runs the hooks registered for this {HookRunner}.
11
11
def run ( args , input , logger )
12
- #stash_unstaged_files
12
+ @args = args
13
+ @input = input
14
+ @logger = logger
15
+
16
+ # stash_unstaged_files
13
17
load_hooks
14
- run_hooks ( args , input , logger )
18
+ run_hooks
15
19
ensure
16
- #restore_unstaged_files
20
+ # restore_unstaged_files
17
21
end
18
22
19
23
# Returns the type of hook this runner deals with (e.g. "CommitMsg",
@@ -26,14 +30,23 @@ def underscored_hook_type
26
30
@underscored_hook_type ||= Overcommit ::Utils . underscorize ( hook_type )
27
31
end
28
32
33
+ # Get a list of added, copied, or modified files that have been staged.
34
+ # Renames and deletions are ignored, since there should be nothing to check.
35
+ def staged_files
36
+ @staged_files ||=
37
+ `git diff --cached --name-only --diff-filter=ACM --ignore-submodules=all` .
38
+ split ( "\n " ) .
39
+ map { |relative_file | File . expand_path ( relative_file ) }
40
+ end
41
+
29
42
private
30
43
31
- def run_hooks ( args , input , log )
32
- reporter = Overcommit ::Reporter . new ( self , @hooks , @config , log )
44
+ def run_hooks
45
+ reporter = Overcommit ::Reporter . new ( self , @hooks , @config , @logger )
33
46
34
47
reporter . start_hook_run
35
48
36
- @hooks . reject { |hook | hook . skip ? } .
49
+ @hooks . select { |hook | hook . run ? } .
37
50
each do |hook |
38
51
reporter . with_status ( hook ) do
39
52
hook . run
@@ -72,8 +85,7 @@ def load_hook_plugins
72
85
Dir [ File . join ( directory , '*.rb' ) ] . sort do |plugin |
73
86
require plugin
74
87
75
- hook_name = Overcommit ::HookRunner . hook_type_to_class_name ( File . basename ( plugin , '.rb' ) )
76
-
88
+ hook_name = self . class . hook_type_to_class_name ( File . basename ( plugin , '.rb' ) )
77
89
@hooks << create_hook ( hook_name )
78
90
end
79
91
end
@@ -82,7 +94,7 @@ def load_hook_plugins
82
94
# hook configuration.
83
95
def create_hook ( hook_name )
84
96
Overcommit ::Hook . const_get ( "#{ hook_type } ::#{ hook_name } " ) .
85
- new ( @config )
97
+ new ( @config , self )
86
98
rescue LoadError , NameError => error
87
99
raise Overcommit ::Exceptions ::HookLoadError ,
88
100
"Unable to load hook '#{ hook_name } ': #{ error } " ,
0 commit comments