Class: Yard::GHPages::BranchMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/yard-ghpages/branch_merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) {|_self| ... } ⇒ BranchMerger

Returns a new instance of BranchMerger.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
# File 'lib/yard-ghpages/branch_merger.rb', line 8

def initialize(opts = {}, &block)
  opts.each { |k, v| self.send("#{k.to_s}=", v) }
  yield(self) if block_given?
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



7
8
9
# File 'lib/yard-ghpages/branch_merger.rb', line 7

def destination
  @destination
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/yard-ghpages/branch_merger.rb', line 7

def message
  @message
end

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/yard-ghpages/branch_merger.rb', line 7

def source
  @source
end

Instance Method Details

#mergeObject

Raises:

  • (Exception)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yard-ghpages/branch_merger.rb', line 13

def merge
  git.reset
  source_tree = sha source[:branch], source[:directory]
  raise Exception.new("Could not find source #{source}") unless source_tree

  dest_commit = head_commit(destination[:branch])

  commit = git.commit_tree(source_tree, message: message, parents: dest_commit || nil )
  git.update_ref(ref_head(destination[:branch]), commit)
  self
end

#pushObject



25
26
27
28
# File 'lib/yard-ghpages/branch_merger.rb', line 25

def push
  git.push('origin', destination[:branch])
  self
end