| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "formula" | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bump_revision_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2019-08-06 14:17:17 -04:00
										 |  |  |         `bump-revision` [<options>] <formula> | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 14:20:27 -04:00
										 |  |  |         Create a commit to increment the revision of <formula>. If no revision is | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |         present, "revision 1" will be added. | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |       EOS | 
					
						
							|  |  |  |       switch "-n", "--dry-run", | 
					
						
							| 
									
										
										
										
											2019-05-14 12:03:06 -04:00
										 |  |  |              description: "Print what would be done rather than doing it." | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |       flag   "--message=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Append <message> to the default commit message." | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |       switch :force | 
					
						
							|  |  |  |       switch :quiet | 
					
						
							|  |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2019-12-13 16:50:54 -05:00
										 |  |  |       max_named 1
 | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bump_revision | 
					
						
							|  |  |  |     bump_revision_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # As this command is simplifying user run commands then let's just use a | 
					
						
							|  |  |  |     # user path, too. | 
					
						
							|  |  |  |     ENV["PATH"] = ENV["HOMEBREW_PATH"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 19:56:24 +05:30
										 |  |  |     formulae = Homebrew.args.formulae | 
					
						
							|  |  |  |     raise FormulaUnspecifiedError if formulae.empty? | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 19:56:24 +05:30
										 |  |  |     formula = formulae.first | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |     current_revision = formula.revision | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if current_revision.zero? | 
					
						
							|  |  |  |       formula_spec = formula.stable | 
					
						
							|  |  |  |       hash_type, old_hash = if (checksum = formula_spec.checksum) | 
					
						
							|  |  |  |         [checksum.hash_type, checksum.hexdigest] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if hash_type | 
					
						
							|  |  |  |         # insert replacement revision after hash | 
					
						
							|  |  |  |         old = <<~EOS | 
					
						
							|  |  |  |           #{hash_type} "#{old_hash}" | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         # insert replacement revision after :revision | 
					
						
							|  |  |  |         old = <<~EOS | 
					
						
							|  |  |  |           :revision => "#{formula_spec.specs[:revision]}" | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       replacement = old + "  revision 1\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       old = "revision #{current_revision}" | 
					
						
							|  |  |  |       replacement = "revision #{current_revision+1}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       ohai "replace #{old.inspect} with #{replacement.inspect}" unless Homebrew.args.quiet? | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Utils::Inreplace.inreplace(formula.path) do |s| | 
					
						
							|  |  |  |         s.gsub!(old, replacement) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     message = "#{formula.name}: revision bump #{args.message}" | 
					
						
							|  |  |  |     if args.dry_run? | 
					
						
							|  |  |  |       ohai "git commit --no-edit --verbose --message=#{message} -- #{formula.path}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       formula.path.parent.cd do | 
					
						
							|  |  |  |         safe_system "git", "commit", "--no-edit", "--verbose", | 
					
						
							| 
									
										
										
										
											2019-05-14 12:03:06 -04:00
										 |  |  |                     "--message=#{message}", "--", formula.path | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |