Class: Bundler::GitSource

Inherits:
DirectorySource show all
Defined in:
lib/bundler/source.rb

Instance Attribute Summary collapse

Attributes inherited from DirectorySource

#required_specs, #specs

Attributes inherited from Source

#local, #repository

Instance Method Summary collapse

Methods inherited from DirectorySource

#==, #add_spec, #can_be_local?, #locate_gemspecs, #merge_defined_specs, #to_s, #validate_gemspec

Constructor Details

#initialize(options) ⇒ GitSource



288
289
290
291
292
293
294
# File 'lib/bundler/source.rb', line 288

def initialize(options)
  super
  @uri = options[:uri]
  @ref = options[:ref]
  @branch = options[:branch]
  @shallow = options[:shallow] ? '--depth=1' : ''
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



286
287
288
# File 'lib/bundler/source.rb', line 286

def branch
  @branch
end

#refObject (readonly)

Returns the value of attribute ref.



286
287
288
# File 'lib/bundler/source.rb', line 286

def ref
  @ref
end

#uriObject (readonly)

Returns the value of attribute uri.



286
287
288
# File 'lib/bundler/source.rb', line 286

def uri
  @uri
end

Instance Method Details

#download(spec) ⇒ Object



323
324
325
# File 'lib/bundler/source.rb', line 323

def download(spec)
  # Nothing needed here
end

#gemsObject



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/bundler/source.rb', line 301

def gems
  unless location.directory?
    # 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

    FileUtils.mkdir_p(location.dirname)

    Bundler.logger.info "Cloning git repository at: #{@uri}"
    `git clone #{@shallow} #{@uri} #{location} --no-hardlinks`

    if @ref
      Dir.chdir(location) { `git checkout --quiet #{@ref}` }
    elsif @branch && @branch != "master"
      Dir.chdir(location) { `git checkout --quiet origin/#{@branch}` }
    end
  end
  super
end

#locationObject



296
297
298
299
# File 'lib/bundler/source.rb', line 296

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