class HandleBranch
Public Class Methods
new(branch)
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 3 def initialize(branch) self.branch = branch end
Public Instance Methods
perform()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 7 def perform if branch_exists_locally? checkout_local_branch && pull_from_origin else fetch_from_origin && checkout_and_track_branch end end
Private Instance Methods
branch_exists_locally?()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 16 def branch_exists_locally? return true unless `git show-ref refs/heads/#{branch}`.empty? end
checkout_and_track_branch()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 35 def checkout_and_track_branch puts "checkout and track branch..." system "git checkout --track origin/#{branch}" end
checkout_local_branch()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 20 def checkout_local_branch puts "branch already exists. Checkout..." system "git checkout #{branch}" end
fetch_from_origin()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 30 def fetch_from_origin puts "no local branch found. Fetching from origin..." system "git fetch origin" end
pull_from_origin()
click to toggle source
# File lib/git-pcheckout/handle_branch.rb, line 25 def pull_from_origin puts "pull from origin..." system "git pull origin #{branch}" end