aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorTim D. Smith2015-07-18 21:55:50 -0700
committerTim D. Smith2015-08-25 00:13:53 -0700
commit143709e6797c8c85a9632e46f18d36a7113ce83e (patch)
tree2667b2a34b47636d952a131a8f88e83b628fb9b8 /Library/Homebrew
parentb808eed08f3b3ef34085c6119112ca860f61e455 (diff)
downloadbrew-143709e6797c8c85a9632e46f18d36a7113ce83e.tar.bz2
include git sha1 in --version output
HOMEBREW_VERSION doesn't change very often; the repository state is more interesting. Closes Homebrew/homebrew#41886.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/test/test_integration_cmds.rb2
-rw-r--r--Library/Homebrew/utils.rb18
2 files changed, 19 insertions, 1 deletions
diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb
index 7594bd87f..19a2372d7 100644
--- a/Library/Homebrew/test/test_integration_cmds.rb
+++ b/Library/Homebrew/test/test_integration_cmds.rb
@@ -40,7 +40,7 @@ class IntegrationCommandTests < Homebrew::TestCase
end
def test_version
- assert_equal HOMEBREW_VERSION.to_s,
+ assert_match HOMEBREW_VERSION.to_s,
cmd("--version")
end
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 1390db14e..63cdaadfa 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -147,10 +147,28 @@ module Homebrew
HOMEBREW_REPOSITORY.cd { `git rev-parse --verify -q HEAD 2>/dev/null`.chuzzle }
end
+ def self.git_short_head
+ HOMEBREW_REPOSITORY.cd { `git rev-parse --short=4 --verify -q HEAD 2>/dev/null`.chuzzle }
+ end
+
def self.git_last_commit
HOMEBREW_REPOSITORY.cd { `git show -s --format="%cr" HEAD 2>/dev/null`.chuzzle }
end
+ def self.git_last_commit_date
+ HOMEBREW_REPOSITORY.cd { `git show -s --format="%cd" --date=short HEAD 2>/dev/null`.chuzzle }
+ end
+
+ def self.homebrew_version_string
+ pretty_revision = git_short_head
+ if pretty_revision
+ last_commit = git_last_commit_date
+ "#{HOMEBREW_VERSION} (git revision #{pretty_revision}; last commit #{last_commit})"
+ else
+ "#{HOMEBREW_VERSION} (no git repository)"
+ end
+ end
+
def self.install_gem_setup_path!(gem, version = nil, executable = gem)
require "rubygems"
ENV["PATH"] = "#{Gem.user_dir}/bin:#{ENV["PATH"]}"