| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "cmd/tap" | 
					
						
							| 
									
										
										
										
											2015-09-29 16:22:49 +08:00
										 |  |  | require "cmd/doctor" | 
					
						
							| 
									
										
										
										
											2015-08-06 22:51:32 +08:00
										 |  |  | require "formula_versions" | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  | require "migrator" | 
					
						
							|  |  |  | require "formulary" | 
					
						
							| 
									
										
										
										
											2015-05-05 15:29:01 -07:00
										 |  |  | require "descriptions" | 
					
						
							| 
									
										
										
										
											2012-03-07 22:48:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def update | 
					
						
							| 
									
										
										
										
											2013-02-17 13:42:45 +00:00
										 |  |  |     unless ARGV.named.empty? | 
					
						
							|  |  |  |       abort <<-EOS.undent
 | 
					
						
							|  |  |  |         This command updates brew itself, and does not take formula names. | 
					
						
							|  |  |  |         Use `brew upgrade <formula>`. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-29 16:22:49 +08:00
										 |  |  |     # check permissions | 
					
						
							|  |  |  |     checks = Checks.new | 
					
						
							|  |  |  |     %w[
 | 
					
						
							|  |  |  |       check_access_usr_local | 
					
						
							|  |  |  |       check_access_homebrew_repository | 
					
						
							|  |  |  |     ].each do |check| | 
					
						
							|  |  |  |       out = checks.send(check) | 
					
						
							|  |  |  |       odie out unless out.nil? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 16:56:29 +08:00
										 |  |  |     # ensure git is installed | 
					
						
							|  |  |  |     Utils.ensure_git_installed! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 18:23:49 -06:00
										 |  |  |     # ensure GIT_CONFIG is unset as we need to operate on .git/config | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     ENV.delete("GIT_CONFIG") | 
					
						
							| 
									
										
										
										
											2012-03-02 18:23:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     cd HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |     git_init_if_necessary | 
					
						
							| 
									
										
										
										
											2011-09-20 02:25:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |     # migrate to new directories based tap structure | 
					
						
							|  |  |  |     migrate_taps | 
					
						
							| 
									
										
										
										
											2013-09-24 19:39:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     report = Report.new | 
					
						
							| 
									
										
										
										
											2014-06-23 18:41:50 -05:00
										 |  |  |     master_updater = Updater.new(HOMEBREW_REPOSITORY) | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |     master_updater.pull! | 
					
						
							| 
									
										
										
										
											2014-06-27 21:58:15 -05:00
										 |  |  |     report.update(master_updater.report) | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 11:26:45 +09:00
										 |  |  |     # rename Taps directories | 
					
						
							|  |  |  |     # this procedure will be removed in the future if it seems unnecessasry | 
					
						
							|  |  |  |     rename_taps_dir_if_necessary | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 17:08:23 +02:00
										 |  |  |     Tap.each do |tap| | 
					
						
							|  |  |  |       next unless tap.git? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |       tap.path.cd do | 
					
						
							|  |  |  |         updater = Updater.new(tap.path) | 
					
						
							| 
									
										
										
										
											2014-04-25 12:34:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |         begin | 
					
						
							|  |  |  |           updater.pull! | 
					
						
							| 
									
										
										
										
											2014-04-25 12:34:28 -05:00
										 |  |  |         rescue | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |           onoe "Failed to update tap: #{tap}" | 
					
						
							| 
									
										
										
										
											2014-04-25 12:34:28 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |           report.update(updater.report) do |_key, oldval, newval| | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |             oldval.concat(newval) | 
					
						
							| 
									
										
										
										
											2012-08-01 16:19:25 -04:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-03-18 01:23:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-27 16:52:14 +08:00
										 |  |  |     Tap.clear_cache | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-30 11:24:05 -07:00
										 |  |  |     # automatically tap any migrated formulae's new tap | 
					
						
							|  |  |  |     report.select_formula(:D).each do |f| | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |       next unless (dir = HOMEBREW_CELLAR/f).exist? | 
					
						
							| 
									
										
										
										
											2013-11-14 09:25:27 -06:00
										 |  |  |       migration = TAP_MIGRATIONS[f] | 
					
						
							|  |  |  |       next unless migration | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       tap_user, tap_repo = migration.split "/" | 
					
						
							| 
									
										
										
										
											2014-01-03 21:51:42 +00:00
										 |  |  |       install_tap tap_user, tap_repo | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |       # update tap for each Tab | 
					
						
							| 
									
										
										
										
											2015-08-25 09:45:21 +02:00
										 |  |  |       tabs = dir.subdirs.map { |d| Tab.for_keg(Keg.new(d)) } | 
					
						
							| 
									
										
										
										
											2015-08-10 17:43:57 +03:00
										 |  |  |       next if tabs.first.source["tap"] != "Homebrew/homebrew" | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |       tabs.each { |tab| tab.source["tap"] = "#{tap_user}/homebrew-#{tap_repo}" } | 
					
						
							|  |  |  |       tabs.each(&:write) | 
					
						
							| 
									
										
										
										
											2013-12-02 16:14:43 -06:00
										 |  |  |     end if load_tap_migrations | 
					
						
							| 
									
										
										
										
											2013-10-30 11:24:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |     load_formula_renames | 
					
						
							|  |  |  |     report.update_renamed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Migrate installed renamed formulae from core and taps. | 
					
						
							|  |  |  |     report.select_formula(:R).each do |oldname, newname| | 
					
						
							|  |  |  |       if oldname.include?("/") | 
					
						
							|  |  |  |         user, repo, oldname = oldname.split("/", 3) | 
					
						
							|  |  |  |         newname = newname.split("/", 3).last | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2015-08-22 13:15:33 +08:00
										 |  |  |         user = "homebrew" | 
					
						
							|  |  |  |         repo = "homebrew" | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next unless (dir = HOMEBREW_CELLAR/oldname).directory? && !dir.subdirs.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							| 
									
										
										
										
											2015-08-28 15:59:53 +08:00
										 |  |  |         f = Formulary.factory("#{user}/#{repo}/#{newname}") | 
					
						
							|  |  |  |       rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next unless f | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         migrator = Migrator.new(f) | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |         migrator.migrate | 
					
						
							|  |  |  |       rescue Migrator::MigratorDifferentTapsError | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     if report.empty? | 
					
						
							|  |  |  |       puts "Already up-to-date." | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       puts "Updated Homebrew from #{master_updater.initial_revision[0, 8]} to #{master_updater.current_revision[0, 8]}." | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |       report.dump | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-05-05 15:29:01 -07:00
										 |  |  |     Descriptions.update_cache(report) | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   def git_init_if_necessary | 
					
						
							| 
									
										
										
										
											2014-06-20 18:36:18 -05:00
										 |  |  |     if Dir[".git/*"].empty? | 
					
						
							|  |  |  |       safe_system "git", "init" | 
					
						
							|  |  |  |       safe_system "git", "config", "core.autocrlf", "false" | 
					
						
							| 
									
										
										
										
											2014-08-12 01:45:54 -05:00
										 |  |  |       safe_system "git", "config", "remote.origin.url", "https://github.com/Homebrew/homebrew.git" | 
					
						
							|  |  |  |       safe_system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" | 
					
						
							| 
									
										
										
										
											2014-06-20 18:36:18 -05:00
										 |  |  |       safe_system "git", "fetch", "origin" | 
					
						
							|  |  |  |       safe_system "git", "reset", "--hard", "origin/master" | 
					
						
							| 
									
										
										
										
											2009-09-08 00:02:28 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-11-16 20:24:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if `git remote show origin -n` =~ /Fetch URL: \S+mxcl\/homebrew/ | 
					
						
							| 
									
										
										
										
											2014-06-20 18:36:18 -05:00
										 |  |  |       safe_system "git", "remote", "set-url", "origin", "https://github.com/Homebrew/homebrew.git" | 
					
						
							|  |  |  |       safe_system "git", "remote", "set-url", "--delete", "origin", ".*mxcl\/homebrew.*" | 
					
						
							| 
									
										
										
										
											2013-11-16 20:24:24 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   rescue Exception | 
					
						
							|  |  |  |     FileUtils.rm_rf ".git" | 
					
						
							|  |  |  |     raise | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 11:26:45 +09:00
										 |  |  |   def rename_taps_dir_if_necessary | 
					
						
							| 
									
										
										
										
											2014-05-31 23:53:36 -05:00
										 |  |  |     Dir.glob("#{HOMEBREW_LIBRARY}/Taps/*/") do |tapd| | 
					
						
							| 
									
										
										
										
											2014-04-24 11:26:45 +09:00
										 |  |  |       begin | 
					
						
							|  |  |  |         if File.directory?(tapd + "/.git") | 
					
						
							| 
									
										
										
										
											2015-08-15 18:32:22 +08:00
										 |  |  |           tapd_basename = File.basename(tapd) | 
					
						
							| 
									
										
										
										
											2014-04-24 11:26:45 +09:00
										 |  |  |           if tapd_basename.include?("-") | 
					
						
							|  |  |  |             # only replace the *last* dash: yes, tap filenames suck | 
					
						
							|  |  |  |             user, repo = tapd_basename.reverse.sub("-", "/").reverse.split("/") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             FileUtils.mkdir_p("#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}") | 
					
						
							|  |  |  |             FileUtils.mv(tapd, "#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}/homebrew-#{repo.downcase}") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if tapd_basename.count("-") >= 2
 | 
					
						
							|  |  |  |               opoo "Homebrew changed the structure of Taps like <someuser>/<sometap>. "\ | 
					
						
							|  |  |  |                 + "So you may need to rename #{HOMEBREW_LIBRARY}/Taps/#{user.downcase}/homebrew-#{repo.downcase} manually." | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             opoo "Homebrew changed the structure of Taps like <someuser>/<sometap>. "\ | 
					
						
							|  |  |  |               "#{tapd} is incorrect name format. You may need to rename it like <someuser>/<sometap> manually." | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       rescue => ex | 
					
						
							|  |  |  |         onoe ex.message | 
					
						
							|  |  |  |         next # next tap directory | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-02 16:14:43 -06:00
										 |  |  |   def load_tap_migrations | 
					
						
							| 
									
										
										
										
											2015-08-10 17:43:21 +03:00
										 |  |  |     load "tap_migrations.rb" | 
					
						
							| 
									
										
										
										
											2015-08-09 15:09:33 +03:00
										 |  |  |   rescue LoadError | 
					
						
							|  |  |  |     false | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def load_formula_renames | 
					
						
							|  |  |  |     load "formula_renames.rb" | 
					
						
							| 
									
										
										
										
											2013-12-02 16:14:43 -06:00
										 |  |  |   rescue LoadError | 
					
						
							|  |  |  |     false | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  | class Updater | 
					
						
							| 
									
										
										
										
											2014-06-23 18:41:50 -05:00
										 |  |  |   attr_reader :initial_revision, :current_revision, :repository | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def initialize(repository) | 
					
						
							|  |  |  |     @repository = repository | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     @stashed = false | 
					
						
							| 
									
										
										
										
											2014-06-23 18:41:50 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def pull!(options = {}) | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     quiet = [] | 
					
						
							|  |  |  |     quiet << "--quiet" unless ARGV.verbose? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unless system "git", "diff", "--quiet" | 
					
						
							|  |  |  |       unless options[:silent] | 
					
						
							|  |  |  |         puts "Stashing your changes:" | 
					
						
							|  |  |  |         system "git", "status", "--short", "--untracked-files" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       safe_system "git", "stash", "save", "--include-untracked", *quiet | 
					
						
							|  |  |  |       @stashed = true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-15 22:08:55 -07:00
										 |  |  |     # The upstream repository's default branch may not be master; | 
					
						
							|  |  |  |     # check refs/remotes/origin/HEAD to see what the default | 
					
						
							|  |  |  |     # origin branch name is, and use that. If not set, fall back to "master". | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       @upstream_branch = `git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null` | 
					
						
							|  |  |  |       @upstream_branch = @upstream_branch.chomp.sub('refs/remotes/origin/', '') | 
					
						
							|  |  |  |     rescue ErrorDuringExecution | 
					
						
							|  |  |  |       @upstream_branch = "master" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-09-11 11:00:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       @initial_branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp | 
					
						
							|  |  |  |     rescue ErrorDuringExecution | 
					
						
							|  |  |  |       @initial_branch = "" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-15 22:08:55 -07:00
										 |  |  |     if @initial_branch != @upstream_branch && !@initial_branch.empty? | 
					
						
							|  |  |  |       safe_system "git", "checkout", @upstream_branch, *quiet | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-02-18 19:24:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     @initial_revision = read_current_revision | 
					
						
							| 
									
										
										
										
											2010-02-18 19:24:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     # ensure we don't munge line endings on checkout | 
					
						
							| 
									
										
										
										
											2014-06-20 18:36:18 -05:00
										 |  |  |     safe_system "git", "config", "core.autocrlf", "false" | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-09 23:50:55 +01:00
										 |  |  |     args = ["pull"] | 
					
						
							| 
									
										
										
										
											2015-07-10 09:46:35 -04:00
										 |  |  |     args << "--ff" | 
					
						
							|  |  |  |     args << ((ARGV.include? "--rebase") ? "--rebase" : "--no-rebase") | 
					
						
							| 
									
										
										
										
											2015-07-09 23:50:55 +01:00
										 |  |  |     args += quiet | 
					
						
							|  |  |  |     args << "origin" | 
					
						
							| 
									
										
										
										
											2015-09-15 22:08:55 -07:00
										 |  |  |     # the refspec ensures that the default upstream branch gets updated | 
					
						
							|  |  |  |     args << "refs/heads/#{@upstream_branch}:refs/remotes/origin/#{@upstream_branch}" | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 15:08:03 -05:00
										 |  |  |     reset_on_interrupt { safe_system "git", *args } | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 16:02:24 +02:00
										 |  |  |     @current_revision = read_current_revision | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     if @initial_branch != "master" && !@initial_branch.empty? | 
					
						
							|  |  |  |       safe_system "git", "checkout", @initial_branch, *quiet | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if @stashed | 
					
						
							|  |  |  |       safe_system "git", "stash", "pop", *quiet | 
					
						
							|  |  |  |       unless options[:silent] | 
					
						
							|  |  |  |         puts "Restored your changes:" | 
					
						
							|  |  |  |         system "git", "status", "--short", "--untracked-files" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       @stashed = false | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 15:08:03 -05:00
										 |  |  |   def reset_on_interrupt | 
					
						
							|  |  |  |     ignore_interrupts { yield } | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     if $?.signaled? && $?.termsig == 2 # SIGINT | 
					
						
							| 
									
										
										
										
											2015-09-11 11:00:07 +01:00
										 |  |  |       safe_system "git", "checkout", @initial_branch unless @initial_branch.empty? | 
					
						
							| 
									
										
										
										
											2013-09-10 15:08:03 -05:00
										 |  |  |       safe_system "git", "reset", "--hard", @initial_revision | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |       safe_system "git", "stash", "pop" if @stashed | 
					
						
							| 
									
										
										
										
											2013-09-10 15:08:03 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  |   def report | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     map = Hash.new { |h, k| h[k] = [] } | 
					
						
							| 
									
										
										
										
											2011-08-26 13:04:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     if initial_revision && initial_revision != current_revision | 
					
						
							| 
									
										
										
										
											2015-08-19 16:02:24 +02:00
										 |  |  |       wc_revision = read_current_revision | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |       diff.each_line do |line| | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |         status, *paths = line.split | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         src = paths.first | 
					
						
							|  |  |  |         dst = paths.last | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 15:54:03 -05:00
										 |  |  |         next unless File.extname(dst) == ".rb" | 
					
						
							|  |  |  |         next unless paths.any? { |p| File.dirname(p) == formula_directory } | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         case status | 
					
						
							| 
									
										
										
										
											2015-05-30 17:29:33 +08:00
										 |  |  |         when "A", "D" | 
					
						
							| 
									
										
										
										
											2014-07-31 15:54:03 -05:00
										 |  |  |           map[status.to_sym] << repository.join(src) | 
					
						
							| 
									
										
										
										
											2015-05-30 17:29:33 +08:00
										 |  |  |         when "M" | 
					
						
							|  |  |  |           file = repository.join(src) | 
					
						
							|  |  |  |           begin | 
					
						
							|  |  |  |             formula = Formulary.factory(file) | 
					
						
							| 
									
										
										
										
											2015-08-19 16:02:24 +02:00
										 |  |  |             new_version = if wc_revision == current_revision | 
					
						
							|  |  |  |               formula.pkg_version | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               FormulaVersions.new(formula).formula_at_revision(@current_revision, &:pkg_version) | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-05-30 17:29:33 +08:00
										 |  |  |             old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version) | 
					
						
							|  |  |  |             next if new_version == old_version | 
					
						
							| 
									
										
										
										
											2015-08-06 23:49:37 +08:00
										 |  |  |           rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e | 
					
						
							| 
									
										
										
										
											2015-05-30 17:29:33 +08:00
										 |  |  |             onoe e if ARGV.homebrew_developer? | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           map[:M] << file | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |         when /^R\d{0,3}/ | 
					
						
							| 
									
										
										
										
											2014-07-31 15:54:03 -05:00
										 |  |  |           map[:D] << repository.join(src) if File.dirname(src) == formula_directory | 
					
						
							|  |  |  |           map[:A] << repository.join(dst) if File.dirname(dst) == formula_directory | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-08-26 13:04:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     map | 
					
						
							| 
									
										
										
										
											2010-07-23 17:32:43 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-08 00:02:28 +02:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2010-07-23 17:37:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |   def formula_directory | 
					
						
							|  |  |  |     if repository == HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |       "Library/Formula" | 
					
						
							|  |  |  |     elsif repository.join("Formula").directory? | 
					
						
							|  |  |  |       "Formula" | 
					
						
							|  |  |  |     elsif repository.join("HomebrewFormula").directory? | 
					
						
							|  |  |  |       "HomebrewFormula" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       "." | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   def read_current_revision | 
					
						
							| 
									
										
										
										
											2012-03-22 18:22:19 -05:00
										 |  |  |     `git rev-parse -q --verify HEAD`.chomp | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |   def diff | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     Utils.popen_read( | 
					
						
							|  |  |  |       "git", "diff-tree", "-r", "--name-status", "--diff-filter=AMDR", | 
					
						
							|  |  |  |       "-M85%", initial_revision, current_revision | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   def `(cmd) | 
					
						
							| 
									
										
										
										
											2014-06-23 18:50:55 -05:00
										 |  |  |     out = super | 
					
						
							| 
									
										
										
										
											2014-09-18 21:48:54 -05:00
										 |  |  |     unless $?.success? | 
					
						
							|  |  |  |       $stderr.puts(out) unless out.empty? | 
					
						
							| 
									
										
										
										
											2014-09-18 20:32:50 -05:00
										 |  |  |       raise ErrorDuringExecution.new(cmd) | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |     ohai(cmd, out) if ARGV.verbose? | 
					
						
							|  |  |  |     out | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 21:58:15 -05:00
										 |  |  | class Report | 
					
						
							|  |  |  |   def initialize | 
					
						
							|  |  |  |     @hash = {} | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def fetch(*args, &block) | 
					
						
							|  |  |  |     @hash.fetch(*args, &block) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update(*args, &block) | 
					
						
							|  |  |  |     @hash.update(*args, &block) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def empty? | 
					
						
							|  |  |  |     @hash.empty? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |   def dump | 
					
						
							|  |  |  |     # Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-05 13:43:07 -07:00
										 |  |  |     dump_formula_report :A, "New Formulae" | 
					
						
							|  |  |  |     dump_formula_report :M, "Updated Formulae" | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |     dump_formula_report :R, "Renamed Formulae" | 
					
						
							| 
									
										
										
										
											2012-10-05 13:43:07 -07:00
										 |  |  |     dump_formula_report :D, "Deleted Formulae" | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |   def update_renamed | 
					
						
							| 
									
										
										
										
											2015-08-20 20:12:02 +08:00
										 |  |  |     renamed_formulae = [] | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fetch(:D, []).each do |path| | 
					
						
							| 
									
										
										
										
											2014-05-14 16:43:52 +09:00
										 |  |  |       case path.to_s | 
					
						
							|  |  |  |       when HOMEBREW_TAP_PATH_REGEX | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |         user = $1 | 
					
						
							|  |  |  |         repo = $2.sub("homebrew-", "") | 
					
						
							|  |  |  |         oldname = path.basename(".rb").to_s | 
					
						
							| 
									
										
										
										
											2015-09-27 16:52:14 +08:00
										 |  |  |         next unless newname = Tap.fetch(user, repo).formula_renames[oldname] | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |       else | 
					
						
							|  |  |  |         oldname = path.basename(".rb").to_s | 
					
						
							|  |  |  |         next unless newname = FORMULA_RENAMES[oldname] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if fetch(:A, []).include?(newpath = path.dirname.join("#{newname}.rb")) | 
					
						
							| 
									
										
										
										
											2015-08-20 20:12:02 +08:00
										 |  |  |         renamed_formulae << [path, newpath] | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 20:12:02 +08:00
										 |  |  |     unless renamed_formulae.empty? | 
					
						
							|  |  |  |       @hash[:A] -= renamed_formulae.map(&:last) if @hash[:A] | 
					
						
							|  |  |  |       @hash[:D] -= renamed_formulae.map(&:first) if @hash[:D] | 
					
						
							|  |  |  |       @hash[:R] = renamed_formulae | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def select_formula(key) | 
					
						
							|  |  |  |     fetch(key, []).map do |path, newpath| | 
					
						
							|  |  |  |       if path.to_s =~ HOMEBREW_TAP_PATH_REGEX | 
					
						
							|  |  |  |         tap = "#{$1}/#{$2.sub("homebrew-", "")}" | 
					
						
							|  |  |  |         if newpath | 
					
						
							|  |  |  |           ["#{tap}/#{path.basename(".rb")}", "#{tap}/#{newpath.basename(".rb")}"] | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           "#{tap}/#{path.basename(".rb")}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       elsif newpath | 
					
						
							|  |  |  |         ["#{path.basename(".rb")}", "#{newpath.basename(".rb")}"] | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |       else | 
					
						
							|  |  |  |         path.basename(".rb").to_s | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     end.sort | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def dump_formula_report(key, title) | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     formula = select_formula(key) | 
					
						
							| 
									
										
										
										
											2015-08-17 21:49:55 +03:00
										 |  |  |     formula.map! { |oldname, newname| "#{oldname} -> #{newname}" } if key == :R | 
					
						
							| 
									
										
										
										
											2012-03-06 02:23:01 +00:00
										 |  |  |     unless formula.empty? | 
					
						
							|  |  |  |       ohai title | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |       puts_columns formula | 
					
						
							| 
									
										
										
										
											2009-09-11 20:58:41 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-09-11 20:09:39 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-17 18:40:21 +01:00
										 |  |  | end |