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
# File 'lib/vendorificator/segment.rb', line 8

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

#headObject



99
100
101
102
103
# File 'lib/vendorificator/segment.rb', line 99

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)


66
67
68
69
70
71
72
73
74
# File 'lib/vendorificator/segment.rb', line 66

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.



90
91
92
# File 'lib/vendorificator/segment.rb', line 90

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

#merged_versionObject



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

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

#pushable_refsObject



54
55
56
# File 'lib/vendorificator/segment.rb', line 54

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

#run!(options = {}) ⇒ Object



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

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



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

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



83
84
85
# File 'lib/vendorificator/segment.rb', line 83

def to_s
  _join name, version
end

#updatable?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/vendorificator/segment.rb', line 76

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



58
59
60
61
62
63
64
# File 'lib/vendorificator/segment.rb', line 58

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

  _join *arr
end