Class: GTA::Diff

Inherits:
Object
  • Object
show all
Includes:
Sh
Defined in:
lib/gta/diff.rb

Constant Summary collapse

DEFAULT_FORMAT =
'short'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sh

#commander, #sh, #sh!

Constructor Details

#initialize(source_name, destination_name, gta_config_path = nil) ⇒ Diff

Returns a new instance of Diff.



9
10
11
12
13
# File 'lib/gta/diff.rb', line 9

def initialize(source_name, destination_name, gta_config_path=nil)
  @source_name = source_name
  @destination_name = destination_name
  @gta_config_path = gta_config_path
end

Instance Attribute Details

#destination_nameObject (readonly)

Returns the value of attribute destination_name.



5
6
7
# File 'lib/gta/diff.rb', line 5

def destination_name
  @destination_name
end

#gta_config_pathObject (readonly)

Returns the value of attribute gta_config_path.



5
6
7
# File 'lib/gta/diff.rb', line 5

def gta_config_path
  @gta_config_path
end

#source_nameObject (readonly)

Returns the value of attribute source_name.



5
6
7
# File 'lib/gta/diff.rb', line 5

def source_name
  @source_name
end

Instance Method Details

#cherry_pickObject



37
38
39
40
41
42
43
# File 'lib/gta/diff.rb', line 37

def cherry_pick
  commits = shas.split("\n")
  sh("git checkout #{destination.name}")
  commits.each do |sha|
    sh("git cherry-pick #{sha}")
  end
end

#destinationObject



23
24
25
# File 'lib/gta/diff.rb', line 23

def destination
  @destination ||= manager.stage!(destination_name)
end

#managerObject



15
16
17
# File 'lib/gta/diff.rb', line 15

def manager
  @manager ||= Manager.new(gta_config_path)
end

#report(format = DEFAULT_FORMAT) ⇒ Object



27
28
29
30
31
# File 'lib/gta/diff.rb', line 27

def report(format=DEFAULT_FORMAT)
  source.fetch!
  destination.fetch!
  sh("git log #{source.name}/master..#{destination.name}/master --format=#{format}")
end

#shasObject



33
34
35
# File 'lib/gta/diff.rb', line 33

def shas
  report('%h')
end

#sourceObject



19
20
21
# File 'lib/gta/diff.rb', line 19

def source
  @source ||= manager.stage!(source_name)
end