class GitTopic::Formatter::Branches

summarizes branches information

Constants

BRANCH_FORMAT
Branch
NAME_LENGTH

Public Class Methods

new(options) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 13
def initialize(options)
  @all = options[:all]
end

Public Instance Methods

print() click to toggle source

Private Instance Methods

branch_format(branch_name, current_branch) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 97
def branch_format(branch_name, current_branch)
  if branch_name == current_branch
    "* #{green}#{bold}%-#{@name_length}s#{clear}"
  else
    "  #{bold}%-#{@name_length}s#{clear}"
  end
end
get_description_of(branch) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 89
def get_description_of(branch)
  config_key = "branch.#{branch.name}.description"
  command = "git config #{config_key}"
  _stdin, stdout, _stderr, _wait_thr = *Open3.popen3(command)
  return nil if stdout.eof?
  stdout.readline
end
name_length(branches) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 41
def name_length(branches)
  longest_name_length = branches.map(&:name).map(&:length).max
  longest_name_length > NAME_LENGTH ? longest_name_length : NAME_LENGTH
end
parse_branch(line) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 70
def parse_branch(line)
  matched = line.match(BRANCH_FORMAT)
  raise 'cannot parse branch' unless matched
  branch_name = matched[:branch_name]
  rev = matched[:rev]
  current_branch = matched[:current_exp] ? branch_name : nil
  [branch_name, rev, current_branch]
end
parse_branches() click to toggle source
# File lib/git_topic/formatter/branches.rb, line 52
def parse_branches
  branches = []
  current_branch = nil
  _stdin, stdout, _stderr, _wait_thr = *Open3.popen3('git branch -v')
  stdout.each do |line|
    branch_name, rev, current_candidate = parse_branch(line)
    current_branch ||= current_candidate
    branches << Branch.new(branch_name, rev)
  end
  [branches, current_branch]
end
parse_length(branches) click to toggle source
# File lib/git_topic/formatter/branches.rb, line 34
def parse_length(branches)
  @name_length = name_length branches
  @rev_length = branches.first.rev.length
end
print_contents(branches, current_branch) click to toggle source
print_header() click to toggle source
print_line(current_branch, branch) click to toggle source