| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2015-05-08 13:48:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  |   def log_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2021-09-30 09:56:39 +09:00
										 |  |  |         Show the `git log` for <formula> or <cask>, or show the log for the Homebrew repository | 
					
						
							|  |  |  |         if no formula or cask is provided. | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  |       EOS | 
					
						
							|  |  |  |       switch "-p", "-u", "--patch", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Also print patch from commit." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  |       switch "--stat", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Also print diffstat from commit." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  |       switch "--oneline", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Print only one line per commit." | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  |       switch "-1", | 
					
						
							|  |  |  |              description: "Print only one commit." | 
					
						
							|  |  |  |       flag   "-n", "--max-count=", | 
					
						
							|  |  |  |              description: "Print only a specified number of commits." | 
					
						
							| 
									
										
										
										
											2021-09-29 22:24:20 +09:00
										 |  |  |       switch "--formula", "--formulae", | 
					
						
							|  |  |  |              description: "Treat all named arguments as formulae." | 
					
						
							|  |  |  |       switch "--cask", "--casks", | 
					
						
							|  |  |  |              description: "Treat all named arguments as casks." | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  |       conflicts "-1", "--max-count" | 
					
						
							| 
									
										
										
										
											2021-09-29 22:24:20 +09:00
										 |  |  |       conflicts "--formula", "--cask" | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 22:24:20 +09:00
										 |  |  |       named_args [:formula, :cask], max: 1
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def log | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = log_args.parse | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:13:43 -04:00
										 |  |  |     # As this command is simplifying user-run commands then let's just use a | 
					
						
							| 
									
										
										
										
											2020-02-24 13:25:59 +01:00
										 |  |  |     # user path, too. | 
					
						
							| 
									
										
										
										
											2022-06-15 05:40:43 +01:00
										 |  |  |     ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s | 
					
						
							| 
									
										
										
										
											2020-02-24 13:25:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |     if args.no_named? | 
					
						
							| 
									
										
										
										
											2020-08-03 17:30:46 +01:00
										 |  |  |       git_log HOMEBREW_REPOSITORY, args: args | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-09-29 22:24:20 +09:00
										 |  |  |       path = args.named.to_paths.first | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  |       tap = Tap.from_path(path) | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  |       git_log path.dirname, path, tap, args: args | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-11-23 15:03:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  |   def git_log(cd_dir, path = nil, tap = nil, args:) | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  |     cd cd_dir | 
					
						
							| 
									
										
										
										
											2021-03-17 15:34:20 +00:00
										 |  |  |     repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  |     if tap | 
					
						
							|  |  |  |       name = tap.to_s | 
					
						
							|  |  |  |       git_cd = "$(brew --repo #{tap})" | 
					
						
							|  |  |  |     elsif cd_dir == HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |       name = "Homebrew/brew" | 
					
						
							|  |  |  |       git_cd = "$(brew --repo)" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       name, git_cd = cd_dir | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if File.exist? "#{repo}/.git/shallow" | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       opoo <<~EOS | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  |         #{name} is a shallow clone so only partial output will be shown. | 
					
						
							| 
									
										
										
										
											2021-01-26 15:21:24 -05:00
										 |  |  |         To get a full clone, run: | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  |           git -C "#{git_cd}" fetch --unshallow | 
					
						
							| 
									
										
										
										
											2015-11-23 15:03:12 +01:00
										 |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     git_args = [] | 
					
						
							|  |  |  |     git_args << "--patch" if args.patch? | 
					
						
							|  |  |  |     git_args << "--stat" if args.stat? | 
					
						
							|  |  |  |     git_args << "--oneline" if args.oneline? | 
					
						
							| 
									
										
										
										
											2021-06-02 11:43:16 +05:30
										 |  |  |     git_args << "-1" if args.public_send(:"1?") | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  |     git_args << "--max-count" << args.max_count if args.max_count | 
					
						
							|  |  |  |     git_args += ["--follow", "--", path] if path.present? | 
					
						
							|  |  |  |     system "git", "log", *git_args | 
					
						
							| 
									
										
										
										
											2015-11-23 15:03:12 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |