class Git::Branch

Attributes

name[RW]
remote[RW]

Public Class Methods

all() click to toggle source
# File lib/Git/Branch.rb, line 77
def all
  result = branch_output.split("\n").collect do |branch|
    if @switches.include?('--remote')
      branch_parts = branch.split('/')
      remote, branch_name = branch_parts.first.sub('*', '').strip, branch_parts.all_but_first.join('/')
      new(branch_name, remote: remote)
    else
      branch_name = branch.sub('*', '').strip
      new(branch_name)
    end
  end
  result
end
branch_output() click to toggle source
# File lib/Git/Branch.rb, line 73
def branch_output
  `#{command_string}`
end
command_string() click to toggle source
# File lib/Git/Branch.rb, line 67
def command_string
  command_string = ['git branch', @switches.join(' ')].join(' ').strip
  @switches = []
  command_string
end
current() click to toggle source
# File lib/Git/Branch.rb, line 91
def current
  branch_name = branch_output.split("\n").detect{|branch| branch =~ /\*/}.sub('*', '').strip
  new(branch_name)
end
Also aliased as: head
default() click to toggle source
# File lib/Git/Branch.rb, line 97
def default
  `git rev-parse --abbrev-ref origin/HEAD`.strip.split('/').last
end
head()
Alias for: current
local() click to toggle source
# File lib/Git/Branch.rb, line 53
def local
  self
end
merged() click to toggle source
# File lib/Git/Branch.rb, line 62
def merged
  @switches << '--merged'
  self
end
new(name = nil, **args) click to toggle source
# File lib/Git/Branch.rb, line 106
def initialize(name = nil, **args)
  @name = name
  @remote = args[:remote]
end
remote() click to toggle source
# File lib/Git/Branch.rb, line 57
def remote
  @switches << '--remote'
  self
end

Public Instance Methods

merged?() click to toggle source
# File lib/Git/Branch.rb, line 111
def merged?
  if @remote
    self.class.remote.merged.all.collect{|branch| branch.name}.include?(@remote + '/' + @name)
  else
    self.class.merged.all.collect{|branch| branch.name}.include?(@name)
  end
end
method_missing(method_name, *args, &block) click to toggle source
# File lib/Git/Branch.rb, line 127
def method_missing(method_name, *args, &block)
  if method_name.to_s =~ /\?$/ && !self.class.instance_methods.include?(method_name)
    @name == method_name.to_s.sub('?', '')
  end
end
to_s() click to toggle source
# File lib/Git/Branch.rb, line 119
def to_s
  if @remote
    @remote + '/' + @name
  else
    @name
  end
end