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
24 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 |
# File 'lib/itamae/resource/git.rb', line 24 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 run_command(['git', 'clone', attributes.repository, attributes.destination]) 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
13 14 15 16 17 18 |
# File 'lib/itamae/resource/git.rb', line 13 def pre_action case @current_action when :sync attributes.exist = true end end |
#set_current_attributes ⇒ Object
20 21 22 |
# File 'lib/itamae/resource/git.rb', line 20 def set_current_attributes current.exist = run_specinfra(:check_file_is_directory, attributes.destination) end |