diff options
author | The Bundler Bot <bot@bundler.io> | 2018-08-22 12:42:27 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2018-08-22 12:42:27 +0000 |
commit | e5e260e0433e78bbc4961a6655cd96131dc9a45c (patch) | |
tree | 5aaf1c3a4d0373b1a735245a0db484421c99069d | |
parent | a5955394c64818750a0210d81d88383e47b5ec10 (diff) | |
parent | bdc6d649c6ea0198f59b61f2dffe89311c61f88f (diff) | |
download | bundler-e5e260e0433e78bbc4961a6655cd96131dc9a45c.tar.gz |
Auto merge of #6664 - greysteil:avoid-printing-git-error, r=colby-swandale
Avoid printing git error when checking version on badly packaged version
### What was the end-user problem that led to this PR?
The problem was https://github.com/bundler/bundler/issues/6453.
### What was your diagnosis of the problem?
A use had a version of Bundler packaged with Ruby 2.5.0 in RVM, but this version didn't include Bundler's git repo or any of the ivars which should have been set. As a result, Bundler was shelling out to git even though it wasn't in a git repo.
### What is your fix for the problem, implemented in this PR?
My fix is to show a nicer result in this case (just say that the SHA is unknown)
### Why did you choose this fix out of the possible options?
I chose this fix because ensuring Bundler is always packaged correctly by others isn't possible (although it seems weird and unlikely that a version without instance variables set would be used). Falling back to a cleaner error message is marginally nicer than what we currently have, and not much work.
Fixes #6453.
-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 |