lib/overcommit/hook_context/pre_push.rb in overcommit-0.42.0 vs lib/overcommit/hook_context/pre_push.rb in overcommit-0.43.0
- old
+ new
@@ -16,15 +16,20 @@
PushedRef.new(*line.split(' '))
end
end
def modified_files
- @modified_files ||= Overcommit::GitRepo.modified_files(
- refs: "#{pushed_refs[0].remote_sha1}..#{pushed_refs[0].local_sha1}"
- )
+ @modified_files ||= pushed_refs.map(&:modified_files).flatten.uniq
end
+ def modified_lines_in_file(file)
+ @modified_lines ||= {}
+ @modified_lines[file] = pushed_refs.each_with_object(Set.new) do |pushed_ref, set|
+ set.merge(pushed_ref.modified_lines_in_file(file))
+ end
+ end
+
PushedRef = Struct.new(:local_ref, :local_sha1, :remote_ref, :remote_sha1) do
def forced?
!(created? || deleted? || overwritten_commits.empty?)
end
@@ -38,14 +43,26 @@
def destructive?
deleted? || forced?
end
+ def modified_files
+ Overcommit::GitRepo.modified_files(refs: ref_range)
+ end
+
+ def modified_lines_in_file(file)
+ Overcommit::GitRepo.extract_modified_lines(file, refs: ref_range)
+ end
+
def to_s
"#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}"
end
private
+
+ def ref_range
+ "#{remote_sha1}..#{local_sha1}"
+ end
def overwritten_commits
return @overwritten_commits if defined? @overwritten_commits
result = Overcommit::Subprocess.spawn(%W[git rev-list #{remote_sha1} ^#{local_sha1}])
if result.success?