Class: Takeoff::Stage::CheckoutDevelopmentBranch

Inherits:
Base
  • Object
show all
Defined in:
lib/takeoff/stage/checkout_development_branch.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Helpers

#branches_up_to_date?, #diff, #execute, #file_has_changed_locally?, #files_have_changed?, #latest_commit, #log

Constructor Details

This class inherits a constructor from Takeoff::Stage::Base

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/takeoff/stage/checkout_development_branch.rb', line 6

def call(env)
  previous_branch = `git rev-parse --abbrev-ref HEAD`.strip
  previous_branch = `git rev-parse --verify HEAD`.strip if previous_branch == "HEAD"

  return @app.call(env) if previous_branch == env[:development_branch]

  log     "Checking out development branch"
  execute "git checkout #{env[:development_branch]}"

  begin
    @app.call(env)
  ensure
    log     "Checking out original branch '#{previous_branch}'"
    execute "git checkout #{previous_branch}"
  end
end