Class: Itamae::Resource::Git
Constant Summary collapse
- DEPLOY_BRANCH =
"deploy"
Instance Attribute Summary
Attributes inherited from Base
#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated
Instance Method Summary collapse
Methods inherited from Base
#action_nothing, define_attribute, inherited, #initialize, #resource_type, #run
Constructor Details
This class inherits a constructor from Itamae::Resource::Base
Instance Method Details
#action_sync(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/itamae/resource/git.rb', line 25 def action_sync() ensure_git_available new_repository = false if run_specinfra(:check_file_is_directory, attributes.destination) run_command_in_repo(['git', 'fetch', 'origin']) else cmd = ['git', 'clone'] cmd << '--recursive' if attributes.recursive cmd << attributes.repository << attributes.destination run_command(cmd) new_repository = true end target = if attributes.revision get_revision(attributes.revision) else run_command_in_repo("git ls-remote origin HEAD | cut -f1").stdout.strip end if new_repository || target != get_revision('HEAD') updated! deploy_old_created = false if current_branch == DEPLOY_BRANCH run_command_in_repo("git branch -m deploy-old") deploy_old_created = true end run_command_in_repo(["git", "checkout", target, "-b", DEPLOY_BRANCH]) if deploy_old_created run_command_in_repo("git branch -d deploy-old") end end end |
#pre_action ⇒ Object
14 15 16 17 18 19 |
# File 'lib/itamae/resource/git.rb', line 14 def pre_action case @current_action when :sync attributes.exist = true end end |
#set_current_attributes ⇒ Object
21 22 23 |
# File 'lib/itamae/resource/git.rb', line 21 def set_current_attributes current.exist = run_specinfra(:check_file_is_directory, attributes.destination) end |