summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2011-09-18 19:06:03 -0700
committerAndre Arko <andre@arko.net>2011-09-18 19:06:03 -0700
commit5d75b3f5dae92b22dded76f842cff1767e08159c (patch)
tree928aa12f140fb0de26bacf0fb20f7c93b6b80d34
parent3920fef3fbcefad7b74f310c470468f6195d3eb0 (diff)
downloadbundler-5d75b3f5dae92b22dded76f842cff1767e08159c.tar.gz
Revert "Merge pull request #1213 from tigris/bundler"
This reverts commit 45c4529daf2a2e807638fb167f2b6424590eb121, reversing changes made to d9dd6edda2e34e9461f0be6e00006cfa3b2f52fc.
-rw-r--r--lib/bundler/source.rb39
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index a3bce5c6f5..139964061b 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -615,16 +615,16 @@ module Bundler
Digest::SHA1.hexdigest(input)
end
- # Escape an argument for shell commands.
- def escape(arg)
+ # Escape the URI for git commands
+ def uri_escaped
if Bundler::WINDOWS
# Windows quoting requires double quotes only, with double quotes
# inside the string escaped by being doubled.
- '"' + arg.to_s.gsub('"') {|s| '""'} + '"'
+ '"' + uri.gsub('"') {|s| '""'} + '"'
else
# Bash requires single quoted strings, with the single quotes escaped
# by ending the string, escaping the quote, and restarting the string.
- "'" + arg.to_s.gsub("'") {|s| "'\\''"} + "'"
+ "'" + uri.gsub("'") {|s| "'\\''"} + "'"
end
end
@@ -644,12 +644,13 @@ module Bundler
if cached?
return if has_revision_cached?
Bundler.ui.info "Updating #{uri}"
- cache unless cached?
- git %|--git-dir #{escape cache_path} fetch --force --quiet --tags #{escape uri} "refs/heads/*:refs/heads/*"|
+ in_cache do
+ git %|fetch --force --quiet --tags #{uri_escaped} "refs/heads/*:refs/heads/*"|
+ end
else
Bundler.ui.info "Fetching #{uri}"
FileUtils.mkdir_p(cache_path.dirname)
- git %|clone #{escape uri} "#{cache_path}" --bare --no-hardlinks|
+ git %|clone #{uri_escaped} "#{cache_path}" --bare --no-hardlinks|
end
end
@@ -660,20 +661,20 @@ module Bundler
git %|clone --no-checkout "#{cache_path}" "#{path}"|
File.chmod((0777 & ~File.umask), path)
end
- dir_opts = %|--git-dir #{escape path}/.git --work-tree #{escape path}|
- git %|#{dir_opts} fetch --force --quiet --tags "#{cache_path}"|
- git "#{dir_opts} reset --hard #{revision}"
+ Dir.chdir(path) do
+ git %|fetch --force --quiet --tags "#{cache_path}"|
+ git "reset --hard #{revision}"
- if @submodules
- git "#{dir_opts} submodule init"
- git "#{dir_opts} submodule update"
+ if @submodules
+ git "submodule init"
+ git "submodule update"
+ end
end
end
def has_revision_cached?
return unless @revision
- cache unless cached?
- git %|--git-dir #{escape cache_path} cat-file -e #{@revision}|
+ in_cache { git %|cat-file -e #{@revision}| }
true
rescue GitError
false
@@ -686,8 +687,7 @@ module Bundler
def revision
@revision ||= begin
if allow_git_ops?
- cache unless cached?
- git("--git-dir #{escape cache_path} rev-parse #{ref}").strip
+ in_cache { git("rev-parse #{ref}").strip }
else
raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
end
@@ -697,6 +697,11 @@ module Bundler
def cached?
cache_path.exist?
end
+
+ def in_cache(&blk)
+ cache unless cached?
+ Dir.chdir(cache_path, &blk)
+ end
end
end