class Gitx::Cli::IntegrateCommand
Public Instance Methods
integrate(integration_branch = 'staging')
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 14 def integrate(integration_branch = 'staging') assert_aggregate_branch!(integration_branch) branch = feature_branch_name print_message(branch, integration_branch) run_git_cmd 'update' pull_request = pull_request_for_branch(branch) unless options[:'skip-pull-request'] integrate_branch(branch, integration_branch, pull_request) unless options[:resume] checkout_branch branch end
Private Instance Methods
commit_message(branch, integration_branch, pull_request)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 52 def commit_message(branch, integration_branch, pull_request) commit_message = "[gitx] Integrate #{branch} into #{integration_branch}" commit_message += "\n\nConnected to ##{pull_request.number}" if pull_request commit_message end
create_remote_branch(target_branch)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 86 def create_remote_branch(target_branch) repo.create_branch(target_branch, config.base_branch) run_git_cmd 'push', 'origin', "#{target_branch}:#{target_branch}" end
feature_branch_name()
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 58 def feature_branch_name @feature_branch_name ||= begin feature_branch = options[:resume] || current_branch.name feature_branch = ask("#{feature_branch} does not exist. Please select one of the available local branches: #{local_branches}") until local_branch_exists?(feature_branch) feature_branch end end
fetch_remote_branch(target_branch)
click to toggle source
nuke local branch and pull fresh version from remote repo
# File lib/gitx/cli/integrate_command.rb, line 67 def fetch_remote_branch(target_branch) create_remote_branch(target_branch) unless remote_branch_exists?(target_branch) run_git_cmd 'fetch', 'origin' run_git_cmd('branch', '--delete', '--force', target_branch) rescue Gitx::Executor::ExecutionError checkout_branch target_branch end
integrate_branch(branch, integration_branch, pull_request)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 42 def integrate_branch(branch, integration_branch, pull_request) fetch_remote_branch(integration_branch) begin run_git_cmd 'merge', '--no-ff', '--message', commit_message(branch, integration_branch, pull_request), branch rescue Gitx::Executor::ExecutionError raise MergeError, "Merge conflict occurred. Please fix merge conflict and rerun command with --resume #{branch} flag" end run_git_cmd 'push', 'origin', 'HEAD' end
local_branch_exists?(branch)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 74 def local_branch_exists?(branch) local_branches.include?(branch) end
local_branches()
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 78 def local_branches @local_branches ||= repo.branches.each_name(:local) end
print_message(branch, integration_branch)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 28 def print_message(branch, integration_branch) message = options[:resume] ? 'Resuming integration of' : 'Integrating' say "#{message} " say "#{branch} ", :green say 'into ' say integration_branch, :green end
pull_request_for_branch(branch)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 36 def pull_request_for_branch(branch) return nil if config.reserved_branch?(branch) find_or_create_pull_request(branch) end
remote_branch_exists?(target_branch)
click to toggle source
# File lib/gitx/cli/integrate_command.rb, line 82 def remote_branch_exists?(target_branch) repo.branches.each_name(:remote).include?("origin/#{target_branch}") end