| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   def tap | 
					
						
							|  |  |  |     if ARGV.empty? | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |       each_tap do |user, repo| | 
					
						
							|  |  |  |         puts "#{user.basename}/#{repo.basename.sub("homebrew-", "")}" if (repo/".git").directory? | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |     elsif ARGV.first == "--repair" | 
					
						
							|  |  |  |       repair_taps | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2014-01-03 21:51:23 +00:00
										 |  |  |       opoo "Already tapped!" unless install_tap(*tap_args) | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def install_tap user, repo | 
					
						
							| 
									
										
										
										
											2012-03-18 01:45:26 +00:00
										 |  |  |     # we special case homebrew so users don't have to shift in a terminal | 
					
						
							|  |  |  |     repouser = if user == "homebrew" then "Homebrew" else user end | 
					
						
							|  |  |  |     user = "homebrew" if user == "Homebrew" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # we downcase to avoid case-insensitive filesystem issues | 
					
						
							| 
									
										
										
										
											2014-04-24 11:26:45 +09:00
										 |  |  |     tapd = HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}" | 
					
						
							| 
									
										
										
										
											2014-01-03 21:51:23 +00:00
										 |  |  |     return false if tapd.directory? | 
					
						
							| 
									
										
										
										
											2014-06-20 18:36:18 -05:00
										 |  |  |     abort unless system "git", "clone", "https://github.com/#{repouser}/homebrew-#{repo}", tapd.to_s | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 22:48:44 +00:00
										 |  |  |     files = [] | 
					
						
							| 
									
										
										
										
											2014-04-25 18:58:16 -05:00
										 |  |  |     tapd.find_formula { |file| files << file } | 
					
						
							| 
									
										
										
										
											2013-02-28 10:56:40 -06:00
										 |  |  |     link_tap_formula(files) | 
					
						
							| 
									
										
										
										
											2014-05-26 11:19:00 -07:00
										 |  |  |     puts "Tapped #{files.length} formula#{plural(files.length, 'e')}" | 
					
						
							| 
									
										
										
										
											2012-05-14 16:18:24 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 20:41:11 -05:00
										 |  |  |     if private_tap?(repouser, repo) then puts <<-EOS.undent
 | 
					
						
							|  |  |  |       It looks like you tapped a private repository. To avoid entering your | 
					
						
							|  |  |  |       credentials each time you update, you can use git HTTP credential caching | 
					
						
							|  |  |  |       or issue the following command: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cd #{tapd} | 
					
						
							|  |  |  |         git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2012-05-14 16:18:24 -06:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-01-03 21:51:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     true | 
					
						
							| 
									
										
										
										
											2012-03-07 22:48:44 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |   def link_tap_formula paths | 
					
						
							| 
									
										
										
										
											2012-03-07 22:48:44 +00:00
										 |  |  |     ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue [] | 
					
						
							| 
									
										
										
										
											2012-03-16 17:11:40 +00:00
										 |  |  |     tapped = 0
 | 
					
						
							| 
									
										
										
										
											2012-03-07 22:48:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |     paths.each do |path| | 
					
						
							|  |  |  |       to = HOMEBREW_LIBRARY.join("Formula", path.basename) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:04:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Unexpected, but possible, lets proceed as if nothing happened | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |       to.delete if to.symlink? && to.resolved_path == path | 
					
						
							| 
									
										
										
										
											2014-04-24 18:04:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |         to.make_relative_symlink(path) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:04:53 -05:00
										 |  |  |       rescue SystemCallError | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |         to = to.resolved_path if to.symlink? | 
					
						
							|  |  |  |         opoo "Could not tap #{Tty.white}#{tap_ref(path)}#{Tty.reset} over #{Tty.white}#{tap_ref(to)}#{Tty.reset}" | 
					
						
							| 
									
										
										
										
											2014-04-24 18:04:53 -05:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2014-04-25 15:12:13 -05:00
										 |  |  |         ignores << path.basename.to_s | 
					
						
							| 
									
										
										
										
											2014-04-24 18:04:53 -05:00
										 |  |  |         tapped += 1
 | 
					
						
							| 
									
										
										
										
											2012-03-04 02:47:11 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-03-04 02:47:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 12:58:39 +00:00
										 |  |  |     HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n")) | 
					
						
							| 
									
										
										
										
											2012-03-16 22:06:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     tapped | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |   def repair_taps | 
					
						
							|  |  |  |     count = 0
 | 
					
						
							|  |  |  |     # prune dead symlinks in Formula | 
					
						
							| 
									
										
										
										
											2014-05-31 23:53:36 -05:00
										 |  |  |     Dir.glob("#{HOMEBREW_LIBRARY}/Formula/*.rb") do |fn| | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |       if not File.exist? fn | 
					
						
							|  |  |  |         File.delete fn | 
					
						
							|  |  |  |         count += 1
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-05-26 11:19:00 -07:00
										 |  |  |     puts "Pruned #{count} dead formula#{plural(count, 'e')}" | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-14 09:35:16 -07:00
										 |  |  |     return unless HOMEBREW_REPOSITORY.join("Library/Taps").exist? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |     count = 0
 | 
					
						
							|  |  |  |     # check symlinks are all set in each tap | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |     each_tap do |user, repo| | 
					
						
							|  |  |  |       files = [] | 
					
						
							| 
									
										
										
										
											2014-04-25 18:58:16 -05:00
										 |  |  |       repo.find_formula { |file| files << file } | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |       count += link_tap_formula(files) | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 11:19:00 -07:00
										 |  |  |     puts "Tapped #{count} formula#{plural(count, 'e')}" | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-25 11:25:38 -05:00
										 |  |  |   def each_tap | 
					
						
							|  |  |  |     taps = HOMEBREW_LIBRARY.join("Taps") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if taps.directory? | 
					
						
							|  |  |  |       taps.subdirs.each do |user| | 
					
						
							|  |  |  |         user.subdirs.each do |repo| | 
					
						
							|  |  |  |           yield user, repo | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   def tap_args | 
					
						
							| 
									
										
										
										
											2014-05-14 16:43:52 +09:00
										 |  |  |     ARGV.first =~ HOMEBREW_TAP_ARGS_REGEX | 
					
						
							| 
									
										
										
										
											2014-01-12 00:20:33 +09:00
										 |  |  |     raise "Invalid tap name" unless $1 && $3 | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     [$1, $3] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 20:41:11 -05:00
										 |  |  |   def private_tap?(user, repo) | 
					
						
							|  |  |  |     GitHub.private_repo?(user, "homebrew-#{repo}") | 
					
						
							| 
									
										
										
										
											2014-02-23 23:04:44 -05:00
										 |  |  |   rescue GitHub::HTTPNotFoundError | 
					
						
							| 
									
										
										
										
											2014-02-08 20:41:11 -05:00
										 |  |  |     true | 
					
						
							|  |  |  |   rescue GitHub::Error | 
					
						
							|  |  |  |     false | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-16 12:49:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:26:05 -05:00
										 |  |  |   def tap_ref(path) | 
					
						
							|  |  |  |     case path.to_s | 
					
						
							| 
									
										
										
										
											2014-07-06 12:42:08 -05:00
										 |  |  |     when %r{^#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Formula}o | 
					
						
							|  |  |  |       "Homebrew/homebrew/#{path.basename(".rb")}" | 
					
						
							| 
									
										
										
										
											2014-05-14 16:43:52 +09:00
										 |  |  |     when HOMEBREW_TAP_PATH_REGEX | 
					
						
							| 
									
										
										
										
											2014-07-06 12:42:08 -05:00
										 |  |  |       "#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}" | 
					
						
							| 
									
										
										
										
											2012-03-16 12:49:09 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |