Module: Overcommit::Utils
Constant Summary
collapse
- @@hooks =
[]
Class Method Summary
collapse
bold, error, notice, success, warning
Class Method Details
.absolute_path(path) ⇒ Object
31
32
33
|
# File 'lib/overcommit/utils.rb', line 31
def absolute_path(path)
File.join(File.expand_path('../../..', __FILE__), path)
end
|
.hook_name ⇒ Object
16
17
18
|
# File 'lib/overcommit/utils.rb', line 16
def hook_name
File.basename($0).tr('-', '_')
end
|
.load_hooks ⇒ Object
20
21
22
23
24
25
|
# File 'lib/overcommit/utils.rb', line 20
def load_hooks
require File.expand_path("../hooks/#{hook_name}", __FILE__)
rescue LoadError
error "No hook definition found for #{hook_name}"
exit 1
end
|
.modified_files ⇒ Object
Get a list of staged Added, Copied, or Modified files (ignore renames and deletions, since there should be nothing to check).
54
55
56
57
|
# File 'lib/overcommit/utils.rb', line 54
def modified_files
@modified_files ||=
`git diff --cached --name-only --diff-filter=ACM`.split "\n"
end
|
.register_hook(hook) ⇒ Object
8
9
10
|
# File 'lib/overcommit/utils.rb', line 8
def register_hook(hook)
@@hooks << hook
end
|
.repo_path(path) ⇒ Object
File.expand_path takes one more ‘..’ than you’re used to… we want to go two directories up from the caller (which will be .git/hooks/something) to the root of the git repo.
38
39
40
|
# File 'lib/overcommit/utils.rb', line 38
def repo_path(path)
File.join(File.expand_path('../../..', $0), path)
end
|
.run_hooks(*args) ⇒ Object
12
13
14
|
# File 'lib/overcommit/utils.rb', line 12
def run_hooks(*args)
@@hooks.each { |hook| hook.new.run(*args) }
end
|
.script_path(script) ⇒ Object
27
28
29
|
# File 'lib/overcommit/utils.rb', line 27
def script_path(script)
File.join(File.expand_path('../../hooks/scripts', $0), script)
end
|
.underscorize(str) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/overcommit/utils.rb', line 44
def underscorize(str)
str.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z\d])([A-Z])/, '\1_\2').
tr('-', '_').
downcase
end
|