aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/missing_formula.rb
diff options
context:
space:
mode:
authorMike McQuaid2017-03-20 20:37:12 +0100
committerMike McQuaid2017-03-20 20:37:12 +0100
commitf59eb358c29c5f40601a99e3f1bf7e8e891f10ba (patch)
tree86c8ad1406611325251b111c83e212a007ced7d1 /Library/Homebrew/missing_formula.rb
parent80e95b684e7485b5c5b7f7209dd95b0bdc9e3406 (diff)
downloadbrew-f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.tar.bz2
missing_formula: subsume historic logic.
These methods belong together so combine them in a single class to provide a simpler API.
Diffstat (limited to 'Library/Homebrew/missing_formula.rb')
-rw-r--r--Library/Homebrew/missing_formula.rb55
1 files changed, 54 insertions, 1 deletions
diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb
index 28738a0dc..ba09f7426 100644
--- a/Library/Homebrew/missing_formula.rb
+++ b/Library/Homebrew/missing_formula.rb
@@ -6,7 +6,7 @@ module Homebrew
module MissingFormula
class << self
def reason(name)
- blacklisted_reason(name)
+ blacklisted_reason(name) || tap_migration_reason(name) || deleted_reason(name)
end
def blacklisted_reason(name)
@@ -100,6 +100,59 @@ module Homebrew
end
alias generic_blacklisted_reason blacklisted_reason
+ def tap_migration_reason(name)
+ message = nil
+
+ Tap.each do |old_tap|
+ new_tap_name = old_tap.tap_migrations[name]
+ next unless new_tap_name
+ message = <<-EOS.undent
+ It was migrated from #{old_tap} to #{new_tap_name}.
+ You can access it again by running:
+ brew tap #{new_tap_name}
+ EOS
+ break
+ end
+
+ message
+ end
+
+ def deleted_reason(name)
+ path = Formulary.path name
+ return if File.exist? path
+ tap = Tap.from_path(path)
+ return unless File.exist? tap.path
+ relative_path = path.relative_path_from tap.path
+
+ tap.path.cd do
+ # We know this may return incomplete results for shallow clones but
+ # we don't want to nag everyone with a shallow clone to unshallow it.
+ log_command = "git log --name-only --max-count=1 --format=%H\\\\n%h\\\\n%B -- #{relative_path}"
+ hash, short_hash, *commit_message, relative_path =
+ Utils.popen_read(log_command).gsub("\\n", "\n").lines.map(&:chomp)
+ if hash.to_s.empty? || short_hash.to_s.empty? ||
+ relative_path.to_s.empty?
+ return
+ end
+
+ commit_message = commit_message.reject(&:empty?).join("\n ")
+
+ commit_message.sub!(/ \(#(\d+)\)$/, " (#{tap.issues_url}/\\1)")
+ commit_message.gsub!(/(Closes|Fixes) #(\d+)/, "\\1 #{tap.issues_url}/\\2")
+
+ <<-EOS.undent
+ #{name} was deleted from #{tap.name} in commit #{short_hash}:
+ #{commit_message}
+
+ To show the formula before removal run:
+ git -C "$(brew --repo #{tap})" show #{short_hash}^:#{relative_path}
+
+ If you still use this formula consider creating your own tap:
+ http://docs.brew.sh/How-to-Create-and-Maintain-a-Tap.html
+ EOS
+ end
+ end
+
require "extend/os/missing_formula"
end
end