Module: Takeoff::Helpers

Included in:
Stage::Base
Defined in:
lib/takeoff/helpers.rb

Instance Method Summary collapse

Instance Method Details

#branches_up_to_date?(a, b) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/takeoff/helpers.rb', line 38

def branches_up_to_date?(a, b)
  latest_commit(a) == latest_commit(b)
end

#diff(from, to, files, name_only: false) ⇒ Object



24
25
26
27
# File 'lib/takeoff/helpers.rb', line 24

def diff(from, to, files, name_only: false)
  files.select! { |file| File.exist?(file) }
  `git diff #{from}..#{to} -U0 #{"--name-only" if name_only} #{files.join(" ")}`
end

#execute(command) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/takeoff/helpers.rb', line 10

def execute(command)
  puts "$ #{command}"
  value = `#{command}`
  puts value

  raise unless $?.success?
  
  value
end

#file_has_changed_locally?(file) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/takeoff/helpers.rb', line 29

def file_has_changed_locally?(file)
  `git ls-files -o -m -d --exclude-standard | grep -E #{Shellwords.escape(file)}`
  $?.success?
end

#files_have_changed?(from, to, files) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/takeoff/helpers.rb', line 34

def files_have_changed?(from, to, files)
  !diff(from, to, files, name_only: true).blank?
end

#latest_commit(branch) ⇒ Object



20
21
22
# File 'lib/takeoff/helpers.rb', line 20

def latest_commit(branch)
  `git rev-parse --verify #{branch}`.strip
end

#log(message = nil) ⇒ Object



5
6
7
8
# File 'lib/takeoff/helpers.rb', line 5

def log(message = nil)
  puts
  puts "🚀  #{message}" if message
end