class Bundler::GitSource

def checkout

def checkout
  Dir.chdir(location) { `git checkout --quiet #{@ref}` }
end

def clone

def clone
  # Raise an error if the source should run in local mode,
  # but it has not been cached yet.
  if local
    raise SourceNotCached, "Git repository '#{@uri}' has not been cloned yet"
  end
  Bundler.logger.info "Cloning git repository at: #{@uri}"
  FileUtils.mkdir_p(location.dirname)
  `git clone #{@uri} #{location} --no-hardlinks`
end

def download(spec)

def download(spec)
  # Nothing needed here
end

def fetch

def fetch
  unless local
    Bundler.logger.info "Fetching git repository at: #{@uri}"
    Dir.chdir(location) { `git fetch origin` }
  end
end

def gems

def gems
  update
  checkout
  super
end

def initialize(bundle, options)

def initialize(bundle, options)
  super
  @uri = options[:uri]
  @branch = options[:branch] || 'master'
  @ref = options[:ref] || "origin/#{@branch}"
end

def location

def location
  # TMP HAX to get the *.gemspec reading to work
  bundle.gem_path.join('dirs', File.basename(@uri, '.git'))
end

def to_s

def to_s
  "git: #{uri}"
end

def update

def update
  if location.directory?
    fetch
  else
    clone
  end
end