diff options
Diffstat (limited to 'lib/bundler/build_metadata.rb')
-rw-r--r-- | lib/bundler/build_metadata.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index a0428f0319..33f91e9162 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -28,12 +28,19 @@ module Bundler # If Bundler has been installed without its .git directory and without a # commit instance variable then we can't determine its commits SHA. git_dir = File.join(File.expand_path("../../..", __FILE__), ".git") - return "unknown" unless File.directory?(git_dir) + if File.directory?(git_dir) + return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze } + end - # Otherwise shell out to git. - @git_commit_sha = Dir.chdir(File.expand_path("..", __FILE__)) do - `git rev-parse --short HEAD`.strip.freeze + # If Bundler is a submodule in RubyGems, get the submodule commit + git_sub_dir = File.join(File.expand_path("../../../..", __FILE__), ".git") + if File.directory?(git_sub_dir) + return @git_commit_sha = Dir.chdir(git_sub_dir) do + `git ls-tree --abbrev=8 HEAD bundler`.split(/\s/).fetch(2, "").strip.freeze + end end + + @git_commit_sha ||= "unknown" end # Whether this is an official release build of Bundler. |