Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #6737
Browse files Browse the repository at this point in the history
6737: when running from source, find submodule shas too r=indirect a=indirect

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.

Co-authored-by: Andre Arko <andre@arko.net>
  • Loading branch information
bundlerbot and indirect committed Oct 20, 2018
2 parents 74f142b + 9849d56 commit 964aaae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/bundler/build_metadata.rb
Expand Up @@ -28,14 +28,19 @@ def self.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")
# 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)
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.
Expand Down

0 comments on commit 964aaae

Please sign in to comment.