Class: MxxRu::Externals::Git

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Impl::ExternalBasics, Impl::OptionsHolder
Defined in:
lib/mxx_ru/externals.rb

Instance Attribute Summary collapse

Attributes included from Impl::ExternalBasics

#name, #paths, #url

Instance Method Summary collapse

Methods included from Impl::OptionsHolder

#option

Methods included from Impl::ExternalBasics

#map, #map_dir, #map_file

Constructor Details

#initialize(name) {|_self| ... } ⇒ Git

Returns a new instance of Git.

Yields:

  • (_self)

Yield Parameters:



511
512
513
514
515
516
517
518
519
520
521
# File 'lib/mxx_ru/externals.rb', line 511

def initialize(name)
  defaults(name)
  @unlimited_depth = false
  @recursive = false

  yield self if block_given?

  raise "#{name}: tag and commit cannot be specified together" if @tag and @commit

  Registry::handle_external(@name, self)
end

Instance Attribute Details

#commit(v) ⇒ Object (readonly) Also known as: commit=

Returns the value of attribute commit.



535
536
537
# File 'lib/mxx_ru/externals.rb', line 535

def commit
  @commit
end

#tag(v) ⇒ Object (readonly) Also known as: tag=

Returns the value of attribute tag.



523
524
525
# File 'lib/mxx_ru/externals.rb', line 523

def tag
  @tag
end

Instance Method Details

#define_rules(old_or_new) ⇒ Object



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/mxx_ru/externals.rb', line 548

def define_rules(old_or_new)
  define(old_or_new) do |tmp_dir|
    if @commit.nil?
      # No specific commit.
      # Simple clone (probably with --depth 1) is enough.
      sh_args = ['git', 'clone']

      sh_args << '--branch' << @tag.to_s if @tag
      sh_args << '--depth' << '1' unless @unlimited_depth
      sh_args << '--recursive' if @recursive
      push_options_to(sh_args)

      sh_args << @url << tmp_dir

      sh *sh_args
    else
      # To extract specific commit is necessary to do
      # at least two commands: clone (without limitiation of depth) and
      # checkout for specific commit.

      # Do `clone repo tmp_dir` 
      sh *(push_options_to(['git', 'clone']).push(@url).push(tmp_dir))
      # Do `checkout commit` inside tmp_dir
      cd tmp_dir do
        sh 'git', 'checkout', @commit
      end
    end
  end
end

#make_hashObject



539
540
541
542
543
544
545
546
# File 'lib/mxx_ru/externals.rb', line 539

def make_hash
  options_to_map.merge!( basics_to_map ).merge!(
    { :recursive => @recursive,
      :unlimited_depth => @unlimited_depth,
      :tag => @tag,
      :commit => @commit
    } )
end

#recursiveObject



531
532
533
# File 'lib/mxx_ru/externals.rb', line 531

def recursive
  @recursive = true
end

#unlimited_depthObject



527
528
529
# File 'lib/mxx_ru/externals.rb', line 527

def unlimited_depth
  @unlimited_depth = true
end