| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  | require "tap" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   def tap | 
					
						
							|  |  |  |     if ARGV.empty? | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |       puts Tap.names | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |     elsif ARGV.first == "--repair" | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |       migrate_taps :force => true | 
					
						
							| 
									
										
										
										
											2015-08-03 20:39:00 +02:00
										 |  |  |     elsif ARGV.first == "--list-official" | 
					
						
							|  |  |  |       require "official_taps" | 
					
						
							| 
									
										
										
										
											2015-08-21 12:33:33 +08:00
										 |  |  |       puts OFFICIAL_TAPS.map { |t| "homebrew/#{t}" } | 
					
						
							|  |  |  |     elsif ARGV.first == "--list-pinned" | 
					
						
							|  |  |  |       puts Tap.select(&:pinned?).map(&:name) | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-06-02 17:27:05 -04:00
										 |  |  |       user, repo = tap_args | 
					
						
							|  |  |  |       clone_target = ARGV.named[1] | 
					
						
							|  |  |  |       opoo "Already tapped!" unless install_tap(user, repo, clone_target) | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def install_tap(user, repo, clone_target = nil) | 
					
						
							| 
									
										
										
										
											2015-06-13 01:57:00 +08:00
										 |  |  |     tap = Tap.new user, repo | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |     return false if tap.installed? | 
					
						
							|  |  |  |     ohai "Tapping #{tap}" | 
					
						
							| 
									
										
										
										
											2015-06-13 01:57:00 +08:00
										 |  |  |     remote = clone_target || "https://github.com/#{tap.user}/homebrew-#{tap.repo}" | 
					
						
							|  |  |  |     args = %W[clone #{remote} #{tap.path}] | 
					
						
							| 
									
										
										
										
											2015-04-01 20:31:17 +08:00
										 |  |  |     args << "--depth=1" unless ARGV.include?("--full") | 
					
						
							| 
									
										
										
										
											2015-08-28 14:33:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       safe_system "git", *args | 
					
						
							|  |  |  |     rescue Interrupt, ErrorDuringExecution | 
					
						
							|  |  |  |       ignore_interrupts do | 
					
						
							|  |  |  |         sleep 0.1 # wait for git to cleanup the top directory when interrupt happens. | 
					
						
							|  |  |  |         tap.path.parent.rmdir_if_possible | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       raise | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |     formula_count = tap.formula_files.size | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{tap.path.abv})" | 
					
						
							| 
									
										
										
										
											2012-05-14 16:18:24 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |     if !clone_target && tap.private? | 
					
						
							| 
									
										
										
										
											2015-06-02 17:27:05 -04:00
										 |  |  |       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: | 
					
						
							| 
									
										
										
										
											2014-02-08 20:41:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 18:05:58 +08:00
										 |  |  |           cd #{tap.path} | 
					
						
							|  |  |  |           git remote set-url origin git@github.com:#{tap.user}/homebrew-#{tap.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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |   # Migrate tapped formulae from symlink-based to directory-based structure. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def migrate_taps(options = {}) | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |     ignore = HOMEBREW_LIBRARY/"Formula/.gitignore" | 
					
						
							|  |  |  |     return unless ignore.exist? || options.fetch(:force, false) | 
					
						
							| 
									
										
										
										
											2015-08-17 17:08:23 +02:00
										 |  |  |     (HOMEBREW_LIBRARY/"Formula").children.each { |c| c.unlink if c.symlink? } | 
					
						
							| 
									
										
										
										
											2015-05-08 20:19:12 +08:00
										 |  |  |     ignore.unlink if ignore.exist? | 
					
						
							| 
									
										
										
										
											2012-08-04 15:06:37 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def tap_args(tap_name = ARGV.named.first) | 
					
						
							| 
									
										
										
										
											2015-02-01 12:11:54 -05:00
										 |  |  |     tap_name =~ 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 | 
					
						
							| 
									
										
										
										
											2012-03-16 12:49:09 +00:00
										 |  |  | end |