class Stencil::Branches

Public Class Methods

grouped(path) click to toggle source
# File lib/stencil/branches.rb, line 30
def grouped(path)
  branches = (read(path) - [ 'master' ]).inject({}) do |hash, branch|
    branch.split('-').inject(hash) do |h, b|
      h[b] ||= {}
    end
    hash
  end
  { 'master' => branches }
end
read(path, type=:all) click to toggle source
# File lib/stencil/branches.rb, line 9
def read(path, type=:all)
  key = "#{type}:#{path}"

  if type == :all
    (read(path, :remote) + read(path, :local)).uniq
  elsif type == :remote && !@@branches[key]
    branches = Cmd.run path, 'git branch -a'
    @@branches[key] = branches.scan(/origin\/([\w-]+\b$)/).flatten.uniq
  elsif type == :remote
    @@branches[key]
  elsif !@@branches[key]
    branches = Cmd.run path, 'git branch'
    branches = branches.split(/[\s\*]+/)
    branches.delete ''
    branches.sort!
    @@branches[key] = branches
  else
    @@branches[key]
  end
end