Class: GithubIssuesCli::Command::Checkout
- Inherits:
-
GithubIssuesCli::Command
- Object
- Clamp::Command
- GithubIssuesCli::Command
- GithubIssuesCli::Command::Checkout
- Defined in:
- lib/github_issues_cli/command/checkout.rb
Instance Attribute Summary
Attributes inherited from GithubIssuesCli::Command
Instance Method Summary collapse
Methods inherited from GithubIssuesCli::Command
#authenticate, #get_git_push_target, #get_git_repo, #get_issue_number, #get_pullrequest, #get_source_branch, #get_upstream_repo, #initialize, #run
Constructor Details
This class inherits a constructor from GithubIssuesCli::Command
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/github_issues_cli/command/checkout.rb', line 6 def execute branch_name = 'issue-' + issue_number repo = get_git_repo is_local_branch = repo.lib.branches_all.map(&:first).include? branch_name if is_local_branch repo.checkout branch_name else source = get_source_branch(issue_number) target = source if source.nil? github_repo = get_upstream_repo request = {:user => github_repo[:user], :repo => github_repo[:name], :number => issue_number} Github::Issues.new.get(request) rescue raise "Can't find issue ##{issue_number}" repo.remote('upstream').fetch source = 'upstream/master' target = 'origin/' + branch_name end repo.lib.command_proxy('checkout', ['-b', branch_name, source]) end print on_green ' ' print " Checked out ##{issue_number} " print "(#{source})" unless is_local_branch puts unless is_local_branch print on_green ' ' puts " Setting upstream to (#{target})" remote_name, branch_name = target.split('/') repo.lib.command_proxy('config', ["branch.#{branch_name}.remote", remote_name]) repo.lib.command_proxy('config', ["branch.#{branch_name}.merge", "refs/heads/#{branch_name}"]) end end |