-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathdiff.rb
More file actions
39 lines (31 loc) · 984 Bytes
/
diff.rb
File metadata and controls
39 lines (31 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
require 'overcommit/git_repo'
require 'set'
module Overcommit::HookContext
# Simulates a pre-commit context based on the diff with another git ref.
#
# This results in pre-commit hooks running against the changes between the current
# and another ref, which is useful for automated CI scripts.
class Diff < Base
def modified_files
@modified_files ||= Overcommit::GitRepo.modified_files(refs: @options[:diff])
end
def modified_lines_in_file(file)
@modified_lines ||= {}
@modified_lines[file] ||= Overcommit::GitRepo.extract_modified_lines(file,
refs: @options[:diff])
end
def hook_class_name
'PreCommit'
end
def hook_type_name
'pre_commit'
end
def hook_script_name
'pre-commit'
end
def initial_commit?
@initial_commit ||= Overcommit::GitRepo.initial_commit?
end
end
end