class GitProc::GitBranch

A Git Branch

@attr_reader [String] name the name of the branch

Attributes

name[R]

Public Class Methods

new(name, current, lib) click to toggle source

@param [String] name the name of the branch; if it starts with “remotes/” that part is stripped

and {#remote?} will return {true}

@param [Boolean] current is this the current branch? @param [GitLib] lib the {GitLib} to use for operations

@todo instead of passing in current, detect it dynamically (e.g., look at HEAD)

# File lib/git-process/git_branch.rb, line 32
def initialize(name, current, lib)
  if /^remotes\// =~ name
    @name = name[8..-1]
    @remote = true
  else
    @name = name
    @remote = false
  end
  @current = current
  @lib = lib
end

Public Instance Methods

<=>(other) click to toggle source

Implements {Comparable} based on the branch name

@param [String, name] other the item to compare to this; if a {String} then it is compared to self.name,

otherwise the names are compared

@return [int, nil] -1, 0, 1 or nil per {Object#<=>}

# File lib/git-process/git_branch.rb, line 87
def <=>(other)
  if other.nil?
    return nil
  elsif other.is_a? String
    return self.name <=> other
  elsif other.respond_to? :name
    return self.name <=> other.name
  else
    return nil
  end
end
checkout_to_new(new_branch, opts = {}) click to toggle source
# File lib/git-process/git_branch.rb, line 138
def checkout_to_new(new_branch, opts = {})
  @lib.checkout(new_branch, :new_branch => @name, :no_track => opts[:no_track])
end
contains_all_of(branch_name) click to toggle source
# File lib/git-process/git_branch.rb, line 133
def contains_all_of(branch_name)
  @lib.rev_list(@name, branch_name, :oneline => true, :num_revs => 1) == ''
end
current?() click to toggle source

@return [Boolean] is this the current branch?

# File lib/git-process/git_branch.rb, line 46
def current?
  @current
end
delete!(force = false) click to toggle source

Delete this branch

@param [Boolean] force should this force removal even if the branch has not been fully merged?

@return [String] the output of running the git command

# File lib/git-process/git_branch.rb, line 114
def delete!(force = false)
  if local?
    @lib.branch(@name, :force => force, :delete => true)
  else
    @lib.push(Process.server_name, nil, nil, :delete => @name)
  end
end
is_ahead_of(base_branch_name) click to toggle source

@param [String] base_branch_name the branch to compare to @return [Boolean] does this branch contain every commit in base_branch_name as well as at least one more?

# File lib/git-process/git_branch.rb, line 102
def is_ahead_of(base_branch_name)
  contains_all_of(base_branch_name) and
      (@lib.rev_list(base_branch_name, @name, :oneline => true, :num_revs => 1) != '')
end
local?() click to toggle source

@return [Boolean] does this represent a local branch?

# File lib/git-process/git_branch.rb, line 58
def local?
  !@remote
end
logger() click to toggle source

@return [GitLogger] the logger to use

# File lib/git-process/git_branch.rb, line 70
def logger
  @lib.logger
end
remote?() click to toggle source

@return [Boolean] does this represent a remote branch?

# File lib/git-process/git_branch.rb, line 52
def remote?
  @remote
end
rename(new_name) click to toggle source
# File lib/git-process/git_branch.rb, line 123
def rename(new_name)
  @lib.branch(@name, :rename => new_name)
end
sha() click to toggle source

@return [String] the SHA-1 of the tip of this branch

# File lib/git-process/git_branch.rb, line 76
def sha
  @lib.sha(name)
end
to_s() click to toggle source

@return [String] the name of the branch

# File lib/git-process/git_branch.rb, line 64
def to_s
  name
end
upstream(upstream_name) click to toggle source
# File lib/git-process/git_branch.rb, line 128
def upstream(upstream_name)
  @lib.branch(@name, :upstream => upstream_name)
end