forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_commit.rb
More file actions
31 lines (29 loc) · 1.07 KB
/
post_commit.rb
File metadata and controls
31 lines (29 loc) · 1.07 KB
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
module Overcommit::HookContext
# Contains helpers related to contextual information used by post-commit
# hooks.
class PostCommit < Base
# Get a list of files that were added, copied, or modified in the last
# commit. Renames and deletions are ignored, since there should be nothing
# to check.
def modified_files
subcmd = 'show --format=%n'
@modified_files ||= Overcommit::GitRepo.modified_files(subcmd: subcmd)
end
# Returns the set of line numbers corresponding to the lines that were
# changed in a specified file.
def modified_lines_in_file(file)
subcmd = 'show --format=%n'
@modified_lines ||= {}
@modified_lines[file] ||=
Overcommit::GitRepo.extract_modified_lines(file, subcmd: subcmd)
end
# Returns whether the commit that triggered this hook is the first commit on
# the branch.
#
# @return [true,false]
def initial_commit?
return @initial_commit unless @initial_commit.nil?
@initial_commit = !Overcommit::Utils.execute(%w[git rev-parse HEAD~]).success?
end
end
end