aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-07 06:41:40 +0200
committerMarkus Reiter2017-05-22 02:01:57 +0200
commit1a96dc39d1d74794de3216dc254e82702a48dddb (patch)
tree16bd44b120bd7bfe550ce3bc47043aef3b627ff9 /Library/Homebrew/utils
parent6d8c170e50b6ee232e4f8958c92735bf411a72e9 (diff)
downloadbrew-1a96dc39d1d74794de3216dc254e82702a48dddb.tar.bz2
Add audit check to see if both version and checksum changed.
Diffstat (limited to 'Library/Homebrew/utils')
-rw-r--r--Library/Homebrew/utils/git.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb
index 1b4d24894..43d93b64e 100644
--- a/Library/Homebrew/utils/git.rb
+++ b/Library/Homebrew/utils/git.rb
@@ -1,3 +1,31 @@
+require "open3"
+
+module Git
+ module_function
+
+ def last_revision_commit_of_file(repo, file, before_commit: nil)
+ args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first]
+
+ out, = Open3.capture3(
+ HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
+ "log", "--oneline", "--max-count=1", *args, "--", file
+ )
+ out.split(" ").first
+ end
+
+ def last_revision_of_file(repo, file, before_commit: nil)
+ relative_file = Pathname(file).relative_path_from(repo)
+
+ commit_hash = last_revision_commit_of_file(repo, file, before_commit: before_commit)
+
+ out, = Open3.capture3(
+ HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
+ "show", "#{commit_hash}:#{relative_file}"
+ )
+ out
+ end
+end
+
module Utils
def self.git_available?
return @git if instance_variable_defined?(:@git)