From 503b51c54f6588c9e38037e8cbfb9cda4f1aba7e Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 24 Jul 2022 22:44:25 +0100 Subject: [PATCH] dev-cmd/contributions: Better error messages for bad `--repos` ``` $ brew contributions --email=me@issyl0.co.uk --repos=coreeeee Error: Unsupported repo: coreeeee. Try one of brew, core, cask, bundle. $ brew untap homebrew/bundle $ brew contributions --email=me@issyl0.co.uk --repos=bundle Error: Couldn't find repo bundle locally. Do you have it tapped? ``` --- Library/Homebrew/dev-cmd/contributions.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index 2a528cf86b..b3eb9c3bc5 100755 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -46,14 +46,15 @@ module Homebrew coauthorships = 0 args[:repos].each do |repo| - repo_location = find_repo_path_for_repo(repo) - unless repo_location - return ofail "Couldn't find location for #{repo}. Do you have it tapped, or is there a typo? " \ - "We only support #{SUPPORTED_REPOS.join(", ")} repos so far." + if SUPPORTED_REPOS.exclude?(repo) + return ofail "Unsupported repo: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." end - commits += git_log_cmd("author", repo_location, args) - coauthorships += git_log_cmd("coauthorships", repo_location, args) + repo_path = find_repo_path_for_repo(repo) + return ofail "Couldn't find repo #{repo} locally. Do you have it tapped?" unless Dir.exist?(repo_path) + + commits += git_log_cmd("author", repo_path, args) + coauthorships += git_log_cmd("coauthorships", repo_path, args) end sentence = "Person #{args[:email]} directly authored #{commits} commits" @@ -87,9 +88,9 @@ module Homebrew end end - sig { params(kind: String, repo_location: String, args: Homebrew::CLI::Args).returns(Integer) } - def git_log_cmd(kind, repo_location, args) - cmd = "git -C #{repo_location} log --oneline" + sig { params(kind: String, repo_path: String, args: Homebrew::CLI::Args).returns(Integer) } + def git_log_cmd(kind, repo_path, args) + cmd = "git -C #{repo_path} log --oneline" cmd += " --author=#{args[:email]}" if kind == "author" cmd += " --format='%(trailers:key=Co-authored-by:)'" if kind == "coauthorships" cmd += " --before=#{args[:to]}" if args[:to]