| 
									
										
										
										
											2020-11-25 17:03:23 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "formula" | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |   def bump_revision_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											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." | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args :formula, min: 1
 | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bump_revision | 
					
						
							| 
									
										
										
										
											2020-07-27 03:59:52 +02:00
										 |  |  |     args = bump_revision_args.parse | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:13:43 -04:00
										 |  |  |     # As this command is simplifying user-run commands then let's just use a | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |     # user path, too. | 
					
						
							|  |  |  |     ENV["PATH"] = ENV["HOMEBREW_PATH"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     args.named.to_formulae.each do |formula| | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |       current_revision = formula.revision | 
					
						
							| 
									
										
										
										
											2021-01-03 21:41:35 -08:00
										 |  |  |       new_revision = current_revision + 1
 | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-18 17:24:40 -08:00
										 |  |  |       if args.dry_run? | 
					
						
							|  |  |  |         unless args.quiet? | 
					
						
							| 
									
										
										
										
											2021-01-03 21:41:35 -08:00
										 |  |  |           old_text = "revision #{current_revision}" | 
					
						
							|  |  |  |           new_text = "revision #{new_revision}" | 
					
						
							| 
									
										
										
										
											2020-12-18 17:24:40 -08:00
										 |  |  |           if current_revision.zero? | 
					
						
							| 
									
										
										
										
											2021-01-03 21:41:35 -08:00
										 |  |  |             ohai "add #{new_text.inspect}" | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2021-01-03 21:41:35 -08:00
										 |  |  |             ohai "replace #{old_text.inspect} with #{new_text.inspect}" | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-07-30 09:30:44 -04:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2021-01-06 09:11:34 -08:00
										 |  |  |         Homebrew.install_bundler_gems! | 
					
						
							|  |  |  |         require "utils/ast" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 09:14:16 -08:00
										 |  |  |         formula_ast = Utils::AST::FormulaAST.new(formula.path.read) | 
					
						
							|  |  |  |         if current_revision.zero? | 
					
						
							|  |  |  |           formula_ast.add_stanza(:revision, new_revision) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           formula_ast.replace_stanza(:revision, new_revision) | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-10 09:14:16 -08:00
										 |  |  |         formula.path.atomic_write(formula_ast.process) | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-15 10:43:29 +02:00
										 |  |  |       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", | 
					
						
							|  |  |  |                       "--message=#{message}", "--", formula.path | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-03-31 19:06:29 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |