diff options
author | Andre Arko <andre@arko.net> | 2018-10-11 23:56:05 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2018-10-12 00:03:21 -0700 |
commit | 4184438e4a3e156786b376f1b733ad154de8003d (patch) | |
tree | 21270122b245e033d34ae24ed2f895fe26e3a1ac | |
parent | 27e88538960817a64a510f840c810654f1a7fa3e (diff) | |
download | bundler-indirect/bundler-submodule-shas.tar.gz |
when running from source, find submodule shas tooindirect/bundler-submodule-shas
We recently merged #6664 to prevent Bundler from (wrongly) claiming the
git commit of any parent directory when it is run from source. However,
Bundler is also run from source as a submodule in RubyGems, and in that
case it does not have its own git directory.
This commit resolves the failure in version_spec.rb that only appears
when the Bundler tests are run from a submodule, by explicitly checking
for that submodule, and using `git ls-tree` to get the sha if so.
Arguably, this is a bugfix compared to the previous behavior, which
would blindly print the current sha from the _RubyGems_ repo, while
claiming that it was the sha of Bundler.
-rw-r--r-- | lib/bundler/build_metadata.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index c9d7482b24..d45796d71d 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -28,14 +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") - # Check for both a file or folder because RubyGems runs Bundler's test suite in a submodule - # which does not have a .git folder - return "unknown" unless File.exist?(git_dir) + if File.directory?(git_dir) + @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) + @git_commit_sha = Dir.chdir(git_sub_dir) do + `git ls-tree --abbrev=8 HEAD bundler | awk '{ print $3 }'`.strip.freeze + end end + + @git_commit_sha ||= "unknown" end # Whether this is an official release build of Bundler. |