# File lib/bundler/source.rb, line 498 498: def self.from_lock(options) 499: new(options.merge("uri" => options.delete("remote"))) 500: end
# File lib/bundler/source.rb, line 484 484: def initialize(options) 485: super 486: 487: # stringify options that could be set as symbols 488: %(ref branch tag revision).each{|k| options[k] = options[k].to_s if options[k] } 489: 490: @uri = options["uri"] 491: @ref = options["ref"] || options["branch"] || options["tag"] || 'master' 492: @revision = options["revision"] 493: @submodules = options["submodules"] 494: @update = false 495: @installed = nil 496: end
# File lib/bundler/source.rb, line 577 577: def cache_path 578: @cache_path ||= begin 579: git_scope = "#{base_name}-#{uri_hash}" 580: 581: if Bundler.requires_sudo? 582: Bundler.user_bundle_path.join("cache/git", git_scope) 583: else 584: Bundler.cache.join("git", git_scope) 585: end 586: end 587: end
# File lib/bundler/source.rb, line 513 513: def eql?(o) 514: Git === o && 515: uri == o.uri && 516: ref == o.ref && 517: name == o.name && 518: version == o.version && 519: submodules == o.submodules 520: end
# File lib/bundler/source.rb, line 560 560: def install(spec) 561: Bundler.ui.info "Using #{spec.name} (#{spec.version}) from #{to_s} " 562: 563: unless @installed 564: Bundler.ui.debug " * Checking out revision: #{ref}" 565: checkout if allow_git_ops? 566: @installed = true 567: end 568: generate_bin(spec) 569: end
# File lib/bundler/source.rb, line 571 571: def load_spec_files 572: super 573: rescue PathError, GitError 574: raise GitError, "#{to_s} is not checked out. Please run `bundle install`" 575: end
# File lib/bundler/source.rb, line 529 529: def name 530: File.basename(@uri, '.git') 531: end
# File lib/bundler/source.rb, line 533 533: def path 534: @install_path ||= begin 535: git_scope = "#{base_name}-#{shortref_for_path(revision)}" 536: 537: if Bundler.requires_sudo? 538: Bundler.user_bundle_path.join(Bundler.ruby_scope).join(git_scope) 539: else 540: Bundler.install_path.join(git_scope) 541: end 542: end 543: end
TODO: actually cache git specs
# File lib/bundler/source.rb, line 550 550: def specs(*) 551: if allow_git_ops? && !@update 552: # Start by making sure the git cache is up to date 553: cache 554: checkout 555: @update = true 556: end 557: local_specs 558: end
# File lib/bundler/source.rb, line 502 502: def to_lock 503: out = "GIT\n" 504: out << " remote: #{@uri}\n" 505: out << " revision: #{revision}\n" 506: %(ref branch tag submodules).each do |opt| 507: out << " #{opt}: #{options[opt]}\n" if options[opt] 508: end 509: out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB 510: out << " specs:\n" 511: end
# File lib/bundler/source.rb, line 684 684: def allow_git_ops? 685: @allow_remote || @allow_cached 686: end
# File lib/bundler/source.rb, line 607 607: def base_name 608: File.basename(uri.sub(%{^(\w+://)?([^/:]+:)?(//\w*/)?(\w*/)*},''),".git") 609: end
# File lib/bundler/source.rb, line 644 644: def cache 645: if cached? 646: return if has_revision_cached? 647: Bundler.ui.info "Updating #{uri}" 648: in_cache do 649: git %fetch --force --quiet --tags #{uri_escaped} "refs/heads/*:refs/heads/*"| 650: end 651: else 652: Bundler.ui.info "Fetching #{uri}" 653: FileUtils.mkdir_p(cache_path.dirname) 654: git %clone #{uri_escaped} "#{cache_path}" --bare --no-hardlinks| 655: end 656: end
# File lib/bundler/source.rb, line 698 698: def cached? 699: cache_path.exist? 700: end
# File lib/bundler/source.rb, line 658 658: def checkout 659: unless File.exist?(path.join(".git")) 660: FileUtils.mkdir_p(path.dirname) 661: FileUtils.rm_rf(path) 662: git %clone --no-checkout "#{cache_path}" "#{path}"| 663: File.chmod((0777 & ~File.umask), path) 664: end 665: Dir.chdir(path) do 666: git %fetch --force --quiet --tags "#{cache_path}"| 667: git "reset --hard #{revision}" 668: 669: if @submodules 670: git "submodule init" 671: git "submodule update" 672: end 673: end 674: end
# File lib/bundler/source.rb, line 590 590: def git(command) 591: if allow_git_ops? 592: out = %{git #{command}} 593: 594: if $?.exitstatus != 0 595: msg = "Git error: command `git #{command}` in directory #{Dir.pwd} has failed." 596: msg << "\nIf this error persists you could try removing the cache directory '#{cache_path}'" if cached? 597: raise GitError, msg 598: end 599: out 600: else 601: raise GitError, "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, " "this error message could probably be more useful. Please submit a ticket at http://github.com/carlhuda/bundler/issues " "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}" 602: end 603: end
# File lib/bundler/source.rb, line 676 676: def has_revision_cached? 677: return unless @revision 678: in_cache { git %cat-file -e #{@revision}| } 679: true 680: rescue GitError 681: false 682: end
# File lib/bundler/source.rb, line 702 702: def in_cache(&blk) 703: cache unless cached? 704: Dir.chdir(cache_path, &blk) 705: end
# File lib/bundler/source.rb, line 688 688: def revision 689: @revision ||= begin 690: if allow_git_ops? 691: in_cache { git("rev-parse #{ref}").strip } 692: else 693: raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application" 694: end 695: end 696: end
# File lib/bundler/source.rb, line 611 611: def shortref_for_display(ref) 612: ref[0..6] 613: end
# File lib/bundler/source.rb, line 615 615: def shortref_for_path(ref) 616: ref[0..11] 617: end
Escape the URI for git commands
# File lib/bundler/source.rb, line 632 632: def uri_escaped 633: if Bundler::WINDOWS 634: # Windows quoting requires double quotes only, with double quotes 635: # inside the string escaped by being doubled. 636: '"' + uri.gsub('"') {|s| '""'} + '"' 637: else 638: # Bash requires single quoted strings, with the single quotes escaped 639: # by ending the string, escaping the quote, and restarting the string. 640: "'" + uri.gsub("'") {|s| "'\\''"} + "'" 641: end 642: end
# File lib/bundler/source.rb, line 619 619: def uri_hash 620: if uri =~ %{^\w+://(\w+@)?} 621: # Downcase the domain component of the URI 622: # and strip off a trailing slash, if one is present 623: input = URI.parse(uri).normalize.to_s.sub(%{/$},'') 624: else 625: # If there is no URI scheme, assume it is an ssh/git URI 626: input = uri 627: end 628: Digest::SHA1.hexdigest(input) 629: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.