Class: Git::Base
- Inherits:
-
Object
- Object
- Git::Base
- 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
-
#find_remote_for_local_branch(branch) ⇒ Object
Shortcut to create a remote for a particular branch, if the branch has an upstream.
-
#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.
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.
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 |