summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Shay <xavier@rhnh.net>2013-08-10 17:50:44 -0700
committerXavier Shay <xavier@rhnh.net>2013-08-18 14:31:10 -0700
commitd8437838ca48b6204dffb5b9f302a37ef5026ac5 (patch)
treef55a598ceb1fa173a34e4d25e1dff09009d3d90a
parent12eee6adc99fac9074c223e52c643ee59932dedf (diff)
downloadbundler-d8437838ca48b6204dffb5b9f302a37ef5026ac5.tar.gz
Ignore git path configuration in env when shelling out to git.
-rw-r--r--lib/bundler/shared_helpers.rb13
-rw-r--r--lib/bundler/source/git/git_proxy.rb2
-rw-r--r--spec/install/git_spec.rb22
-rw-r--r--spec/support/builders.rb6
4 files changed, 41 insertions, 2 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 14e76a6cdb..7e53518669 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -57,6 +57,19 @@ module Bundler
end
end
+ def with_clean_git_env(&block)
+ keys = %w[GIT_DIR GIT_WORK_TREE]
+ old_env = keys.inject({}) do |h, k|
+ h.update(k => ENV[k])
+ end
+
+ keys.each {|key| ENV.delete(key) }
+
+ block.call
+ ensure
+ keys.each {|key| ENV[key] = old_env[key] }
+ end
+
private
def find_gemfile
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index 800439a0fb..19e297fcc2 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -85,7 +85,7 @@ module Bundler
def git(command, check_errors=true)
if allow?
- out = %x{git #{command}}
+ out = SharedHelpers.with_clean_git_env { %x{git #{command}} }
if check_errors && $?.exitstatus != 0
msg = "Git error: command `git #{command}` in directory #{Dir.pwd} has failed."
diff --git a/spec/install/git_spec.rb b/spec/install/git_spec.rb
index ae9e5a145b..5c537beccd 100644
--- a/spec/install/git_spec.rb
+++ b/spec/install/git_spec.rb
@@ -875,4 +875,26 @@ describe "bundle install with git sources" do
end
end
+ it 'ignores git environment variables' do
+ build_git "xxxxxx" do |s|
+ s.executables = "xxxxxxbar"
+ end
+
+ Bundler::SharedHelpers.with_clean_git_env do
+ ENV['GIT_DIR'] = 'bar'
+ ENV['GIT_WORK_TREE'] = 'bar'
+
+ result = install_gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ git "#{lib_path('xxxxxx-1.0')}" do
+ gem 'xxxxxx'
+ end
+ G
+
+ expect(exitstatus).to eq(0)
+ expect(ENV['GIT_DIR']).to eq('bar')
+ expect(ENV['GIT_WORK_TREE']).to eq('bar')
+ end
+ end
+
end
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index 856f0479cc..05c09a0b44 100644
--- a/spec/support/builders.rb
+++ b/spec/support/builders.rb
@@ -1,3 +1,5 @@
+require 'bundler/shared_helpers'
+
module Spec
module Builders
def self.constantize(name)
@@ -588,7 +590,9 @@ module Spec
private
def git(cmd)
- Dir.chdir(@path) { `git #{cmd}`.strip }
+ Bundler::SharedHelpers.with_clean_git_env do
+ Dir.chdir(@path) { `git #{cmd}`.strip }
+ end
end
end