diff options
author | Grey Baker <greysteil@gmail.com> | 2018-08-15 10:27:17 +0100 |
---|---|---|
committer | Grey Baker <greysteil@gmail.com> | 2018-08-16 12:05:09 +0100 |
commit | bdc6d649c6ea0198f59b61f2dffe89311c61f88f (patch) | |
tree | a74077a49a2dbe49bd56b5f7110ac0ae53fdac6e | |
parent | fc60fe4362a23254602fd4082a8d63ec5daf8106 (diff) | |
download | bundler-bdc6d649c6ea0198f59b61f2dffe89311c61f88f.tar.gz |
Avoid printing git error when checking version on badly packaged version
-rw-r--r-- | lib/bundler/build_metadata.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index 54436f982d..a0428f0319 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -23,7 +23,15 @@ module Bundler # The SHA for the git commit the bundler gem was built from. def self.git_commit_sha - @git_commit_sha ||= Dir.chdir(File.expand_path("..", __FILE__)) do + return @git_commit_sha if @git_commit_sha + + # 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) + + # Otherwise shell out to git. + @git_commit_sha = Dir.chdir(File.expand_path("..", __FILE__)) do `git rev-parse --short HEAD`.strip.freeze end end |