Sha256: c9540b22ffc5ca4ddc6dc177bb3b8962721328f9fc10aa24dca0b39114805c9e

Contents?: true

Size: 814 Bytes

Versions: 6

Compression:

Stored size: 814 Bytes

Contents

require File.dirname(__FILE__) + "/cmd"

class Stencil
  class Branches
    class <<self
      
      def read(path)
        branches = Cmd.run path, 'git branch'
        branches = branches.split(/\s+/)
        branches.delete '*'
        branches.delete 'master'
        branches
      end
      
      def grouped(path)
        groups, ignore = [], []
        branches = read(path).sort { |a, b| a.length <=> b.length }
        branches.each do |branch|
          next if ignore.include?(branch)
          groups << [ branch ] + group(branches, branch)
          ignore += groups.last
        end
        groups
      end
      
      private
      
      def group(branches, branch)
        branches.select do |b|
          b != branch && b[0..branch.length-1] == branch
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stencil-0.1.5 lib/stencil/branches.rb
stencil-0.1.4 lib/stencil/branches.rb
stencil-0.1.3 lib/stencil/branches.rb
stencil-0.1.2 lib/stencil/branches.rb
stencil-0.1.1 lib/stencil/branches.rb
stencil-0.1.0 lib/stencil/branches.rb