Class: Loca::Git::BranchCreator

Inherits:
Object
  • Object
show all
Includes:
Common, Utils
Defined in:
lib/loca/git/branch_creator.rb

Instance Method Summary collapse

Methods included from Utils

non_empty_string?

Methods included from Common

#branches, #git, #git_urls_match?, #run_git_checkers

Constructor Details

#initialize(pull_num, branch_name, remote_name, remote_url) ⇒ BranchCreator

Returns a new instance of BranchCreator.



7
8
9
# File 'lib/loca/git/branch_creator.rb', line 7

def initialize(pull_num, branch_name, remote_name, remote_url)
  @pull_num, @branch_name, @remote_name, @remote_url = pull_num, branch_name, remote_name, remote_url
end

Instance Method Details

#checkoutObject



25
26
27
# File 'lib/loca/git/branch_creator.rb', line 25

def checkout
  git "checkout #{@branch_name}" # prints to stderr for some reason
end

#createObject



11
12
13
14
15
16
17
18
# File 'lib/loca/git/branch_creator.rb', line 11

def create
  run_git_checkers
  add_remote
  # To avoid fatal error: Refusing to fetch into current branch
  delete unless first_time_creating?
  fetch
  checkout
end

#fetchObject



20
21
22
23
# File 'lib/loca/git/branch_creator.rb', line 20

def fetch
  # Performs `git fetch upstream pull/PR_NUMBER/head:BRANCH_NAME`
  git "fetch #{@remote_name} pull/#{@pull_num}/head:#{@branch_name}" # shellout has stderr for some reason
end