Class: Vendorificator::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/vendorificator/segment.rb

Direct Known Subclasses

Overlay, Vendor

Defined Under Namespace

Classes: Overlay, Vendor

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Segment

Returns a new instance of Segment.



4
5
6
# File 'lib/vendorificator/segment.rb', line 4

def initialize(args = {})
  @metadata = {}
end

Instance Method Details

#fast_forward(branch) ⇒ Object



8
9
10
11
12
13
# File 'lib/vendorificator/segment.rb', line 8

def fast_forward(branch)
  in_branch do |tmpgit|
    tmpgit.checkout(:quiet => true)
    tmpgit.merge({:ff_only => true, :quiet => true}, branch)
  end
end

#headObject



102
103
104
105
106
# File 'lib/vendorificator/segment.rb', line 102

def head
  git.capturing.rev_parse({:verify => true, :quiet => true}, "refs/heads/#{branch_name}").strip
rescue MiniGit::GitError
  nil
end

#included_in_list?(module_list) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
# File 'lib/vendorificator/segment.rb', line 69

def included_in_list?(module_list)
  modpaths = module_list.map { |m| File.expand_path(m) }

  module_list.include?(name) ||
    module_list.include?("#{group}/#{name}") ||
    modpaths.include?(File.expand_path(work_dir)) ||
    module_list.include?(merged_base) ||
    module_list.include?(branch_name)
end

#merged_notesObject

Public: Get git vendor notes of the merged commit.

Returns the Hash of git vendor notes.



93
94
95
# File 'lib/vendorificator/segment.rb', line 93

def merged_notes
  Commit.new(merged_base, git).notes?
end

#merged_versionObject



97
98
99
# File 'lib/vendorificator/segment.rb', line 97

def merged_version
  merged_tag && merged_tag[(1 + tag_name_base.length)..-1]
end

#pushable_refsObject



57
58
59
# File 'lib/vendorificator/segment.rb', line 57

def pushable_refs
  created_tags.unshift("refs/heads/#{branch_name}")
end

#run!(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vendorificator/segment.rb', line 35

def run!(options = {})
  say_status :default, :module, name
  indent do
    case status

    when :up_to_date
      say_status :default, 'up to date', to_s

    when :unpulled, :unmerged
      say_status :default, 'merging', to_s, :yellow
      merge_back tagged_sha1

    when :outdated, :new
      say_status :default, 'fetching', to_s, :yellow
      update options

    else
      say_status :quiet, self.status, "I'm unsure what to do.", :red
    end
  end
end

#statusObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vendorificator/segment.rb', line 15

def status
  # If there's no branch yet, it's a completely new module
  return :new unless head

  # If there's a branch but no tag, it's a known module that's not
  # been updated for the new definition yet.
  return :outdated unless tagged_sha1

  # Well, this is awkward: branch is in config and exists, but is
  # not merged into current branch at all.
  return :unmerged unless merged?

  # Merge base is tagged with our tag. We're good.
  return :up_to_date if tagged_sha1 == merged_base

  return :unpulled if environment.fast_forwardable?(tagged_sha1, merged_base)

  return :unknown
end

#to_sObject



86
87
88
# File 'lib/vendorificator/segment.rb', line 86

def to_s
  _join name, version
end

#updatable?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/vendorificator/segment.rb', line 79

def updatable?
  return nil if self.status == :up_to_date
  return false if !head
  return false if head && merged_base == head
  git.describe({:abbrev => 0, :always => true}, branch_name)
end

#work_dir(relative = false) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/vendorificator/segment.rb', line 61

def work_dir(relative = false)
  arr = relative ? [] : [git.git_work_tree]
  arr << environment.relative_root_dir
  arr << work_subdir

  _join *arr
end