Class: Git::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/git_pr/git.rb

Overview

Add some methods to the git class that operate a lot faster than the defaults

Instance Method Summary collapse

Instance Method Details

#find_remote_for_local_branch(branch) ⇒ Object

Shortcut to create a remote for a particular branch, if the branch has an upstream.



17
18
19
20
21
22
# File 'lib/git_pr/git.rb', line 17

def find_remote_for_local_branch(branch)
  self.chdir do
    remote_name = `git for-each-ref --format='%(upstream:short)' refs/heads/#{branch}`.strip.sub(/\/#{branch}$/, '')
    remote_name.empty? ? nil : Git::Remote.new(self, remote_name)
  end
end

#is_local_branch_fast?(branch) ⇒ Boolean

Default implementation of is_local_branch? will create O(N) Git::Branch objects for all branches, local and remote. All we care about is existence, so we don’t need all that.

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/git_pr/git.rb', line 9

def is_local_branch_fast?(branch)
  self.chdir do
    local_branches = `git branch`.split.map { |b| b.gsub('*', '').strip }
    local_branches.include? branch
  end
end