diff options
author | The Bundler Bot <bot@bundler.io> | 2018-08-22 12:42:27 +0000 |
---|---|---|
committer | Colby Swandale <me@colby.fyi> | 2018-09-14 22:26:18 +1000 |
commit | 2c5212fc70d38e5a01ed1114656bd014d02eafa9 (patch) | |
tree | 840dfec30ccc36c92dcd53d684c4484e05615adb | |
parent | a356d8cf94342542cf63a6d8827baa2c0a53711f (diff) | |
download | bundler-2c5212fc70d38e5a01ed1114656bd014d02eafa9.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.
(cherry picked from commit e5e260e0433e78bbc4961a6655cd96131dc9a45c)
-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 |