From 23dec587fd26c606e459e72b2987e73bc910a095 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 3 Oct 2016 16:12:19 +0200 Subject: [PATCH] Make `core_tap_version_string` reusable. --- Library/Homebrew/brew.rb | 3 ++- Library/Homebrew/cask/lib/hbc/version.rb | 11 ++++------- Library/Homebrew/tap.rb | 9 ++++++++- Library/Homebrew/utils.rb | 12 ------------ 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 4ab3609953..a73df50d24 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -14,8 +14,9 @@ $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) require "global" if ARGV == %w[--version] || ARGV == %w[-v] + require "tap" puts "Homebrew #{HOMEBREW_VERSION}" - puts "Homebrew/homebrew-core #{Homebrew.core_tap_version_string}" + puts "Homebrew/homebrew-core #{CoreTap.instance.version_string}" exit 0 end diff --git a/Library/Homebrew/cask/lib/hbc/version.rb b/Library/Homebrew/cask/lib/hbc/version.rb index 471fd1999d..2eb942b956 100644 --- a/Library/Homebrew/cask/lib/hbc/version.rb +++ b/Library/Homebrew/cask/lib/hbc/version.rb @@ -1,13 +1,10 @@ -HBC_VERSION = "0.60.0".freeze - module Hbc def self.full_version @full_version ||= begin - revision, commit = Dir.chdir(Hbc.default_tap.path) do - [`git rev-parse --short=4 --verify -q HEAD 2>/dev/null`.chomp, - `git show -s --format="%cr" HEAD 2>/dev/null`.chomp] - end - "#{HBC_VERSION} (git revision #{revision}; last commit #{commit})" + <<-EOS.undent + Homebrew-Cask #{HOMEBREW_VERSION} + caskroom/homebrew-cask #{Hbc.default_tap.version_string} + EOS end end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index c73e3f7a73..d970a0a37f 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -138,6 +138,13 @@ class Tap name end + def version_string + return "N/A" unless installed? + pretty_revision = git_short_head + return "(no git repository)" unless pretty_revision + "(git revision #{pretty_revision}; last commit #{git_last_commit_date})" + end + # True if this {Tap} is an official Homebrew tap. def official? user == "Homebrew" @@ -525,7 +532,7 @@ class CoreTap < Tap end def self.instance - @instance ||= CoreTap.new + @instance ||= new end def self.ensure_installed!(options = {}) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 04d1572621..fbe603b912 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -173,18 +173,6 @@ module Homebrew _system(cmd, *args) end - def core_tap_version_string - require "tap" - tap = CoreTap.instance - return "N/A" unless tap.installed? - if pretty_revision = tap.git_short_head - last_commit = tap.git_last_commit_date - "(git revision #{pretty_revision}; last commit #{last_commit})" - else - "(no git repository)" - end - end - def install_gem_setup_path!(name, version = nil, executable = name) # Respect user's preferences for where gems should be installed. ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s