# File lib/bundler/source.rb, line 468
468: def self.from_lock(options)
469: new(options.merge("uri" => options.delete("remote")))
470: end
# File lib/bundler/source.rb, line 459
459: def initialize(options)
460: super
461: @uri = options["uri"]
462: @ref = options["ref"] || options["branch"] || options["tag"] || 'master'
463: @revision = options["revision"]
464: @submodules = options["submodules"]
465: @update = false
466: end
# File lib/bundler/source.rb, line 483
483: def eql?(o)
484: Git === o &&
485: uri == o.uri &&
486: ref == o.ref &&
487: name == o.name &&
488: version == o.version &&
489: submodules == o.submodules
490: end
# File lib/bundler/source.rb, line 530
530: def install(spec)
531: Bundler.ui.info "Using #{spec.name} (#{spec.version}) from #{to_s} "
532:
533: unless @installed
534: Bundler.ui.debug " * Checking out revision: #{ref}"
535: checkout if allow_git_ops?
536: @installed = true
537: end
538: generate_bin(spec)
539: end
# File lib/bundler/source.rb, line 541
541: def load_spec_files
542: super
543: rescue PathError, GitError
544: raise GitError, "#{to_s} is not checked out. Please run `bundle install`"
545: end
# File lib/bundler/source.rb, line 499
499: def name
500: File.basename(@uri, '.git')
501: end
# File lib/bundler/source.rb, line 503
503: def path
504: @install_path ||= begin
505: git_scope = "#{base_name}-#{shortref_for_path(revision)}"
506:
507: if Bundler.requires_sudo?
508: Bundler.user_bundle_path.join(Bundler.ruby_scope).join(git_scope)
509: else
510: Bundler.install_path.join(git_scope)
511: end
512: end
513: end
TODO: actually cache git specs
# File lib/bundler/source.rb, line 520
520: def specs
521: if allow_git_ops? && !@update
522: # Start by making sure the git cache is up to date
523: cache
524: checkout
525: @update = true
526: end
527: local_specs
528: end
# File lib/bundler/source.rb, line 472
472: def to_lock
473: out = "GIT\n"
474: out << " remote: #{@uri}\n"
475: out << " revision: #{revision}\n"
476: %(ref branch tag submodules).each do |opt|
477: out << " #{opt}: #{options[opt]}\n" if options[opt]
478: end
479: out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
480: out << " specs:\n"
481: end
# File lib/bundler/source.rb, line 636
636: def allow_git_ops?
637: @allow_remote || @allow_cached
638: end
# File lib/bundler/source.rb, line 564
564: def base_name
565: File.basename(uri.sub(%{^(\w+://)?([^/:]+:)},''), ".git")
566: end
# File lib/bundler/source.rb, line 600
600: def cache
601: if cached?
602: return if has_revision_cached?
603: Bundler.ui.info "Updating #{uri}"
604: in_cache { git %fetch --force --quiet "#{uri}" refs/heads/*:refs/heads/*| }
605: else
606: Bundler.ui.info "Fetching #{uri}"
607: FileUtils.mkdir_p(cache_path.dirname)
608: git %clone "#{uri}" "#{cache_path}" --bare --no-hardlinks|
609: end
610: end
# File lib/bundler/source.rb, line 588
588: def cache_path
589: @cache_path ||= begin
590: git_scope = "#{base_name}-#{uri_hash}"
591:
592: if Bundler.requires_sudo?
593: Bundler.user_bundle_path.join("cache/git", git_scope)
594: else
595: Bundler.cache.join("git", git_scope)
596: end
597: end
598: end
# File lib/bundler/source.rb, line 650
650: def cached?
651: cache_path.exist?
652: end
# File lib/bundler/source.rb, line 612
612: def checkout
613: unless File.exist?(path.join(".git"))
614: FileUtils.mkdir_p(path.dirname)
615: git %clone --no-checkout "#{cache_path}" "#{path}"|
616: end
617: Dir.chdir(path) do
618: git %fetch --force --quiet "#{cache_path}"|
619: git "reset --hard #{revision}"
620:
621: if @submodules
622: git "submodule init"
623: git "submodule update"
624: end
625: end
626: end
# File lib/bundler/source.rb, line 549
549: def git(command)
550: if allow_git_ops?
551: out = %{git #{command}}
552:
553: if $? != 0
554: raise GitError, "An error has occurred in git when running `git #{command}. Cannot complete bundling."
555: end
556: out
557: else
558: 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")}"
559: end
560: end
# File lib/bundler/source.rb, line 628
628: def has_revision_cached?
629: return unless @revision
630: in_cache { git %cat-file -e #{@revision}| }
631: true
632: rescue GitError
633: false
634: end
# File lib/bundler/source.rb, line 654
654: def in_cache(&blk)
655: cache unless cached?
656: Dir.chdir(cache_path, &blk)
657: end
# File lib/bundler/source.rb, line 640
640: def revision
641: @revision ||= begin
642: if allow_git_ops?
643: in_cache { git("rev-parse #{ref}").strip }
644: else
645: raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
646: end
647: end
648: end
# File lib/bundler/source.rb, line 568
568: def shortref_for_display(ref)
569: ref[0..6]
570: end
# File lib/bundler/source.rb, line 572
572: def shortref_for_path(ref)
573: ref[0..11]
574: end
# File lib/bundler/source.rb, line 576
576: def uri_hash
577: if uri =~ %{^\w+://(\w+@)?}
578: # Downcase the domain component of the URI
579: # and strip off a trailing slash, if one is present
580: input = URI.parse(uri).normalize.to_s.sub(%{/$},'')
581: else
582: # If there is no URI scheme, assume it is an ssh/git URI
583: input = uri
584: end
585: Digest::SHA1.hexdigest(input)
586: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.