84 lines
2.5 KiB
Ruby
Raw Normal View History

2023-03-06 09:49:53 -08:00
# typed: true
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
2023-03-06 15:11:10 -08:00
def self.log_args
2019-01-30 21:30:18 +00:00
Homebrew::CLI::Parser.new do
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",
description: "Also print patch from commit."
2019-01-30 21:30:18 +00:00
switch "--stat",
description: "Also print diffstat from commit."
2019-01-30 21:30:18 +00:00
switch "--oneline",
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
named_args [:formula, :cask], max: 1, without_api: true
2019-01-30 21:30:18 +00:00
end
end
2023-03-06 15:11:10 -08:00
def self.log
2020-07-30 18:40:10 +02:00
args = log_args.parse
2019-01-30 21:30:18 +00:00
# As this command is simplifying user-run commands then let's just use a
# user path, too.
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
if args.no_named?
2024-03-07 16:20:20 +00:00
git_log(HOMEBREW_REPOSITORY, args:)
else
2021-09-29 22:24:20 +09:00
path = args.named.to_paths.first
tap = Tap.from_path(path)
2024-03-07 16:20:20 +00:00
git_log path.dirname, path, tap, args:
end
end
2023-03-06 15:11:10 -08:00
def self.git_log(cd_dir, path = nil, tap = nil, args:)
2023-03-06 15:00:50 -08:00
cd cd_dir do
repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp
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
2023-03-06 15:00:50 -08:00
if File.exist? "#{repo}/.git/shallow"
opoo <<~EOS
#{name} is a shallow clone so only partial output will be shown.
To get a full clone, run:
git -C "#{git_cd}" fetch --unshallow
EOS
end
2020-07-31 17:06:04 +02:00
2023-03-06 15:00:50 -08:00
git_args = []
git_args << "--patch" if args.patch?
git_args << "--stat" if args.stat?
git_args << "--oneline" if args.oneline?
git_args << "-1" if args.public_send(:"1?")
git_args << "--max-count" << args.max_count if args.max_count
git_args += ["--follow", "--", path] if path.present?
system "git", "log", *git_args
end
end
end